((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/combinators" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "combinators" (p "Combinators grab-bag.") (toc)) (section 2 "Documentation" (section 3 "Section Combinators" (section 4 "Usage" (highlight scheme "(require-extension section-combinators)") (p (tt "FUNC") " a procedure.")) (section 4 "left-section" (def (sig (procedure "(left-section FUNC ARG0 ...) => procedure" (id left-section))) (p "Returns a procedure that partially applies some of its arguments from the left.") (p (tt "ARG0 ...") " a prefix of the arguments for " (tt "FUNC") ".") (p "Returns a partially curried procedure."))) (section 4 "right-section" (def (sig (procedure "(right-section FUNC ARG0 ...) => procedure" (id right-section))) (p "Returns a procedure that partially applies some of its arguments from the right.") (p (tt "ARG0 ...") " a suffix of the arguments for " (tt "FUNC") ".") (p "Returns a partially curried procedure."))) (section 4 "crop-left" (def (sig (procedure "(crop-left FUNC N) => procedure" (id crop-left))) (p "Returns a procedure that drops the " (tt "N") " left arguments before applying " (tt "FUNC") "."))) (section 4 "crop-right" (def (sig (procedure "(crop-right FUNC N) => procedure" (id crop-right))) (p "Returns a procedure that drops the " (tt "N") " right arguments before applying " (tt "FUNC") "."))) (section 4 "reversed" (def (sig (procedure "(reversed FUNC) => procedure" (id reversed))) (p "Returns a procedure that reverses the arguments before applying " (tt "FUNC") "."))) (section 4 "arguments-chain " (def (sig (procedure "(arguments-chain [FUNC0...]) => procedure" (id arguments-chain))) (p "Returns a procedure that applies each " (tt "FUNCi") " to result of the " (tt "FUNCi+1") ". " (tt "FUNCn") " is applied to the arguments.") (p "Examples:") (pre "((arguments-chain f g h) arg...) -> (apply f (apply g (apply h arg...)))") (pre "((arguments-chain f) arg...) -> (apply f arg...)") (pre "((arguments-chain) arg...) -> (list arg...)"))) (section 4 "arguments-each " (def (sig (procedure "(arguments-each [FUNC0...]) => procedure" (id arguments-each))) (p "Returns a procedure that calls each " (tt "FUNCi") " to the " (tt "ARGi") ". The result is returned as a " (tt "list") ". The " (tt "FUNC0...") " are re-used until the argument list is exhausted.") (p "Examples:") (pre "((arguments-each f g h) a b c d e) -> (list (f a) (g b) (h c) (f d) (g e))") (pre "((arguments-each f g h) a b c) -> (list (f a) (g b) (h c))") (pre "((arguments-each) arg...) -> (list arg...)"))) (section 4 "arguments-all " (def (sig (procedure "(arguments-all [FUNC0...]) => procedure" (id arguments-all))) (p "Returns a procedure that calls each " (tt "FUNCi") " with all the arguments. The result is returned as a " (tt "list") ".") (p "Examples:") (pre "((arguments-all f g h) a b c) -> (list (f a b c) (g a b c) (h a b c))") (pre "((arguments-all) arg...) -> (list arg...)")))) (section 3 "Sort Combinators" (p "Except for " (tt "make-less-than/key") " and " (tt "make-equal/key") " these are not combinators.") (section 4 "Usage" (highlight scheme "(require-extension sort-combinators)")) (section 4 "Examples" (highlight scheme "(group/key identity '(1 2 3 3 4 4 4)) ;=> ((1) (2) (3 3) (4 4 4))\n\n(group/key car '((a 1) (a 2) (b 1)))  ;=> '(((a 1) (a 2)) ((b 1)))\n\n(sort '((\"a\" . 1) (\"z\" . 3) (\"b\" . 2)) (make-less-than/key first string-ci<?)) ;=> ((\"a\" . 1) (\"b\" . 2) (\"z\" . 3))")) (section 4 "group-by" (def (sig (procedure "(group-by FUNC [EQUALITY equal?]) => procedure" (id group-by))) (p "Returns a procedure that takes a list and groups the elements by some key attribute. Uses the single-argument " (tt "FUNC") " to retrieve key values & the " (tt "EQUALITY") " function to compare them."))) (section 4 "group/key" (def (sig (procedure "(group/key FUNC LYST [EQUALITY equal?])" (id group/key))) (p "Groups a " (tt "LYST") " of elements by some key attribute. Uses the single-argument " (tt "FUNC") " to retrieve key values & the " (tt "EQUALITY") " function to compare them.") (p "The " (tt "LYST") " must be in sorted order with respect to the key!") (p "Returns a list of grouped elements."))) (section 4 "make-less-than/key" (def (sig (procedure "(make-less-than/key FUNC [LESS-THAN <]) => {{procedure/2}}" (id make-less-than/key))) (p "Returns a two-argument procedure that uses the single-argument " (tt "FUNC") " to retrieve key values & the two-argument " (tt "LESS-THAN") " procedure to compare them."))) (section 4 "make-equal/key" (def (sig (procedure "(make-equal/key FUNC [EQUAL =]) => {{procedure/2}}" (id make-equal/key))) (p "Returns a two-argument procedure that uses the single-argument " (tt "FUNC") " to retrieve key values & the two-argument " (tt "EQUAL") " procedure to compare them.")))) (section 3 "Logical Combinators" (section 4 "Usage" (highlight scheme "(require-extension logical-combinators)")) (section 4 "andf" (def (sig (procedure "(andf OBJECT...)" (id andf))) (p "Eager version of " (tt "and") ".") (p "Returns last " (tt "(not #f)") " " (tt "OBJECT") " when all " (tt "OBJECT...") " are " (tt "(not #f)") ", " (tt "#f") " otherwise."))) (section 4 "orf" (def (sig (procedure "(orf OBJECT...)" (id orf))) (p "Eager version of " (tt "or") ".") (p "Returns first " (tt "(not #f)") " " (tt "OBJECT") ", " (tt "#f") " otherwise.")))) (section 3 "Uni Combinators" (p (tt "C") " is a " (tt "function") ".") (p (tt "F") ", " (tt "G") " and " (tt "H") " are " (tt "function") ".") (section 4 "Usage" (highlight scheme "(require-extension uni-combinators)")) (section 4 "uni" (def (sig (procedure "(uni C F) => procedure" (id uni))) (p "Returns " (tt "(lambda (X) (C (F X)))") "."))) (section 4 "uni2" (def (sig (procedure "(uni2 C F) => procedure" (id uni2))) (p "Returns " (tt "(lambda (X Y) (C (F X Y)))") "."))) (section 4 "uni3" (def (sig (procedure "(uni3 C F) => procedure" (id uni3))) (p "Returns " (tt "(lambda (X Y Z) (C (F X Y Z)))") "."))) (section 4 "uni-each" (def (sig (procedure "(uni-each C F) => procedure" (id uni-each))) (p "Same as " (tt "uni") "."))) (section 4 "uni-all" (def (sig (procedure "(uni-all C F) => procedure" (id uni-all))) (p "Returns " (tt "(lambda XS (C (apply F XS)))") ".")))) (section 3 "Bi Combinators" (section 4 "Usage" (highlight scheme "(require-extension bi-combinators)")) (section 4 "bi" (def (sig (procedure "(bi C F G) => procedure" (id bi))) (p "Returns " (tt "(lambda (X) (C (F X) (G X)))") "."))) (section 4 "bi2" (def (sig (procedure "(bi2 C F G) => procedure" (id bi2))) (p "Returns " (tt "(lambda (X Y) (C (F X Y) (G X Y)))") "."))) (section 4 "bi3" (def (sig (procedure "(bi3 C F G) => procedure" (id bi3))) (p "Returns " (tt "(lambda (X Y Z) (C (F X Y Z) (G X Y Z)))") "."))) (section 4 "bi-each" (def (sig (procedure "(bi-each C F) => procedure" (id bi-each))) (p "Returns " (tt "(lambda (X Y) (C (F X) (F Y)))") "."))) (section 4 "bi-all" (def (sig (procedure "(bi-all C F G) => procedure" (id bi-all))) (p "Returns " (tt "(lambda XS (C (apply F XS) (apply G XS)))") ".")))) (section 3 "Tri Combinators" (section 4 "Usage" (highlight scheme "(require-extension tri-combinators)")) (section 4 "tri" (def (sig (procedure "(tri C F G H) => procedure" (id tri))) (p "Returns " (tt "(lambda (X) (C (F X) (G X) (H X)))") "."))) (section 4 "tri2" (def (sig (procedure "(tri2 C F G H) => procedure" (id tri2))) (p "Returns " (tt "(lambda (X Y) (C (F X Y) (G X Y) (H X Y)))") "."))) (section 4 "tri3" (def (sig (procedure "(tri3 C F G H) => procedure" (id tri3))) (p "Returns " (tt "(lambda (X Y Z) (C (F X Y Z) (G X Y Z) (H X Y Z)))") "."))) (section 4 "tri-each" (def (sig (procedure "(tri-each C F) => procedure" (id tri-each))) (p "Returns " (tt "(lambda (X Y Z) (C (F X) (F Y) (F Z)))") "."))) (section 4 "tri-all" (def (sig (procedure "(tri-all C F G H) => procedure" (id tri-all))) (p "Returns " (tt "(lambda XS (C (apply F XS) (apply G XS) (apply H XS)))") ".")))) (section 3 "Stack Combinators" (p "These treat the argument list as a FORTH-like stack.") (p "The utility is probably low.") (section 4 "Usage" (highlight scheme "(require-extension stack-combinators)") (p (tt "C") " is a " (tt "function") ".") (p (tt "F") ", " (tt "G") " and " (tt "H") " are " (tt "function") ".") (p (tt "X") ", " (tt "Y") " and " (tt "Z") " are " (tt "object") ".")) (section 4 "uni" (def (sig (procedure "(uni X F C) => procedure" (id uni))) (p "Returns the result of " (tt "(C (F X))") ".")) (def (sig (procedure "(uni F C) => {{procedure/1}}" (id uni)) (procedure "(uni C) => {{procedure/1}}" (id uni)) (procedure "(uni) => {{procedure/1}}" (id uni))) (p "Returns a curried procedure."))) (section 4 "uni2" (def (sig (procedure "(uni2 X Y F C) => procedure" (id uni2))) (p "Returns the result of " (tt "(C (F X Y))") ".")) (def (sig (procedure "(uni2 F C) => {{procedure/2}}" (id uni2)) (procedure "(uni2 C) => {{procedure/1}}" (id uni2)) (procedure "(uni2) => {{procedure/1}}" (id uni2))) (p "Returns a curried procedure."))) (section 4 "uni3" (def (sig (procedure "(uni3 X Y Z F C) => procedure" (id uni3))) (p "Returns the result of " (tt "(C (F X Y Z))") ".")) (def (sig (procedure "(uni3 F C) => {{procedure/3}}" (id uni3)) (procedure "(uni3 C) => {{procedure/1}}" (id uni3)) (procedure "(uni3) => {{procedure/1}}" (id uni3))) (p "Returns a curried procedure."))) (section 4 "uni@" (def (sig (procedure "(uni@ X F C) => procedure" (id uni@))) (p "Returns the result of " (tt "(C (F X))") ".")) (def (sig (procedure "(uni@ F C) => {{procedure/1}}" (id uni@))) (p "Returns a curried procedure."))) (section 4 "bi" (def (sig (procedure "(bi X F G C) => procedure" (id bi))) (p "Returns the result of " (tt "(C (F X) (G X))") ".")) (def (sig (procedure "(bi F G C) => {{procedure/1}}" (id bi)) (procedure "(bi F G) => {{procedure/1}}" (id bi)) (procedure "(bi C) => {{procedure/2}}" (id bi)) (procedure "(bi) => {{procedure/1}}" (id bi))) (p "Returns a curried procedure."))) (section 4 "bi2" (def (sig (procedure "(bi2 X Y F G C) => procedure" (id bi2))) (p "Returns the result of " (tt "(C (F X Y) (G X Y))") ".")) (def (sig (procedure "(bi2 F G C) => {{procedure/2}}" (id bi2)) (procedure "(bi2 F G) => {{procedure/1}}" (id bi2)) (procedure "(bi2 C) => {{procedure/2}}" (id bi2)) (procedure "(bi2) => {{procedure/1}}" (id bi2))) (p "Returns a curried procedure."))) (section 4 "bi3" (def (sig (procedure "(bi3 X Y Z F G C) => procedure" (id bi3))) (p "Returns the result of " (tt "(C (F X Y Z) (G X Y Z))") ".")) (def (sig (procedure "(bi3 F G C) => {{procedure/3}}" (id bi3)) (procedure "(bi3 F G) => {{procedure/1}}" (id bi3)) (procedure "(bi3 C) => {{procedure/2}}" (id bi3)) (procedure "(bi3) => {{procedure/1}}" (id bi3))) (p "Returns a curried procedure."))) (section 4 "bi@" (def (sig (procedure "(bi@ X Y F C) => procedure" (id bi@))) (p "Returns the result of " (tt "(C (F X) (F Y))") ".")) (def (sig (procedure "(bi@ F C) => {{procedure/2}}" (id bi@))) (p "Returns a curried procedure."))) (section 4 "tri" (def (sig (procedure "(tri X F G H C) => procedure" (id tri))) (p "Returns the result of " (tt "(C (F X) (G X) (H X))") ".")) (def (sig (procedure "(tri F G H C) => {{procedure/1}}" (id tri)) (procedure "(tri F G H) => {{procedure/1}}" (id tri)) (procedure "(tri C) => {{procedure/3}}" (id tri)) (procedure "(tri) => {{procedure/1}}" (id tri))) (p "Returns a curried procedure."))) (section 4 "tri2" (def (sig (procedure "(tri2 X Y F G H C) => procedure" (id tri2))) (p "Returns the result of " (tt "(C (F X Y) (G X Y) (H X Y))") ".")) (def (sig (procedure "(tri2 F G H C) => {{procedure/2}}" (id tri2)) (procedure "(tri2 F G H) => {{procedure/1}}" (id tri2)) (procedure "(tri2 C) => {{procedure/3}}" (id tri2)) (procedure "(tri2) => {{procedure/1}}" (id tri2))) (p "Returns a curried procedure."))) (section 4 "tri3" (def (sig (procedure "(tri3 X Y Z F G H C) => procedure" (id tri3))) (p "Returns the result of " (tt "(C (F X Y Z) (G X Y Z) (H X Y Z))") ".")) (def (sig (procedure "(tri3 F G H C) => {{procedure/3}}" (id tri3)) (procedure "(tri3 F G H) => {{procedure/1}}" (id tri3)) (procedure "(tri3 C) => {{procedure/3}}" (id tri3)) (procedure "(tri3) => {{procedure/1}}" (id tri3))) (p "Returns a curried procedure."))) (section 4 "tri@" (def (sig (procedure "(tri@ X Y Z F C) => procedure" (id tri@))) (p "Returns the result of " (tt "(C (F X) (F Y) (F Z))") ".")) (def (sig (procedure "(tri@ F C) => {{procedure/3}}" (id tri@))) (p "Returns a curried procedure."))) (section 4 "dip" (def (sig (procedure "(dip X Y F C) => procedure" (id dip))) (p "Returns the result of " (tt "(C (F X) Y)") ".")) (def (sig (procedure "(dip F C) => {{procedure/2}}" (id dip))) (p "Returns a curried procedure."))) (section 4 "dup" (def (sig (procedure "(dup X C) => procedure" (id dup))) (p "Returns the result of " (tt "(C X X)") ".")) (def (sig (procedure "(dup C) => {{procedure/1}}" (id dup))) (p "Returns a curried procedure."))) (section 4 "dupd" (def (sig (procedure "(dupd X Y C) => procedure" (id dupd))) (p "Returns the result of " (tt "(C X X Y)") ".")) (def (sig (procedure "(dupd C) => {{procedure/2}}" (id dupd))) (p "Returns a curried procedure."))) (section 4 "swap" (def (sig (procedure "(swap X Y C) => procedure" (id swap))) (p "Returns the result of " (tt "(C Y X)") ".")) (def (sig (procedure "(swap C) => {{procedure/2}}" (id swap))) (p "Returns a curried procedure."))) (section 4 "drop" (def (sig (procedure "(drop X C) => procedure" (id drop))) (p "Returns the result of " (tt "(C)") ".")) (def (sig (procedure "(drop C) => {{procedure/1}}" (id drop))) (p "Returns a curried procedure."))) (section 4 "drop/2" (def (sig (procedure "(drop/2 X Y C) => procedure" (id drop/2))) (p "Returns the result of " (tt "(C X)") ".")) (def (sig (procedure "(drop/2 C) => {{procedure/2}}" (id drop/2))) (p "Returns a curried procedure."))))) (section 2 "Notes" (ul (li "Inspired by e-mail conversations with Graham Fawcett in Feb '08.") (li "The procedures " (tt "left-section") " and " (tt "right-section") " from Philip L. Bewig."))) (section 2 "Author" (p (int-link "/users/kon-lovett" "Kon Lovett"))) (section 2 "Version history" (dl (dt "1.2.0") (dd "Added " (tt "uni/bi/tri-combinators") " & more " (tt "section-combinators") ".") (dt "1.1.0") (dd "Added " (tt "section-combinators") ".") (dt "1.0.0") (dd "Chicken 4 release."))) (section 2 "License" (p "Public Domain.")))