Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

(filter P S) or [x for x in S if P(x)] ???

Name: Anonymous 2011-01-04 2:15

???

Name: Anonymous 2011-01-04 5:05

(define-syntax for
   (syntax-rules (in collect if do)
     ((for var in list collect body) (map (lambda (var) body) list))
     ((for var in list collect body if pred) (map (lambda (var) body) (filter pred list)))
     ((for var in list do body) (for-each (lambda (var) body)))
     ((for var in list do body if pred) (for-each (lambda (var) body) (filter pred list)))))

(for x in '(1 2 3 4 5) collect (* x x)) ; => '(1 4 9 16 25)
(for x in '(1 2 3 4 5) collect (* x x) if even?) ; => '(4 16)
(for x in '(1 2 3 4 5) do (display x)) ; => #<void>, output: 12345
(for x in '(1 2 3 4 5) do (display x) if odd?) ; => #<void>, output: 135


But I use filter and map, because I'm not a faggot.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List