From: Jonathan Heusser on 19 Jun 2006 04:12 Emre Sevinc wrote: > 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) > > 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. > all a matter of taste which version is more natural/readable, right ;)
From: Frank Buss on 19 Jun 2006 04:38 joswig(a)corporate-world.lisp.de wrote: > 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) I know it is possible, but I'm not sure aboout how to write the following with a functional approach: > (loop for i from 1 to 10 collect (loop for j from 1 to i collect j)) ((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5) (1 2 3 4 5 6) (1 2 3 4 5 6 7) (1 2 3 4 5 6 7 8) (1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9 10)) -- Frank Buss, fb(a)frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
From: Pascal Costanza on 19 Jun 2006 05:38 Marc Battyani wrote: > "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 See also http://p-cos.net/lisp-ecoop/submissions/Nystrom.pdf Pascal -- 3rd European Lisp Workshop July 3 - Nantes, France - co-located with ECOOP 2006 http://lisp-ecoop06.bknr.net/
From: Marcin 'Qrczak' Kowalczyk on 19 Jun 2006 18:32 Frank Buss <fb(a)frank-buss.de> writes: > I know it is possible, but I'm not sure aboout how to write the following > with a functional approach: > >> (loop for i from 1 to 10 collect (loop for j from 1 to i collect j)) > ((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5) (1 2 3 4 5 6) (1 2 3 4 5 6 7) (1 2 > 3 4 5 6 7 8) (1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9 10)) It's a matter of appropriate building blocks. For example: - an arithmetic sequence (range) - map - conversion of a sequence to a list -- __("< Marcin Kowalczyk \__/ qrczak(a)knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/
From: Alexander Schmolck on 19 Jun 2006 19:50 Frank Buss <fb(a)frank-buss.de> writes: > joswig(a)corporate-world.lisp.de wrote: > > > 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) > > I know it is possible, but I'm not sure aboout how to write the following > with a functional approach: > > > (loop for i from 1 to 10 collect (loop for j from 1 to i collect j)) > ((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5) (1 2 3 4 5 6) (1 2 3 4 5 6 7) (1 2 > 3 4 5 6 7 8) (1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9 10)) e.g. (mapcar #'upto (upto 10)) or (unfold (its = 10) #'upto #'1+ 1) with (untested) (defun upto (n) (labels ((rec (i) (and (plusp i) (cons (- n i -1) (rec (- i 1)))))) (rec n))) (defun unfold (p f g seed) (and (not (funcall p seed)) (cons (funcall f seed) (unfold p f g (funcall g seed))))) (defmacro its (f &rest rest) `(lambda (#1=#:x) (,f #1# ,@rest))) 'as
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: the Modernization of Emacs Next: Clipboard Access on Windows |