Tutorial by Examples

Map

Map applies a function to every element of a list: map: (a -> b) (listof a) -> (listof b) > (map (lambda (x) (* x 2)) (list 1 2 3 4 5) (list 2 4 6 8 10) > (map sqrt (list 1 4 9)) (list 1 2 3) > (map (lambda (x) (if (even? x) "even" "odd")) (list 1 2 3))...
Fold Right successively applies a two-argument function to every element in a list from left to right starting with a base value: foldr: (a b -> b) b (listof a) -> b > (foldr + 0 (list 1 2 3 4)) 10 > (foldr string-append "" (list "h" "e" "l&quot...
filter returns a list of each item in the given list for which the given predicate returns a non-#f value. ;; Get only even numbers in a list > (filter even? '(1 2 3 4)) '(2 4) ;; Get all square numbers from 1 to 100 > (filter (lambda (n) (integer? (sqrt n))) (range 1 100)) '(1 4 9 16 ...
Lets you compose several functions f₀ f₁ … fₙ. It returns a function that will successively apply fₙ to its arguments, then fₙ₋₁ to the result of fₙ and so on. Function are applied from right to left, like for mathematical function composition: (f ∘ g ∘ h)(x) = f(g(h(x))). > ((compose sqrt +) 16...
Returns a partially applied function. > ((curry + 10) 20) 30 curryr can be used when the arguments need to be inserted at the end. In other words, (curryr list 1 2) will produce a function expecting some new-arguments .... When called, that new function will in turn call (list new-arguments ...

Page 1 of 1