source code: https://github.com/AlexKnauth/mutable-match-lambda
> my+#<procedure:my+>
> (my+12)3
> (mutable-match-lambda-add-clause! my+#:match-lambda*[(list (?vector? vs)... )(apply vector-map + vs)])> (my+#(12)#(34))'#(4 6)
struct
#:mutable#:transparent)name:any/c
procedure
...[ #:namename])proc:procedure?
procedure
clause-proc:procedure?procedure
procclause-proc...)clause-proc:procedure?
clause-procs)))
> (mutable-match-lambda-add-clause-proc! my+(clause->proc #:match-lambda*[(list (?number? ns)... )(apply + ns)]))> (my+12)3
> (mutable-match-lambda-add-clause-proc! my+(clause->proc #:match-lambda*[(list (?vector? vs)... )(apply vector-map + vs)]))> (my+#(12)#(34))'#(4 6)
> (my+12)3
> (my+#(12)#(34))'#(4 6)
> (my+"not a number or a vector")7
> (my+12)42
syntax
( mutable-match-lambda-add-clause! proc-exprclause-proc-expr...)
syntax
( mutable-match-lambda-add-overriding-clause! proc-exprclause-proc-expr...)
> (my+12)3
> (mutable-match-lambda-add-clause! my+#:match-lambda*[(list (?vector? vs)... )(apply vector-map + vs)])> (my+#(12)#(34))'#(4 6)
> (my+12)3
> (my+#(12)#(34))'#(4 6)
> (my+"not a number or a vector")7
> (my+12)42
procedure
...proc:procedure?
This is what mutable-match-lambda-procedure uses to combine its clauses.
procedure
It is similar in spirit to match ’s failure-cont , except that it does escape the current context, and it cares about the dynamic extent, not syntactic scope.
procedure
...[ #:namename])proc:procedure?
The difference between this and make-mutable-match-lambda is that if a proc is a mutable-match-lambda-procedure , then its procs are spliced into the resulting list. As a result the mutable-match-lambda-procedures are effectively copied (and in fact mutable-match-lambda-copy is defined with mutable-match-lambda-append ).
If you don’t want this copying behavior, you can use make-mutable-match-lambda to achieve that.
procedure
( mutable-match-lambda-copy proc)
proc:procedure?
It is equivalent to (mutable-match-lambda-append proc#:name(mutable-match-lambda-procedure-name proc)).
syntax
( make-mutable-match-lambda/infer-name proc-expr...)
It is used to infer the names for forms like mutable-case-lambda and mutable-match-lambda .
syntax
( mutable-case-lambda case-lambda-clause...)
> (examples)examples: undefined;
cannot reference an identifier before its definition
in module: top-level
syntax
( mutable-match-lambda match-lambda-clause...)
> (examples)examples: undefined;
cannot reference an identifier before its definition
in module: top-level
syntax
( mutable-match-lambda* match-lambda*-clause...)
> (examples)examples: undefined;
cannot reference an identifier before its definition
in module: top-level
procedure
( make-clause-proc test-procthen-proc)→procedure?
test-proc:procedure?then-proc:procedure?
> (my+12)3
> (clause-112)3
> (my+#(12)#(34))'#(4 6)
> (clause-2#(12)#(34))'#(4 6)
syntax
( clause->proc kwclause)
For example (clause->proc #:match-lambda*match-lambda*-clause) creates a clause-proc that acts like a match-lambda* clause. It actually expands to (clause->proc/match-lambda* match-lambda*-clause), and then clause->proc/match-lambda* does the rest.
(clause->proc #:whateverclause) expands to (clause->proc/whateverclause), so if you define a macro with the name clause->proc/whatever, then you can use (clause->proc #:whateverclause).
When defining a new clause->proc/whatever macro, it should call mutable-match-lambda-next if it doesn’t match.
clause->proc/case-lambda , clause->proc/match-lambda , and clause->proc/match-lambda* are already defined, so to start with clause->proc supports #:case-lambda, #:match-lambda, and #:match-lambda* as keywords.
#<procedure:(clause->proc #:case-lambda ((x y) (list x y)))>
ans> (f#t)42
> (f#f)"didn't match"
syntax
( clause->proc/case-lambda clause)
syntax
( clause->proc/match-lambda clause)
syntax
( clause->proc/match-lambda* clause)