tag:blogger.com,1999:blog-11788780.post3680941294862397847..comments2023-12-29T13:22:33.104-08:00Comments on JJinuxLand: Lisp: List Comprehensionsjjinuxhttp://www.blogger.com/profile/03270879497119114175noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-11788780.post-56330350474344231232008-07-16T17:13:00.000-07:002008-07-16T17:13:00.000-07:00Great comments. Thanks, guys!Great comments. Thanks, guys!jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-67502607921736046822008-07-15T08:44:00.000-07:002008-07-15T08:44:00.000-07:00SETL had set comprehensions (a straight-forward im...SETL had set comprehensions (a straight-forward implementation of the "set builder" math notation) long before anyone else implemented that.<BR/><BR/>The 1998 thread that begins with <A HREF="http://groups.google.com/group/comp.lang.python/msg/0914356b98334370" REL="nofollow">this post</A> by Greg Ewing is the first discussion about list comprehensions in Python land that I could find.<BR/><BR/>A few posts down, Tim Peters explains that "List comprehensions are a std feature of modern functional languages, to<BR/>which you can look for more examples." Terry Reedy later mentions the set builder notation, and Tim follows up with a post about their use in SETL.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-36590085613613687802008-07-15T06:40:00.000-07:002008-07-15T06:40:00.000-07:00That COLLECT function isn't standard to either Sch...That COLLECT function isn't standard to either Scheme or Common Lisp. It must be something developed in an earlier section of SICP (I don't have my copy handy at the moment).<BR/><BR/>Common Lisp has a LOOP macro as one way of expressing these sorts of things. It's essentially a domain specific language for looping constructs. Your Python list comprehension would look something like this with LOOP (untested):<BR/><BR/>(loop for i from 1 to (+ n 1)<BR/> for j from 1 to (- i 1)<BR/> when (prime-p (+ i j))<BR/> collect (list i j (+ i j)))<BR/><BR/>Google "lisp loop" for a few handy tutorials on the LOOP macro.<BR/><BR/>There's an even better macro for Common Lisp called <A HREF="http://common-lisp.net/project/iterate/" REL="nofollow">ITERATE</A> which isn't standard, but is better than LOOP in a number of ways (it's a lot more "lispy" for one thing). The above would look something like this with ITERATE (also untested):<BR/><BR/>(iter<BR/> (for i from 1 to (+ n 1))<BR/> (for j from 1 to (- i 1))<BR/> (if (prime-p (+ i j))<BR/> (collect (list i j (+ i j)))))John Landahlhttps://www.blogger.com/profile/01232274242533656318noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-72543668383570968862008-07-15T04:34:00.000-07:002008-07-15T04:34:00.000-07:00My memory is that list comprehensions in python we...My memory is that list comprehensions in python were inspired by SETL and not Haskell.Anonymousnoreply@blogger.com