Changeset 37988 in project
- Timestamp:
- 11/11/19 13:58:11 (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/5/holes
r37979 r37988 8 8 9 9 Besides the documentation procedure, this module exports two curry 10 procedures, @> and @<, one macro, @@, and a sharp-read-macro, ##, as11 well as a read-macro, ^, which abbreviates the call of that latter 12 macro.They all create partial procedures.10 procedures, @> and @<, and one macro, @@, which implements the holes 11 mechanism. 12 They all create partial procedures. 13 13 14 Holes are spezial identifiers, enclosing zero or more digits either by <15 and >, the new way, or by bangs !!, the old way. You can choose between 16 the two versions with a parameter named hole-delimiters.14 Holes are spezial identifiers, delimited by < and >, possibly enclosing 15 zero or more digits. This new syntax replaces the old one, where both 16 delimiters were bangs. 17 17 18 18 The macro @@ transforms expressions with zero or more holes into a 19 19 procedure which has as many arguments as there are different holes in 20 20 the expression. Moreover, the arguments are ordered according to the 21 digits enclosed by the delimiters. 22 23 For example, (@@ 5), ##5 or ^5, which are all the same, is a thunk, 24 because there are no holes. And ^(- <2> <1> <2>) is a procedure of two 21 digits enclosed by the delimiters. For example, (@@ 5), is a thunk, 22 because there are no holes. And (@@ (- <2> <1> <2>)) is a procedure of two 25 23 arguments, <1> and <2> in this order, returning (- 20 10 20) when 26 applied to 10 20: ( ^(- <2> <1> <2>) 10 20) is -10.24 applied to 10 20: ((@@(- <2> <1> <2>)) 10 20) is -10. 27 25 28 26 But holes aren't restricted to flat list expressions, nested ones are 29 accepted as well. For example, ^(+ 5 (* <> 2)) is a unary procedure27 accepted as well. For example, (@@ (+ 5 (* <> 2))) is a unary procedure 30 28 which applied to 7 gives 19. The holes may appear in different 31 29 nesting levels, which gives great flexibility. 32 30 33 Notice the difference of @@ to cut and cute, where two pairs <> <> accept 34 different arguments, @@ would accept only one. 31 Notice the difference of @@ to cut and cute. In the latter each pair 32 <> accepts different arguments, whereas in the former different holes 33 are needed. 35 34 36 35 === Documentation … … 43 42 the documentation of sym. 44 43 45 ==== hole-delimiters46 47 <parameter>(hole-delimiters [str])</parameter>48 49 returns or sets the hole-delimiters to either "<>", the default, or50 "!!".51 52 44 ==== @@ 53 45 … … 58 50 argument list of a procedure, with code as body. 59 51 60 This macro can be called with sharp-read-syntax ## as well. Note, that 61 ##xpr is always a procedure, maybe a thunk, if there are no holes in 62 xpr. 52 Note, that (@@ xpr) is always a procedure, maybe a thunk, if there are no 53 holes in xpr. 63 54 64 55 ==== @> … … 84 75 ((@> map add1) '(0 1 2)) ; -> '(1 2 3) 85 76 ((@< list-ref 2) '(0 1 2 3)) ; -> 2 77 86 78 ((@@ 5)) ; -> 5 87 (##5) ; -> 5 88 ##(vector 1 !!) ; -> procedure 89 (call-with-values ##(values 1 2 3) list) 90 ; -> '(1 2 3) 91 (##(+ !1! 5) 2) ; -> 7 92 (##'(1 . 2)) ; -> '(1 . 2) 93 (##(+ 5 (* !! 2)) 7) ; -> 19 94 (##(!! 1 2 3) *) ; -> 6 95 (##(!! 1 2 3) +) ; -> 6 96 (##(list 1 2 (vector 3 4 !! 6)) 5) 97 ; -> '(1 2 #(3 4 5 6)) 98 (##(list 1 2 #(3 4 !! 6))) 99 ; note that the third arg of list is quoted 100 ; hence there are no holes and we get a thunk 101 ; -> '(1 2 #(3 4 !! 6))) 102 (##(vector 1 2 !!) 3) 103 ; -> #(1 2 3) 104 (##(list 1 !! 2 !1!) 3 4) 105 ; -> '(1 3 2 4) 106 (##(list 1 !! 2 !!) 3) 107 ; -> '(1 3 2 3) 108 (##(list 1 !! 2 (vector !!)) 3) 109 ; -> '(1 3 2 #(3)) 110 ((##(lambda (x) (- x !!)) 2) 3) ; -> 1 111 (##(list !! !1! 2 (vector !!)) 1 2) 112 ; -> '(1 2 2 #(1))) 113 (##(cons !2! !1!) 1 2) ; -> '(2 . 1) 114 (##(list (cons !2! !1!) (cons !1! !2!)) 1 2) 115 ; -> '((2 . 1) (1 . 2)) 116 (##(x y : (+ x y)) 1 2) ; -> 3 79 80 (((@@ (lambda (x) (- x <>))) 2) 3) ; ->1 81 82 (call-with-values 83 (@@ (values 1 2 3)) 84 list) 85 ;-> '(1 2 3) 86 87 ((@@ (list 1 2 (vector 3 4 <> 6))) 5) 88 ; ->'(1 2 #(3 4 5 6)) 89 90 ((@@ (list 1 2 '#(3 4 <> 6)))) 91 ; note that the third arg of list is quoted 92 ; hence there are no holes 93 ; -> '(1 2 #(3 4 <> 6)) 94 95 ((@@ (list (cons <2> <1>) (cons <1> <2>))) 1 2) 96 ; -> '((2 . 1) (1 . 2)) 117 97 </enscript> 118 98 … … 123 103 == Last update 124 104 125 Nov 07, 2019105 Nov 11, 2019 126 106 127 107 == Author … … 161 141 162 142 == Version History 143 ; 1.2 : parameter hole-delimiters and read macros removed, 144 only delimiters < and > accepted instead of bangs 163 145 ; 1.1 : parameter hole-delimiters added accepting "<>" or "!!" 164 146 ; 1.0 : port from chicken-4, version 1.4, with modifications
Note: See TracChangeset
for help on using the changeset viewer.