Code: Select all
(map print (sequence 5 8))
Code: Select all
5678
In Scheme, the order is unspecified. SRFI 1 proposes map-in-order, which works from left to right.
Code: Select all
(map print (sequence 5 8))
Code: Select all
5678
Code: Select all
(map list '(1 2 3 4 5) '(a b c))
=> ((1 a) (2 b) (3 c) (4 nil) (5 nil))
(map list '(1 2 3) '(a b c d e))
=> ((1 a) (2 b) (3 c))
One solution wasI just want to use a print statement with multiple things inside of it.
This doesn't seem possible. Is there a work-a-round?
(print "the value of variable foo is " foo)
Code: Select all
(define (myprint . args)
(for-each (lambda (x) (display x)) args))
Code: Select all
(define (myprint . args)
(map display args))
Also, you can drop the lambda too in that person's for-each solution; so that it becomes something like:The arguments to for-each are like the arguments to map, but for-each calls proc for its side effects rather than for its values. Unlike map, for-each is guaranteed to call proc on the elements of the lists in order from the first element(s) to the last, and the value returned by for-each is unspecified.
Code: Select all
(define (display+ . args) (for-each display args))