source: project/wiki/eggref/4/holes @ 33706

Last change on this file since 33706 was 33706, checked in by juergen, 4 years ago

holes 1.2 docu updated

File size: 3.8 KB
Line 
1[[tags: egg]]
2
3== holes
4
5[[toc:]]
6
7=== Description
8
9Besides the documentation procedure, this module exports only one macro,
10->proc, and a sharp-read-macro, ##, which abbreviates the call of
11that macro.
12
13The macro transforms expressions with zero or more holes into a
14procedure. Insofar, it's a bit like cut or cute. But while in cut or
15cute a hole is the special identifier <>, in this module it's a pair of
16bangs, possibly enclosing a sequence of digits, for examples !! or !1!.
17In this way, holes needn't name different variables like in cut or cute.
18
19Another difference to cut or cute is, that the holes may appear in
20nested expressions at different levels. This gives great flexibility.
21And the sharp-read-syntax ## adds ease of use.
22
23=== Documentation
24
25==== holes
26
27<procedure>(holes)</procedure>
28
29shows the definition of the ->proc macro.
30
31==== ->proc
32
33<macro>(->proc code)</macro>
34
35extracts the holes out of the argument expression, code, sorts them
36numerically while removing dups and considers the resulting list as the
37argument list of a procedure, with code as body.
38
39This macro can be called with sharp-read-syntax ## as well. Note, that
40##xpr is always a procedure, maybe a thunk, if there are no holes in
41xpr.
42
43=== Examples
44
45<enscript highlight=scheme>
46(vector 1 !!) ; -> procedure
47(##5) ; -> 5
48(call-with-values ##(values 1 2 3) list)
49  ; -> '(1 2 3)
50(##(+ !1! 5) 2) ; -> 7
51(##'(1 . 2)) ; -> '(1 . 2)
52(##(+ 5 (* !! 2)) 7) ; -> 19
53(##(!! 1 2 3) *) ; -> 6
54(##(!! 1 2 3) +) ; -> 6
55(##(list 1 2 (vector 3 4 !! 6)) 5)
56   ; -> '(1 2 #(3 4 5 6))
57(##(list 1 2 #(3 4 !! 6)))
58   ; note that the third arg of list is quoted
59   ; hence there are no holes and we get a thunk
60   ; -> '(1 2 #(3 4 !! 6)))
61(##(vector 1 2 !!) 3)
62   ; -> #(1 2 3)
63(##(list 1 !! 2 !1!) 3 4)
64   ; -> '(1 3 2 4)
65(##(list 1 !! 2 !!) 3)
66   ; -> '(1 3 2 3)
67(##(list 1 !! 2 (vector !!)) 3)
68   ; -> '(1 3 2 #(3))
69((##(lambda (x) (- x !!)) 2) 3) ; -> 1
70(##(list !! !1! 2 (vector !!)) 1 2)
71   ; -> '(1 2 2 #(1)))
72(##(cons !2! !1!) 1 2) ; -> '(2 . 1)
73(##(list (cons !2! !1!) (cons !1! !2!)) 1 2)
74   ; -> '((2 . 1) (1 . 2))
75</enscript>
76
77=== Requirements
78
79none
80
81== Last update
82
83Oct 10, 2016
84
85== Author
86
87[[/users/juergen-lorenz|Juergen Lorenz]]
88
89== License
90
91 Copyright (c) 2016, Juergen Lorenz
92 All rights reserved.
93
94 Redistribution and use in source and binary forms, with or without
95 modification, are permitted provided that the following conditions are
96 met:
97 
98 Redistributions of source code must retain the above copyright
99 notice, this list of conditions and the following disclaimer.
100 
101 Redistributions in binary form must reproduce the above copyright
102 notice, this list of conditions and the following disclaimer in the
103 documentation and/or other materials provided with the distribution.
104 Neither the name of the author nor the names of its contributors may be
105 used to endorse or promote products derived from this software without
106 specific prior written permission.
107   
108 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
109 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
110 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
111 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
112 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
113 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
114 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
115 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
116 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
117 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
118 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119
120== Version History
121; 1.2 : holes now numerically sorted
122; 1.1 : bug with adjacent holes fixed, regexes replaced
123; 1.0 : initial import
124
125
126
Note: See TracBrowser for help on using the repository browser.