Changeset 38643 in project


Ignore:
Timestamp:
04/25/20 12:50:55 (6 weeks ago)
Author:
juergen
Message:

bindings-3.2 docu with improved bind-case and bindable?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/bindings

    r38229 r38643  
    1313This library provides an alternative to matchable, a bunch of macros,
    1414all starting with the bind prefix, and all being derived from bind
    15 and related macros.  They destructure nested pseudolist which match a
     15and related macros.  They destructure nested pseudolists which match a
    1616pattern and can be easily enhanced to accept other sequence types as
    1717well, vectors, strings, arrays, or what have you. All this sequence
     
    189189==== bindable?
    190190
     191<macro>(bindable? pat (where fender ...) seq)</macro>
     192<macro>(bindable? pat seq)</macro>
     193<macro>(bindable? pat (where fender ...))</macro>
    191194<macro>(bindable? pat)</macro>
    192 
    193 returns a unary predicate which checks, if its sequence argument matches
    194 the pattern argument, pat.
     195The first two forms check if sequence seq matches pattern pat,
     196with optional fenders, i.e. boolean expressions.
     197The second two forms are curried versions of the first two.
    195198
    196199====  bind-case
    197200
     201<macro>(bind-case seq (pat (where fender ...) xpr ....) ....)</macro>
    198202<macro>(bind-case seq (pat xpr ....) ....)</macro>
    199203
    200204Matches seq against a series of patterns and executes the body of the
    201 first matching pattern.
     205first matching pattern. Fenders, i.e. boolean expressions,  are optional.
    202206
    203207==== bind-lambda
     
    215219==== bind-case-lambda
    216220
     221<macro>(bind-case-lambda (pat (where fender ...) xpr ....) ....)</macro>
    217222<macro>(bind-case-lambda (pat xpr ....) ....)</macro>
    218223
     
    221226==== bind-case-lambda*
    222227
     228<macro>(bind-case-lambda* (pat (where fender ...) xpr ....) ....)</macro>
    223229<macro>(bind-case-lambda* (pat xpr ....) ....)</macro>
    224230
     
    438444; -> #f
    439445
     446(bindable? (a b) (where (even? a) (odd? b)) '(2 2))
     447; -> #f
     448
    440449(bind-case #(1 2)
    441450  (() '())
     
    444453  ((a b c) (list a b c)))
    445454; -> '(1 2))
     455
     456(bind-case #(2 2)
     457  ((a b) (where (even? a) (odd? b)) (print 'even-odd a b))
     458  ((a b) (where (odd? a) (even? b)) (print 'odd-even a b))
     459  ((a b) (list a b)))
     460; -> '(2 2)
    446461
    447462(define (my-map fn lst)
     
    500515== Last update
    501516
    502 Feb 27, 2020
     517Apr 25, 2020
    503518
    504519== Author
     
    538553
    539554== Version History
     555; 3.2 : bindable? now in two forms, bind-case improved, both with optional fenders.
    540556; 3.1 : bind* now deprecated, use bind-loop instead.
    541557; 3.0.1 : bugs in bind and bind-listify* fixed
Note: See TracChangeset for help on using the changeset viewer.