From: Emre Sevinc on

I was browsing around lazily when I came across the List comprehensions
article in Wikipedia:

http://en.wikipedia.org/wiki/List_comprehensions

I looked at the first few lines and I sighed "oh how close-to-natural
in terms of mathematical notation! But it looks like Haskell, how would
it be in Common Lisp?"

After showing this to one of my fellow Turkish Lispers, HB, he told me that
he had just found a paper by Guy Lapalme [1], written in 1991 with a title
of "Implementation of a Lisp comprehension macro":

http://rali.iro.umontreal.ca/Publications/urls/LapalmeLispComp.pdf

We both rushed to our Emacsen + SLIMEs, typed the code:

http://paste.lisp.org/display/21380

and then saw that we were able to write similar list comprehension
code like that:

CL-USER> [x (x <- '(1 2 3)) (oddp x)]
(1 3)

CL-USER> [(list x y) (x <- '(a b c)) (y <- '(1 2 3))]
((A 1) (A 2) (A 3) (B 1) (B 2) (B 3) (C 1) (C 2) (C 3))

(The paper also included the classical QuickSort implementation
that used this list comprehension notation).

Once again I understood why Lisp is called a "programmable
programming language."

In the conclusion, author mentions advantages and drawbacks of
the implementation of this notation, he also compares it to
the Series.

Since the article was written about 15 years ago, I just wondered
if this macro became a part of a frequently used package.

Maybe Lispers who know much more will tell us more about
this subject?



1- http://www.iro.umontreal.ca/~lapalme/

--
Emre Sevinc

eMBA Software Developer Actively engaged in:
http://emba.bilgi.edu.tr http://ileriseviye.org
http://www.bilgi.edu.tr http://fazlamesai.net
Cognitive Science Student http://cazci.com
http://www.cogsci.boun.edu.tr
From: Jonathan Heusser on

>
> CL-USER> [x (x <- '(1 2 3)) (oddp x)]
> (1 3)
>
CL-USER> (loop for x in (list 1 2 3) when (oddp x) collect x)
(1 3)

LOOP does some kind of list comprehension aswell, without an additional
software.


From: Emre Sevinc on
Jonathan Heusser <jonny(a)drugphish.ch> writes:

>>
>> CL-USER> [x (x <- '(1 2 3)) (oddp x)]
>> (1 3)
>>
> CL-USER> (loop for x in (list 1 2 3) when (oddp x) collect x)
> (1 3)
>
> LOOP does some kind of list comprehension aswell, without an additional
> software.

Certainly it does. However I'd still be happy to have alternatives
and "more natural" (whatever that means, at least it rings some
bells for me ;-)) syntax as well as a more compact and concise one.

LOOP construct of CL has a very nice English-like syntax
but the one presented in the paper I mentioned in my original post
also provides a good syntax for the mathematically inclined.

Happy hacking,

--
Emre Sevinc

eMBA Software Developer Actively engaged in:
http://emba.www.bilgi.edu.tr http://ileriseviye.org
http://www.bilgi.edu.tr http://fazlamesai.net
Cognitive Science Student http://cazci.com
http://www.cogsci.boun.edu.tr
From: Marc Battyani on

"Emre Sevinc" <emres(a)bilgi.edu.tr> wrote
>> LOOP does some kind of list comprehension aswell, without an additional
>> software.
>
> Certainly it does. However I'd still be happy to have alternatives
> and "more natural" (whatever that means, at least it rings some
> bells for me ;-)) syntax as well as a more compact and concise one.
>
> LOOP construct of CL has a very nice English-like syntax
> but the one presented in the paper I mentioned in my original post
> also provides a good syntax for the mathematically inclined.

Here are other list comprehension librairies:
http://www.cl-user.net/asp/search?search=comprehension

Marc


From: joswig on

Jonathan Heusser schrieb:

> >
> > CL-USER> [x (x <- '(1 2 3)) (oddp x)]
> > (1 3)
> >
> CL-USER> (loop for x in (list 1 2 3) when (oddp x) collect x)
> (1 3)
>
> LOOP does some kind of list comprehension aswell, without an additional
> software.

For combinations of this kind of stuff I really prefer the functional
approach:
CL-USER 5 > (remove-if-not 'oddp '(1 2 3))
(1 3)