You are looking at historical revision 14019 of this page. It may differ significantly from its current revision.

• egg

## combinators

Combinators grab-bag.

## Documentation

### Sort Combinators

#### group/key

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

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

Returns a list of grouped elements.

#### make-less-than/key

[procedure] (make-less-than/key KEYPROC [LESS-THAN <])

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

#### make-equal/key

[procedure] (make-equal/key KEYPROC [EQUAL =])

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

### Logical Combinators

#### andf

[procedure] (andf OBJECT...)

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

#### orf

[procedure] (orf OBJECT...)

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

### Stack Combinators

C is a combinator function.

F, G and H are function.

X, Y and Z are object.

#### uni

[procedure] (uni X F C) => OBJECT

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

[procedure] (uni F C) => PROCEDURE/1
[procedure] (uni C) => PROCEDURE/1
[procedure] (uni) => PROCEDURE/1

Returns a curried procedure.

#### uni2

[procedure] (uni2 X Y F C) => OBJECT

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

[procedure] (uni2 F C) => PROCEDURE/2
[procedure] (uni2 C) => PROCEDURE/1
[procedure] (uni2) => PROCEDURE/1

Returns a curried procedure.

#### uni3

[procedure] (uni3 X Y Z F C) => OBJECT

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

[procedure] (uni3 F C) => PROCEDURE/3
[procedure] (uni3 C) => PROCEDURE/1
[procedure] (uni3) => PROCEDURE/1

Returns a curried procedure.

#### bi

[procedure] (bi X F G C) => OBJECT

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

[procedure] (bi F G C) => PROCEDURE/1
[procedure] (bi F G) => PROCEDURE/1
[procedure] (bi C) => PROCEDURE/2
[procedure] (bi) => PROCEDURE/1

Returns a curried procedure.

#### bi2

[procedure] (bi2 X Y F G C) => OBJECT

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

[procedure] (bi2 F G C) => PROCEDURE/2
[procedure] (bi2 F G) => PROCEDURE/1
[procedure] (bi2 C) => PROCEDURE/2
[procedure] (bi2) => PROCEDURE/1

Returns a curried procedure.

#### bi3

[procedure] (bi3 X Y Z F G C) => OBJECT

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

[procedure] (bi3 F G C) => PROCEDURE/3
[procedure] (bi3 F G) => PROCEDURE/1
[procedure] (bi3 C) => PROCEDURE/2
[procedure] (bi3) => PROCEDURE/1

Returns a curried procedure.

#### bi@

[procedure] (bi@ X Y F C) => OBJECT

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

[procedure] (bi@ F C) => PROCEDURE/2

Returns a curried procedure.

#### tri

[procedure] (tri X F G H C) => OBJECT

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

[procedure] (tri F G H C) => PROCEDURE/1
[procedure] (tri F G H) => PROCEDURE/1
[procedure] (tri C) => PROCEDURE/3
[procedure] (tri) => PROCEDURE/1

Returns a curried procedure.

#### tri2

[procedure] (tri2 X Y F G H C) => OBJECT

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

[procedure] (tri2 F G H C) => PROCEDURE/2
[procedure] (tri2 F G H) => PROCEDURE/1
[procedure] (tri2 C) => PROCEDURE/3
[procedure] (tri2) => PROCEDURE/1

Returns a curried procedure.

#### tri3

[procedure] (tri3 X Y Z F G H C) => OBJECT

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

[procedure] (tri3 F G H C) => PROCEDURE/3
[procedure] (tri3 F G H) => PROCEDURE/1
[procedure] (tri3 C) => PROCEDURE/3
[procedure] (tri3) => PROCEDURE/1

Returns a curried procedure.

#### tri@

[procedure] (tri@ X Y Z F G H C) => OBJECT

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

[procedure] (tri@ F G H C) => PROCEDURE/3

Returns a curried procedure.

#### dip

[procedure] (dip X Y F C) => OBJECT

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

[procedure] (dip F C) => PROCEDURE/2

Returns a curried procedure.

#### dup

[procedure] (dup X C) => OBJECT

Returns the result of (C X X).

[procedure] (dup C) => PROCEDURE/1

Returns a curried procedure.

#### dupd

[procedure] (dupd X Y C) => OBJECT

Returns the result of (C X X Y).

[procedure] (dupd C) => PROCEDURE/2

Returns a curried procedure.

#### swap

[procedure] (swap X Y C) => OBJECT

Returns the result of (C Y X).

[procedure] (swap C) => PROCEDURE/2

Returns a curried procedure.

#### drop

<procedure>(drop X C)< => OBJECT/procedure>

Returns the result of (C).

[procedure] (drop C) => PROCEDURE/1

Returns a curried procedure.

#### drop/2

[procedure] (drop/2 X Y C) => OBJECT

Returns the result of (C X).

[procedure] (drop/2 C) => PROCEDURE/2

Returns a curried procedure.

## Usage

`(require-extension logical-combinators)`
```(require-library logical-combinators)
...
(import logical-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))```

## Notes

• Inspired by e-mail conversations with Graham Fawcett in Feb '08.

kon lovett

## Version history

1.0.0
Chicken 4 release.