1 Evaluation
(require neuron/evaluation) | package: neuron |
The bind form offers an alternative to match-lambda for specifying steppers with Racket’s Pattern Matching sub-system.
syntax
(bind ([quoted-pat q-exp ...] ...) maybe-match maybe-else)
maybe-match =
| #:match ([pat p-exp ...] ...) maybe-else =
| #:else default
Creates a match-lambda with quoted-pats implicitly
quasiquoted. If pat clauses are given, they are appended
to the quoted-pat clauses unmodified. If default is given,
a final catch-all clause that returns default is added.
Example:
> (define vars (make-hash))
> (define calc (bind ([(,a + ,b) (+ (calc a) (calc b))] [(,a ^ ,b) (expt (calc a) (calc b))] [(,a = ,b) (hash-set! vars a (calc b)) (hash-ref vars a)]) #:match ([(? number? n) n] [(? symbol? x) (hash-ref vars x)]) #:else 'stuck)) > (calc '(a = 2)) 2
> (calc '(b = ((a ^ 3) + (3 ^ a)))) 17
> vars '#hash((a . 2) (b . 17))