Skip to content
Chris Petersen edited this page Oct 16, 2014 · 1 revision

maps behaves like map, except for stripping empty lists from the returned list.

Parameter Description
fcn Function to be applied to each element
lst The list to operate on

Example

Example 1: Show the difference between map and maps.

> (define lst (list (list 1 (list)) (list 2 (list 3 8 34))))
> (map cadr lst)
(() (3 8 34))
> (maps cadr lst)
((3 8 34))

Example 2: Example from a communication page, where we want to keep only recent chat messages.

> (define allchats (list 
    (list (- ##now 1000) "A" "Once upon a time there was a blue dinosaur." 1)
    (list (- ##now 2200) "B" "Hope this will be interesting ..." 0)
    (list (- ##now 2300) "B" "Okay." 0)
    (list (- ##now 2500) "A" "Shell I tell you a story" 1)
    (list (- ##now 2500) "B" "I am really bored right now" 0)
    (list (- ##now 3000) "B" "The red fox jumps over the lazy dog." 0))) 
> (define age 2400)
> (maps (lambda(l) (if (< (- ##now (car l)) age) l '())) allchats)
((-1000. "A" "Once upon a time there was a blue dinosaur." 1)
(-2200. "B" "Hope this will be interesting ..." 0)
(-2300. "B" "Okay." 0))
Clone this wiki locally