chickadee » combinators

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

combinators

Combinators grab-bag.

Documentation

Section Combinators

Usage

(require-extension section-combinators)

FUNC a procedure.

left-section

left-section FUNC ARG0 ...procedure

Returns a procedure that partially applies some of its arguments from the left.

ARG0 ... a prefix of the arguments for FUNC.

Returns a partially curried procedure.

right-section

right-section FUNC ARG0 ...procedure

Returns a procedure that partially applies some of its arguments from the right.

ARG0 ... a suffix of the arguments for FUNC.

Returns a partially curried procedure.

crop-left

crop-left FUNC Nprocedure

Returns a procedure that drops the N left arguments before applying FUNC.

crop-right

crop-right FUNC Nprocedure

Returns a procedure that drops the N right arguments before applying FUNC.

reversed

reversed FUNCprocedure

Returns a procedure that reverses the arguments before applying FUNC.

arguments-chain

arguments-chain #!optional FUNC0...procedure

Returns a procedure that applies each FUNCi to result of the FUNCi+1. FUNCn is applied to the arguments.

Examples:

((arguments-chain f g h) arg...) -> (apply f (apply g (apply h arg...)))
((arguments-chain f) arg...) -> (apply f arg...)
((arguments-chain) arg...) -> (list arg...)

arguments-each

arguments-each #!optional FUNC0...procedure

Returns a procedure that calls each FUNCi to the ARGi. The result is returned as a list. The FUNC0... are re-used until the argument list is exhausted.

Examples:

((arguments-each f g h) a b c d e) -> (list (f a) (g b) (h c) (f d) (g e))
((arguments-each f g h) a b c) -> (list (f a) (g b) (h c))
((arguments-each) arg...) -> (list arg...)

arguments-all

arguments-all #!optional FUNC0...procedure

Returns a procedure that calls each FUNCi with all the arguments. The result is returned as a list.

Examples:

((arguments-all f g h) a b c) -> (list (f a b c) (g a b c) (h a b c))
((arguments-all) arg...) -> (list arg...)

Sort Combinators

Except for make-less-than/key and make-equal/key these are not combinators.

Usage

(require-extension sort-combinators)

Examples

(group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4))

(group/key car '((a 1) (a 2) (b 1)))  ;=> '(((a 1) (a 2)) ((b 1)))

(sort '(("a" . 1) ("z" . 3) ("b" . 2)) (make-less-than/key first string-ci<?)) ;=> (("a" . 1) ("b" . 2) ("z" . 3))

group-by

(group-by FUNC [EQUALITY equal?]) => procedureprocedure

Returns a procedure that takes a list and groups the elements by some key attribute. Uses the single-argument FUNC to retrieve key values & the EQUALITY function to compare them.

group/key

(group/key FUNC LYST [EQUALITY equal?])procedure

Groups a LYST of elements by some key attribute. Uses the single-argument FUNC to retrieve key values & the EQUALITY function to compare them.

The LYST must be in sorted order with respect to the key!

Returns a list of grouped elements.

make-less-than/key

(make-less-than/key FUNC [LESS-THAN <]) => {{procedure/2}}procedure

Returns a two-argument procedure that uses the single-argument FUNC to retrieve key values & the two-argument LESS-THAN procedure to compare them.

make-equal/key

(make-equal/key FUNC [EQUAL =]) => {{procedure/2}}procedure

Returns a two-argument procedure that uses the single-argument FUNC to retrieve key values & the two-argument EQUAL procedure to compare them.

Logical Combinators

Usage

(require-extension logical-combinators)

andf

andf OBJECT...procedure

Eager version of and.

Returns last (not #f) OBJECT when all OBJECT... are (not #f), #f otherwise.

orf

orf OBJECT...procedure

Eager version of or.

Returns first (not #f) OBJECT, #f otherwise.

Uni Combinators

C is a function.

F, G and H are function.

Usage

(require-extension uni-combinators)

uni

uni C Fprocedure

Returns (lambda (X) (C (F X))).

uni2

uni2 C Fprocedure

Returns (lambda (X Y) (C (F X Y))).

uni3

uni3 C Fprocedure

Returns (lambda (X Y Z) (C (F X Y Z))).

uni-each

uni-each C Fprocedure

Same as uni.

uni-all

uni-all C Fprocedure

Returns (lambda XS (C (apply F XS))).

Bi Combinators

Usage

(require-extension bi-combinators)

bi

bi C F Gprocedure

Returns (lambda (X) (C (F X) (G X))).

bi2

bi2 C F Gprocedure

Returns (lambda (X Y) (C (F X Y) (G X Y))).

bi3

bi3 C F Gprocedure

Returns (lambda (X Y Z) (C (F X Y Z) (G X Y Z))).

bi-each

bi-each C Fprocedure

Returns (lambda (X Y) (C (F X) (F Y))).

bi-all

bi-all C F Gprocedure

Returns (lambda XS (C (apply F XS) (apply G XS))).

Tri Combinators

Usage

(require-extension tri-combinators)

tri

tri C F G Hprocedure

Returns (lambda (X) (C (F X) (G X) (H X))).

tri2

tri2 C F G Hprocedure

Returns (lambda (X Y) (C (F X Y) (G X Y) (H X Y))).

tri3

tri3 C F G Hprocedure

Returns (lambda (X Y Z) (C (F X Y Z) (G X Y Z) (H X Y Z))).

tri-each

tri-each C Fprocedure

Returns (lambda (X Y Z) (C (F X) (F Y) (F Z))).

tri-all

tri-all C F G Hprocedure

Returns (lambda XS (C (apply F XS) (apply G XS) (apply H XS))).

Stack Combinators

These treat the argument list as a FORTH-like stack.

The utility is probably low.

Usage

(require-extension stack-combinators)

C is a function.

F, G and H are function.

X, Y and Z are object.

uni

uni X F Cprocedure

Returns the result of (C (F X)).

uni F Cprocedure
uni Cprocedure
uniprocedure

Returns a curried procedure.

uni2

uni2 X Y F Cprocedure

Returns the result of (C (F X Y)).

uni2 F Cprocedure
uni2 Cprocedure
uni2procedure

Returns a curried procedure.

uni3

uni3 X Y Z F Cprocedure

Returns the result of (C (F X Y Z)).

uni3 F Cprocedure
uni3 Cprocedure
uni3procedure

Returns a curried procedure.

uni@

uni@ X F Cprocedure

Returns the result of (C (F X)).

uni@ F Cprocedure

Returns a curried procedure.

bi

bi X F G Cprocedure

Returns the result of (C (F X) (G X)).

bi F G Cprocedure
bi F Gprocedure
bi Cprocedure
biprocedure

Returns a curried procedure.

bi2

bi2 X Y F G Cprocedure

Returns the result of (C (F X Y) (G X Y)).

bi2 F G Cprocedure
bi2 F Gprocedure
bi2 Cprocedure
bi2procedure

Returns a curried procedure.

bi3

bi3 X Y Z F G Cprocedure

Returns the result of (C (F X Y Z) (G X Y Z)).

bi3 F G Cprocedure
bi3 F Gprocedure
bi3 Cprocedure
bi3procedure

Returns a curried procedure.

bi@

bi@ X Y F Cprocedure

Returns the result of (C (F X) (F Y)).

bi@ F Cprocedure

Returns a curried procedure.

tri

tri X F G H Cprocedure

Returns the result of (C (F X) (G X) (H X)).

tri F G H Cprocedure
tri F G Hprocedure
tri Cprocedure
triprocedure

Returns a curried procedure.

tri2

tri2 X Y F G H Cprocedure

Returns the result of (C (F X Y) (G X Y) (H X Y)).

tri2 F G H Cprocedure
tri2 F G Hprocedure
tri2 Cprocedure
tri2procedure

Returns a curried procedure.

tri3

tri3 X Y Z F G H Cprocedure

Returns the result of (C (F X Y Z) (G X Y Z) (H X Y Z)).

tri3 F G H Cprocedure
tri3 F G Hprocedure
tri3 Cprocedure
tri3procedure

Returns a curried procedure.

tri@

tri@ X Y Z F Cprocedure

Returns the result of (C (F X) (F Y) (F Z)).

tri@ F Cprocedure

Returns a curried procedure.

dip

dip X Y F Cprocedure

Returns the result of (C (F X) Y).

dip F Cprocedure

Returns a curried procedure.

dup

dup X Cprocedure

Returns the result of (C X X).

dup Cprocedure

Returns a curried procedure.

dupd

dupd X Y Cprocedure

Returns the result of (C X X Y).

dupd Cprocedure

Returns a curried procedure.

swap

swap X Y Cprocedure

Returns the result of (C Y X).

swap Cprocedure

Returns a curried procedure.

drop

drop X Cprocedure

Returns the result of (C).

drop Cprocedure

Returns a curried procedure.

drop/2

drop/2 X Y Cprocedure

Returns the result of (C X).

drop/2 Cprocedure

Returns a curried procedure.

Notes

Author

Kon Lovett

Version history

1.2.0
Added uni/bi/tri-combinators & more section-combinators.
1.1.0
Added section-combinators.
1.0.0
Chicken 4 release.

License

Public Domain.

Contents »