The ability in loop to do even complex things like:
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
Kent M. Pitman wrote:
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
It's much shorter if we use a Lispy language
instead of CL.
Gauche Scheme
"!" is similar to "do".
(! (x :in '(1 2 3 4 5 6 7)
evens cons x
odds cons x
:if-else (even? x))
#f @@ (values evens odds))
===>
(2 4 6)
(1 3 5 7)
(loop for x in '(a b (c d) e f)
when (atom x)
collect x
else
append x)
(A B C D E F)
(loop for item in list
maximize (f item))
(loop for item in list
maximize (f item))
It's shorter in Gauche Scheme.
(use srfi-42) ;; max-ec
(max-ec (: x '(-8 2 0)) (abs x))
===>
8
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
B. Pym wrote:
(loop for item in list
maximize (f item))
It's shorter in Gauche Scheme.
(use srfi-42) ;; max-ec
(max-ec (: x '(-8 2 0)) (abs x))
===>
8
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
It's shorter in Gauche Scheme.
(partition even? '(2 3 4 5 6 7))
===>
(2 4 6)
(3 5 7)
(loop for x in '(a b (c d) e f)
when (atom x)
collect x
else
append x)
(A B C D E F)
(loop with best-foo = nil ;untested
for foo in (list foo1 foo2)
when (or (not best-foo)
(> (weight foo) (weight best-foo)))
do (setq best-foo foo)
finally (return best-foo))
B. Pym wrote:
B. Pym wrote:
(loop for item in list
maximize (f item))
It's shorter in Gauche Scheme.
(use srfi-42) ;; max-ec
(max-ec (: x '(-8 2 0)) (abs x))
===>
8
(loop for x in '(1 2 3 4 5 6 7)
when (evenp x)
collect x into evens
else
collect x into odds
finally
(return (values evens odds)))
(2 4 6), (1 3 5 7)
It's shorter in Gauche Scheme.
(partition even? '(2 3 4 5 6 7))
===>
(2 4 6)
(3 5 7)
M. Pitman wrote:
(loop with best-foo = nil ;untested
for foo in (list foo1 foo2)
when (or (not best-foo)
(> (weight foo) (weight best-foo)))
do (setq best-foo foo)
finally (return best-foo))
Gauche Scheme:
(use gauche.collection :only (find-max))
(find-max '((a 2) (b 8) (c 5)) :key last)
(b 8)
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:29:28 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,603 |