Changeset 38844 in project


Ignore:
Timestamp:
08/14/20 18:32:40 (4 months ago)
Author:
juergen
Message:

dotted-lambdas 1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/dotted-lambdas

    r38830 r38844  
    33
    44
    5 == Lambdas with dots as symbols
     5== Lambda equivalents with dots as trailing symbols
    66
    77Scheme lambdas allow for variable length argument lists by using a
     
    1313The meaning of theses symbols is
    1414
    15 * two dots: the argument to the left references a callable list
    16             with zero or one items
     15* two dots:   the argument to the left references a callable list
     16              with zero or one items
    1717* three dots: the argument to the left references a callable list
    18 * four dots: the argument to the left references a nonempty callable list
     18* four dots:  the argument to the left references a nonempty callable list
    1919
    20 We've used callable instead of ordinary lists for ease of use. Indeed,
    21 (lst 3) is much easyer on the fingers than (list-ref lst 3). Moreover,
    22 they are much more flexible, because they allow for slices, e.g.
    23 (lst 2 4) and (lst 4 2).
     20Using the appropriate dots-type gives you additional control over the
     21length of the variable argument lists.
     22
     23We've used callable-sequences instead of ordinary lists for ease of use.
     24Indeed, (lst 3) is much easyer on the fingers than (list-ref lst 3).
     25Moreover, they are much more flexible, because they allow for slices,
     26e.g.  (lst 2 4) and (lst 4 2) returning callable-sequences encapsulating
     27'(2 3) and '(4 3) respectively.
    2428
    2529Note, that there is an egg written by Mario, named callable-data-structures,
    2630which could have been used instead.
    2731
    28 The implementation of the macro is quite simple. I use a Chicken
    29 extension of syntax-rules, which allows to replace ellipses with another
    30 symbol, here !!!. So I can use e.g. ... as a keyword.
     32The implementation of the macro is quite simple. I use a not so
     33well-known Chicken extension of syntax-rules, which allows to replace
     34ellipses with another symbol, here !!!. So I can use e.g. ... as a
     35keyword.
    3136
    3237=== API
     
    3843
    3944returns the list of exported symbols, if called without argument, or the
    40 documentation of sym otherwise
     45documentation of sym otherwise.
    4146
    4247==== lambda*
     
    5257=== Requirements
    5358
    54 callables
     59callable-sequences
    5560
    5661=== Examples
     
    5863<enscript highlight=scheme>
    5964
    60 (import dotted-lambdas callables (chicken condition))
     65(import dotted-lambdas callable-sequences (chicken condition))
    6166
    6267((lambda* (xs ...)
    6368   (list (xs 0) (xs 1) (xs 2))) 1 2 3)
    6469; -> '(1 2 3)
     70
    6571(condition-case
    6672  ((lambda* (xs ..) xs) 1 2 3)
    6773  ((exn) #f))
    6874; -> #f
     75
    6976(condition-case
    7077  ((lambda* (xs ....) xs))
    7178  ((exn) #f))
    7279; -> #f
     80
    7381((lambda* (xs ...) (xs)))
    7482; -> '()
     83
    7584((lambda* (x y zs ...) (list x y (zs 0) (zs 1))) 1 2 3 4)
    7685; -> '(1 2 3 4)
     86
    7787(condition-case
    7888  ((lambda* (x y zs ..) (list x y zs)) 1 2 3 4)
    7989  ((exn) #f))
    8090; -> #f
     91
    8192(condition-case
    8293  ((lambda* (x y zs ....) (list x y zs)) 1 2)
    8394  ((exn) #f))
    8495; -> #f
     96
    8597((lambda* (a b) (list a b)) 1 2)
    8698; -> '(1 2)
     99
    87100((lambda* (a b . cs) (list a b cs)) 1 2 3 4)
    88101; -> '(1 2 (3 4))
     102
    89103((lambda* as as) 1 2 3)
    90104; -> '(1 2 3)
     105
    91106((lambda* as as))
    92107; -> '()
     
    96111== Last update
    97112
    98 Aug 11, 2020
     113Aug 14, 2020
    99114
    100115== Author
Note: See TracChangeset for help on using the changeset viewer.