8.6
3.3 列表
3.3.1 查找
取出列表的头部。
Examples:
3.3.2 合并
拼接两条数组。
Examples:
> (concat (list) (list)) '()
> (const (list 1 2 3) (list)) '(1 2 3)
> (const (list 2 3) (list 3 2)) '(2 3)
合并两个列表。
(define zip (zip-with cons))
以cons合并。
Example:
> (zip '(1 2 3 4 5) '(a b c)) '((1 . a) (2 . b) (3 . c))
3.3.3 遍历
柯里化的foldl,固定参数长度。
Examples:
柯里化的foldr,固定参数长度。
Examples:
3.3.4 变换
柯里化map,固定参数个数。
Examples:
3.3.5 过滤
procedure
f : (-> a boolean?) xs : (listof a) (reject f xs) → (listof a) f : (-> a boolean?) xs : (listof a)
Examples:
Examples:
procedure
(filter-map f xs) → (listof b)
f : (-> a (Maybe/c b)) xs : (listof a)
Examples:
> (filter-map (const nothing) (list 1 2 3)) '()
> (filter-map Just (list 1 2 3)) '(1 2 3)
> (define (f x) (if (even? x) (Just x) nothing)) > (filter-map f (list 1 2 3 4 5 6)) '(2 4 6)