Changeset 37988 in project


Ignore:
Timestamp:
11/11/19 13:58:11 (4 weeks ago)
Author:
juergen
Message:

holes 1.2 with new delimiters and without read macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/holes

    r37979 r37988  
    88
    99Besides the documentation procedure, this module exports two curry
    10 procedures, @> and @<, one macro, @@, and a sharp-read-macro, ##, as
    11 well as a read-macro, ^, which abbreviates the call of that latter
    12 macro. They all create partial procedures.
     10procedures, @> and @<, and one macro, @@, which implements the holes
     11mechanism.
     12They all create partial procedures.
    1313
    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.
     14Holes are spezial identifiers, delimited by < and >, possibly enclosing
     15zero or more digits. This new syntax replaces the old one, where both
     16delimiters were bangs.
    1717
    1818The macro @@ transforms expressions with zero or more holes into a
    1919procedure which has as many arguments as there are different holes in
    2020the 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
     21digits enclosed by the delimiters.  For example, (@@ 5), is a thunk,
     22because there are no holes. And (@@ (- <2> <1> <2>)) is a procedure of two
    2523arguments, <1> and <2> in this order, returning (- 20 10 20) when
    26 applied to 10 20: (^(- <2> <1> <2>) 10 20) is -10.
     24applied to 10 20: ((@@(- <2> <1> <2>)) 10 20) is -10.
    2725
    2826But holes aren't restricted to flat list expressions, nested ones are
    29 accepted as well. For example, ^(+ 5 (* <> 2)) is a unary procedure
     27accepted as well. For example, (@@ (+ 5 (* <> 2))) is a unary procedure
    3028which applied to 7 gives 19. The holes may appear in different
    3129nesting levels, which gives great flexibility.
    3230
    33 Notice the difference of @@ to cut and cute, where two pairs <> <> accept
    34 different arguments, @@ would accept only one.
     31Notice the difference of @@ to cut and cute. In the latter each pair
     32<> accepts different arguments, whereas in the former different holes
     33are needed.
    3534
    3635=== Documentation
     
    4342the documentation of sym.
    4443
    45 ==== hole-delimiters
    46 
    47 <parameter>(hole-delimiters [str])</parameter>
    48 
    49 returns or sets the hole-delimiters to either "<>", the default, or
    50 "!!".
    51 
    5244==== @@
    5345
     
    5850argument list of a procedure, with code as body.
    5951
    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.
     52Note, that (@@ xpr) is always a procedure, maybe a thunk, if there are no
     53holes in xpr.
    6354
    6455==== @>
     
    8475((@> map add1) '(0 1 2)) ; -> '(1 2 3)
    8576((@< list-ref 2) '(0 1 2 3)) ; -> 2
     77
    8678((@@ 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))
    11797</enscript>
    11898
     
    123103== Last update
    124104
    125 Nov 07, 2019
     105Nov 11, 2019
    126106
    127107== Author
     
    161141
    162142== Version History
     143; 1.2 : parameter hole-delimiters and read macros removed,
     144        only delimiters < and > accepted instead of bangs
    163145; 1.1 : parameter hole-delimiters added accepting "<>" or "!!"
    164146; 1.0 : port from chicken-4, version 1.4,  with modifications
Note: See TracChangeset for help on using the changeset viewer.