[comp.lang.scheme] news

munawar@vaxb.acs.unt.edu (03/01/91)

Hello,
  In my previous I made a mistake.
  My problem is to flatten
  '((a b)(c d)(e f)) in to '(a b c d e f)
I am not sure how to tackle this problem specifically in TI PCSCHEME

Any help highily appriciated

-Shri

lpl@cunixb.cc.columbia.edu (Leonard P Lidov) (03/02/91)

In article <1991Mar1.153624.45733@vaxb.acs.unt.edu> munawar@vaxb.acs.unt.edu writes:

>  My problem is to flatten
>  '((a b)(c d)(e f)) in to '(a b c d e f)
>I am not sure how to tackle this problem specifically in _TI PCSCHEME_
>

Gee--do you need a PCScheme specific solution?? The problem isn't hard, 
though: 

using a nicely abstracted form from Ableson & Susman:

given that z is ((a b) (c d) (e f)):

(define (accumulate combiner init-value l)
	(if (null? l)
	    init-value
	    (combiner (car l) (accumulate combiner init-value (cdr l)))))

(accumulate append '() z)

ought to produce (a b c d e f) pretty easily.

Good Luck,

Len

"All history is the history of CS"
			Marx

huntley@copper.ucs.indiana.edu (Haydn Huntley) (03/02/91)

In article <1991Mar1.153624.45733@vaxb.acs.unt.edu> munawar@vaxb.acs.unt.edu writes:
| Hello,
|   My problem is to flatten
|   '((a b)(c d)(e f)) in to '(a b c d e f)
| I am not sure how to tackle this problem specifically in TI PCSCHEME

; Here is a version of flatten.
(define flatten
  (lambda (ls)
    (cond
     ((null? ls) '())
     ((pair? (car ls))
      (append (flatten (car ls))
              (flatten (cdr ls))))
     (else (cons (car ls)
                 (flatten (cdr ls)))))))

--
;;  *****************************************************
;;  *  Haydn Huntley    huntley@copper.ucs.indiana.edu  *
;;  *****************************************************

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (03/03/91)

> In article <1991Mar1.153624.45733@vaxb.acs.unt.edu> munawar@vaxb.acs.unt.edu writes:
> [how to flatten a list of lists] '((a b)(c d)(e f))> 

In article <1991Mar2.000059.16156@cunixf.cc.columbia.edu>,
lpl@cunixb.cc.columbia.edu (Leonard P Lidov) proposed a complicated solution.

(apply append '((a b) (c d) (e f)))

is all that is called for.

-- 
The purpose of advertising is to destroy the freedom of the market.