From: Tamas K Papp on
Is there a more idiomatic way to implement this function:

(defun flatten1 (list)
(apply #'concatenate 'list list))

Example:

(flatten1 '((a 1) (b 2) (c 3))) ;; => (A 1 B 2 C 3)

I am using it in macros, eg

(setf ,(flatten1 (function-that-generates-pairs)))

Thanks,

Tamas
From: Pascal Costanza on
On 09/12/2009 12:19, Tamas K Papp wrote:
> Is there a more idiomatic way to implement this function:
>
> (defun flatten1 (list)
> (apply #'concatenate 'list list))

(apply #'append lists)
(apply #'nconc lists)
(loop for list in lists append list)
(loop for list in lists nconc list)


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: vippstar on
On Dec 9, 1:49 pm, Pascal Costanza <p...(a)p-cos.net> wrote:
> On 09/12/2009 12:19, Tamas K Papp wrote:
>
> > Is there a more idiomatic way to implement this function:
>
> > (defun flatten1 (list)
> >    (apply #'concatenate 'list list))
>
> (apply #'append lists)
> (apply #'nconc lists)
> (loop for list in lists append list)
> (loop for list in lists nconc list)

(mapcan #'identity list)

I'm more concerned about the name. I mean, is it flatten1 or flattenl?
Is it right to assume the programmer is using a good font for
programming? ;-P.
From: Jussi Piitulainen on
vippstar <vippstar(a)gmail.com> writes:
> On Dec 9, 1:49 pm, Pascal Costanza <p...(a)p-cos.net> wrote:
> > On 09/12/2009 12:19, Tamas K Papp wrote:
> >
> > > Is there a more idiomatic way to implement this function:
> >
> > > (defun flatten1 (list)
> > >    (apply #'concatenate 'list list))
> >
> > (apply #'append lists)
> > (apply #'nconc lists)
> > (loop for list in lists append list)
> > (loop for list in lists nconc list)
>
> (mapcan #'identity list)
>
> I'm more concerned about the name. I mean, is it flatten1 or flattenl?

Or f1atten1 or f1attenl.

> Is it right to assume the programmer is using a good font for
> programming? ;-P.

Yes.
From: joswig on
On 9 Dez., 12:19, Tamas K Papp <tkp...(a)gmail.com> wrote:
> Is there a more idiomatic way to implement this function:
>
> (defun flatten1 (list)
>   (apply #'concatenate 'list list))

See CALL-ARGUMENTS-LIMIT : 'An integer not smaller than 50 ...'

>
> Example:
>
> (flatten1 '((a 1) (b 2) (c 3))) ;; => (A 1 B 2 C 3)
>
> I am using it in macros, eg
>
> (setf ,(flatten1 (function-that-generates-pairs)))
>
> Thanks,
>
> Tamas