mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Add internal definitions to derived forms
This commit adds internal definitions to the following derived forms: when, unless, cond, case, with-fluids, and and-let*. * doc/ref/api-control.texi (Conditionals): Update the syntax and docs of when, unless, cond, and case. * module/ice-9/and-let-star.scm (and-let*): Changed begins to let. * module/ice-9/boot-9.scm (cond, case, when, unless, with-fluids): Changed begins to let.
This commit is contained in:
parent
9b20ca275d
commit
764e3614b8
3 changed files with 22 additions and 21 deletions
|
@ -152,10 +152,10 @@ documentation:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
(define-syntax-rule (when test stmt stmt* ...)
|
(define-syntax-rule (when test stmt stmt* ...)
|
||||||
(if test (begin stmt stmt* ...)))
|
(if test (let () stmt stmt* ...)))
|
||||||
|
|
||||||
(define-syntax-rule (unless test stmt stmt* ...)
|
(define-syntax-rule (unless test stmt stmt* ...)
|
||||||
(if (not test) (begin stmt stmt* ...)))
|
(if (not test) (let () stmt stmt* ...)))
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
That is to say, @code{when} evaluates its consequent statements in order
|
That is to say, @code{when} evaluates its consequent statements in order
|
||||||
|
@ -167,11 +167,11 @@ statements if @var{test} is false.
|
||||||
Each @code{cond}-clause must look like this:
|
Each @code{cond}-clause must look like this:
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(@var{test} @var{expression} @dots{})
|
(@var{test} @var{body} @dots{})
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
where @var{test} and @var{expression} are arbitrary expressions, or like
|
where @var{test} is an arbitrary expression and @var{body} is a
|
||||||
this
|
lambda-like body, or like this
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(@var{test} => @var{expression})
|
(@var{test} => @var{expression})
|
||||||
|
@ -217,7 +217,7 @@ result of the @code{cond}-expression.
|
||||||
@var{key} may be any expression, and the @var{clause}s must have the form
|
@var{key} may be any expression, and the @var{clause}s must have the form
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
((@var{datum1} @dots{}) @var{expr1} @var{expr2} @dots{})
|
((@var{datum1} @dots{}) @var{body} @dots{})
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
or
|
or
|
||||||
|
@ -229,7 +229,7 @@ or
|
||||||
and the last @var{clause} may have the form
|
and the last @var{clause} may have the form
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
(else @var{expr1} @var{expr2} @dots{})
|
(else @var{expr1} @var{body} @dots{})
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
or
|
or
|
||||||
|
@ -239,13 +239,14 @@ or
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
All @var{datum}s must be distinct. First, @var{key} is evaluated. The
|
All @var{datum}s must be distinct. First, @var{key} is evaluated. The
|
||||||
result of this evaluation is compared against all @var{datum} values using
|
result of this evaluation is compared against all @var{datum} values
|
||||||
@code{eqv?}. When this comparison succeeds, the expression(s) following
|
using @code{eqv?}. When this comparison succeeds, the @var{body}
|
||||||
the @var{datum} are evaluated from left to right, returning the value of
|
following the @var{datum} is evaluated like the body of a lambda,
|
||||||
the last expression as the result of the @code{case} expression.
|
returning the value of the last expression as the result of the
|
||||||
|
@code{case} expression.
|
||||||
|
|
||||||
If the @var{key} matches no @var{datum} and there is an
|
If the @var{key} matches no @var{datum} and there is an
|
||||||
@code{else}-clause, the expressions following the @code{else} are
|
@code{else}-clause, the @var{body} following the @code{else} is
|
||||||
evaluated. If there is no such clause, the result of the expression is
|
evaluated. If there is no such clause, the result of the expression is
|
||||||
unspecified.
|
unspecified.
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@
|
||||||
((_ orig-form ((var expr)) . body)
|
((_ orig-form ((var expr)) . body)
|
||||||
(identifier? #'var)
|
(identifier? #'var)
|
||||||
#'(let ((var expr))
|
#'(let ((var expr))
|
||||||
(and var (begin . body))))
|
(and var (let () . body))))
|
||||||
((_ orig-form ((expr)) . body)
|
((_ orig-form ((expr)) . body)
|
||||||
#'(and expr (begin . body)))
|
#'(and expr (let () . body)))
|
||||||
((_ orig-form (var) . body)
|
((_ orig-form (var) . body)
|
||||||
(identifier? #'var)
|
(identifier? #'var)
|
||||||
#'(and var (begin . body)))
|
#'(and var (let () . body)))
|
||||||
|
|
||||||
;; Handle bad clauses.
|
;; Handle bad clauses.
|
||||||
((_ orig-form (bad-clause . rest) . body)
|
((_ orig-form (bad-clause . rest) . body)
|
||||||
|
|
|
@ -417,10 +417,10 @@ If returning early, return the return value of F."
|
||||||
(include-from-path "ice-9/quasisyntax")
|
(include-from-path "ice-9/quasisyntax")
|
||||||
|
|
||||||
(define-syntax-rule (when test stmt stmt* ...)
|
(define-syntax-rule (when test stmt stmt* ...)
|
||||||
(if test (begin stmt stmt* ...)))
|
(if test (let () stmt stmt* ...)))
|
||||||
|
|
||||||
(define-syntax-rule (unless test stmt stmt* ...)
|
(define-syntax-rule (unless test stmt stmt* ...)
|
||||||
(if (not test) (begin stmt stmt* ...)))
|
(if (not test) (let () stmt stmt* ...)))
|
||||||
|
|
||||||
(define-syntax else
|
(define-syntax else
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
@ -461,7 +461,7 @@ If returning early, return the return value of F."
|
||||||
((else e e* ...)
|
((else e e* ...)
|
||||||
(lambda (tail)
|
(lambda (tail)
|
||||||
(if (null? tail)
|
(if (null? tail)
|
||||||
#'((begin e e* ...))
|
#'((let () e e* ...))
|
||||||
(bad-clause "else must be the last clause"))))
|
(bad-clause "else must be the last clause"))))
|
||||||
((else . _) (bad-clause))
|
((else . _) (bad-clause))
|
||||||
((test => receiver)
|
((test => receiver)
|
||||||
|
@ -488,7 +488,7 @@ If returning early, return the return value of F."
|
||||||
((test e e* ...)
|
((test e e* ...)
|
||||||
(lambda (tail)
|
(lambda (tail)
|
||||||
#`((if test
|
#`((if test
|
||||||
(begin e e* ...)
|
(let () e e* ...)
|
||||||
#,@tail))))
|
#,@tail))))
|
||||||
(_ (bad-clause))))
|
(_ (bad-clause))))
|
||||||
#'(clause clauses ...))))))))
|
#'(clause clauses ...))))))))
|
||||||
|
@ -534,7 +534,7 @@ If returning early, return the return value of F."
|
||||||
((=> receiver ...)
|
((=> receiver ...)
|
||||||
(bad-clause
|
(bad-clause
|
||||||
"wrong number of receiver expressions"))
|
"wrong number of receiver expressions"))
|
||||||
((e e* ...) #'(begin e e* ...))
|
((e e* ...) #'(let () e e* ...))
|
||||||
(_ (bad-clause)))))
|
(_ (bad-clause)))))
|
||||||
(syntax-case #'test (else)
|
(syntax-case #'test (else)
|
||||||
((datums ...)
|
((datums ...)
|
||||||
|
@ -674,7 +674,7 @@ If returning early, return the return value of F."
|
||||||
#`(let ((fluid-tmp fluid) ...)
|
#`(let ((fluid-tmp fluid) ...)
|
||||||
(let ((val-tmp val) ...)
|
(let ((val-tmp val) ...)
|
||||||
#,(emit-with-fluids #'((fluid-tmp val-tmp) ...)
|
#,(emit-with-fluids #'((fluid-tmp val-tmp) ...)
|
||||||
#'(begin exp exp* ...)))))))))
|
#'(let () exp exp* ...)))))))))
|
||||||
|
|
||||||
(define-syntax current-source-location
|
(define-syntax current-source-location
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue