Magic Pipes
Documentation
Login

mpmap procedure-expr

Reads s-expressions from standard input, and applies the procedure expression procedure-expr to each of them. The results are then written to standard output. The procedure expression may return an arbitrary number of values; all non-undefined values are output in order (separated by a single space), and a newline is written after the values from each application of the procedure expression. It is legal for the procedure expression to return zero values.

Examples

Basic operation

$ echo '"Alaric" "was" "here"' | mpmap string-reverse
"ciralA"
"saw"
"ereh"

Returning multiple values

$ echo "1 2 3" | mpmap '(lambda (x) (values x (+ x 1)))'
1 2
2 3
3 4

Note how the two values returned for each input s-expr are output on the same line, for clarity.

Defining utilities with -d

$ echo "1 2 3" | mpmap -d '(define (foo x) (values x (+ x 1)))' 'foo'
1 2
2 3
3 4

Using procedures from Chicken modules

$ echo "1 2 3" | mpmap -u srfi-4 'make-u8vector'
#u8(112)
#u8(74 61)
#u8(136 51 131)

Omitting undefined values

$ echo "#t #f #t" | mpmap '(lambda (x) (values x (if x "Yes" (void)) x))'
#t "Yes" #t
#f #f
#t "Yes" #t

Omitting entire inputs

$ echo "1 2 3 4 5 6" | mpmap '(lambda (x) (if (even? x) x (values)))'

2

4

6

When we produce zero values with values, only a blank line is output.