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

Last change on this file since 33697 was 33697, checked in by juergen, 3 years ago

holes 1.1

File size: 3.6 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 xpr)</macro>
34
35extracts the holes out of the argument expression, removes duplicates,
36and considers the resulting list as the argument list of a procedure,
37with xpr 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</enscript>
73
74=== Requirements
75
76none
77
78== Last update
79
80Oct 04, 2016
81
82== Author
83
84[[/users/juergen-lorenz|Juergen Lorenz]]
85
86== License
87
88 Copyright (c) 2016, Juergen Lorenz
89 All rights reserved.
90
91 Redistribution and use in source and binary forms, with or without
92 modification, are permitted provided that the following conditions are
93 met:
94 
95 Redistributions of source code must retain the above copyright
96 notice, this list of conditions and the following disclaimer.
97 
98 Redistributions in binary form must reproduce the above copyright
99 notice, this list of conditions and the following disclaimer in the
100 documentation and/or other materials provided with the distribution.
101 Neither the name of the author nor the names of its contributors may be
102 used to endorse or promote products derived from this software without
103 specific prior written permission.
104   
105 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
106 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
107 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
108 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
109 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
110 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
111 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
112 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
113 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
114 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
115 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116
117== Version History
118; 1.1 : bug with adjacent holes fixed, regexes replaced
119; 1.0 : initial import
120
121
122
Note: See TracBrowser for help on using the repository browser.