[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

Gauche has some primitive procedures that allows combinatory programming.

__Function:__**pa$***proc arg ...*- Partial application. Returns a procedure, and when it is
called with arguments
`m`..., it is equivalent to call`(proc arg ... m ...)`

.(define add3 (pa$ + 3)) (add3 4) => 7 (map (pa$ * 2) '(1 2 3)) => (2 4 6)

Macros

`cut`

and`cute`

defined in SRFI-26 provide a similar abstraction, with a bit more flexible but less compact notation. See section 4.3 Making Procedures.

__Function:__**apply$***proc*__Function:__**map$***proc*__Function:__**for-each$***proc*- Partial application version of
`apply`

,`map`

and`for-each`

.(define map2* (map$ (pa$ * 2))) (map2* '(1 2 3)) => (2 4 6)

There are more 'partial-applied' version of procedures defined in
SRFI-1 (See section 10.2 `srfi-1`

- List library), such as `fold$`

,
`filter$`

, `member$`

, etc.

__Function:__**compose***f g h ...*- Combine two or more procedures. Arguments must be procedures.
When two procedures are given,
`(compose f g)`

is equivalent to(lambda args (call-with-values (lambda () (apply g args)) f))

Some examples:

(define not-zero? (compose not zero?)) (not-zero? 3) => #t (not-zero? 0) => #f (define dot-product (compose (apply$ +) (map$ *))) (dot-product '(1 2 3) '(4 5 6)) => 32

__Function:__**any-pred***pred ...*- Returns a procedure which applies given argument(s) to
each predicate
`pred`. If any`pred`returns a non-`#f`

value, the value is returned. If all the`pred`s return`#f`

,`#f`

is returned.(define string-or-symbol? (any-pred string? symbol?)) (string-or-symbol? "abc") => #t (string-or-symbol? 'abc) => #t (string-or-symbol? 3) => #f (define <> (any-pred < >)) (<> 3 4) => #t (<> 3 3) => #f ((any-pred (cut memq <> '(a b c)) (cut memq <> '(1 2 3))) 'b) => '(b c)

__Function:__**every-pred***pred ...*- Returns a procedure which applies given argument(s) to
each predicate
`pred`. If every`pred`returns a non-`#f`

value, the value returned by the last`pred`is returned. If any`pred`returns`#f`

,`every-pred`

returns`#f`

without calling further`pred`s.((every-pred odd? positive?) 3) => #t ((every-pred odd? positive?) 4) => #f ((every-pred odd? positive?) -3) => #f (define safe-length (every-pred list? length)) (safe-length '(a b c)) => 3 (safe-length "aaa") => #f

[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

This document was generated by