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)
Kent M. Pitman wrote:
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)
Gauche Scheme
(partition odd? (iota 9)
===>
(1 3 5 7)
(0 2 4 6 8)
Also, being able to vary the collection is handy. Consider:
(loop for x in '(a b (c d) e f)
when (atom x)
collect x
else
append x)
(A B C D E F)
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 across array-of-numbers
minimizing x into min
maximizing x into max
summing x into total
counting t into count
finally (return (list min max (/ total count))))
On 6/9/2024, B. Pym wrote:
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)
Peter Seibel wrote:
(loop for x across array-of-numbers
minimizing x into min
maximizing x into max
summing x into total
counting t into count
finally (return (list min max (/ total count))))
Peter Seibel wrote:
(loop for x across array-of-numbers
minimizing x into min
maximizing x into max
summing x into total
counting t into count
finally (return (list min max (/ total count))))
In Gauche Scheme, it's a one-liner.
(use gauche.sequence)
(define v #(0 2 -3 99 48 35 86 27 50 18))
(define count (vector-length v))
`(,(find-min v) ,(find-max v) ,(/ (fold + 0 v) count))
===>
(-3 99 181/5)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:12:30 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,028 |