From a956004715d4c299a12c6840eda514421e9c38e7 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Tue, 24 Dec 2013 16:30:59 +0100 Subject: [PATCH] Fix missing arg in pcase example. * doc/lispref/control.texi (Pattern matching case statement): Fix missing argument in simple expression language sample. Add some sample programs written in that language. Mention that `pcase' requires lexical binding. Fixes: debbugs:16238 --- doc/lispref/ChangeLog | 7 +++++++ doc/lispref/control.texi | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index bee08a59072..b1c210834d2 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,10 @@ +2013-12-24 Tassilo Horn + + * control.texi (Pattern matching case statement): Fix missing + argument in simple expression language sample (Bug#16238). Add + some sample programs written in that language. Mention that + `pcase' requires lexical binding. + 2013-12-23 Xue Fuqiao * eval.texi (Special Forms): Document `special-form-p'. diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 34a02aab69d..a9e7236fc3a 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -328,7 +328,7 @@ expression language could look like: (defun evaluate (exp env) (pcase exp (`(add ,x ,y) (+ (evaluate x env) (evaluate y env))) - (`(call ,fun ,arg) (funcall (evaluate fun) (evaluate arg env))) + (`(call ,fun ,arg) (funcall (evaluate fun env) (evaluate arg env))) (`(fn ,arg ,body) (lambda (val) (evaluate body (cons (cons arg val) env)))) ((pred numberp) exp) @@ -342,6 +342,19 @@ third elements and binds them to the variables @code{x} and @code{y}. @code{(pred numberp)} is a pattern that simply checks that @code{exp} is a number, and @code{_} is the catch-all pattern that matches anything. +Here are some sample programs including their evaluation results: + +@example +(evaluate '(add 1 2) nil) ;=> 3 +(evaluate '(add x y) '((x . 1) (y . 2))) ;=> 3 +(evaluate '(call (fn x (add 1 x)) 2) nil) ;=> 3 +(evaluate '(sub 1 2) nil) ;=> (error "Unknown expression (sub 1 2)") +@end example + +Note that (parts of) @code{pcase} only work as expected with lexical +binding, so lisp files using @code{pcase} should have enable it +(@pxref{Using Lexical Binding}, for how to enable lexical binding). + There are two kinds of patterns involved in @code{pcase}, called @emph{U-patterns} and @emph{Q-patterns}. The @var{upattern} mentioned above are U-patterns and can take the following forms: -- 2.39.2