Besides the documentation procedure, this module exports two curry procedures, @> and @<, and one macro, @@, which implements the holes mechanism. They all create partial procedures.
Holes are spezial identifiers, delimited by < and >, possibly enclosing zero or more digits. This new syntax replaces the old one, where both delimiters were bangs.
The macro @@ transforms expressions with zero or more holes into a procedure which has as many arguments as there are different holes in the expression. Moreover, the arguments are ordered according to the digits enclosed by the delimiters. For example, (@@ 5), is a thunk, because there are no holes. And (@@ (- <2> <1> <2>)) is a procedure of two arguments, <1> and <2> in this order, returning (- 20 10 20) when applied to 10 20: ((@@(- <2> <1> <2>)) 10 20) is -10.
But holes aren't restricted to flat list expressions, nested ones are accepted as well. For example, (@@ (+ 5 (* <> 2))) is a unary procedure which applied to 7 gives 19. The holes may appear in different nesting levels, which gives great flexibility.
Notice the difference of @@ to cut and cute. In the latter each pair <> accepts different arguments, whereas in the former different holes are needed.
- holes #!optional symprocedure
documentation procedure. Shows either the list of exported symbols or the documentation of sym.
- (@@ code)syntax
extracts the holes out of the argument expression, code, sorts them numerically while removing dups and considers the resulting list as the argument list of a procedure, with code as body.
Note, that (@@ xpr) is always a procedure, maybe a thunk, if there are no holes in xpr.
- @> proc #!rest headprocedure
returns a curried procedure with arguments tail, which applies proc to (append head tail)
- @< proc #!rest tailprocedure
returns a curried procedure with arguments head, which applies proc to (append head tail)
((@> map add1) '(0 1 2)) ; -> '(1 2 3) ((@< list-ref 2) '(0 1 2 3)) ; -> 2 ((@@ 5)) ; -> 5 (((@@ (lambda (x) (- x <>))) 2) 3) ; ->1 (call-with-values (@@ (values 1 2 3)) list) ;-> '(1 2 3) ((@@ (list 1 2 (vector 3 4 <> 6))) 5) ; ->'(1 2 #(3 4 5 6)) ((@@ (list 1 2 '#(3 4 <> 6)))) ; note that the third arg of list is quoted ; hence there are no holes ; -> '(1 2 #(3 4 <> 6)) ((@@ (list (cons <2> <1>) (cons <1> <2>))) 'a 'b) ; -> '((b . a) (a . b))
Nov 11, 2019
This egg is hosted on the CHICKEN Subversion repository:
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Copyright (c) 2016-2019, Juergen Lorenz All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- parameter hole-delimiters and read macros removed, only delimiters < and > accepted instead of bangs
- parameter hole-delimiters added accepting "<>" or "!!"
- port from chicken-4, version 1.4, with modifications