From: Kevin Ryde <user42@zip.com.au>
Cc: guile-devel@gnu.org
Subject: Re: let-keywords?
Date: Thu, 14 Dec 2006 08:28:37 +1100 [thread overview]
Message-ID: <87lklbo58a.fsf@zip.com.au> (raw)
In-Reply-To: <457DF066.1060508@xs4all.nl> (Han-Wen Nienhuys's message of "Tue, 12 Dec 2006 00:57:26 +0100")
I checked in the text below.
5.8.3.2 let-keywords Reference
..............................
`let-keywords' and `let-keywords*' extract values from keyword style
argument lists, binding local variables to those values or to defaults.
-- library syntax: let-keywords args allow-other-keys? (binding ...)
body ...
-- library syntax: let-keywords* args allow-other-keys? (binding ...)
body ...
ARGS is evaluated and should give a list of the form `(#:keyword1
value1 #:keyword2 value2 ...)'. The BINDINGs are variables and
default expressions, with the variables to be set (by name) from
the keyword values. The BODY forms are then evaluated and the
last is the result. An example will make the syntax clearest,
(define args '(#:xyzzy "hello" #:foo "world"))
(let-keywords args #t
((foo "default for foo")
(bar (string-append "default" "for" "bar")))
(display foo)
(display ", ")
(display bar))
-| world, defaultforbar
The binding for `foo' comes from the `#:foo' keyword in `args'.
But the binding for `bar' is the default in the `let-keywords',
since there's no `#:bar' in the args.
ALLOW-OTHER-KEYS? is evaluated and controls whether unknown
keywords are allowed in the ARGS list. When true other keys are
ignored (such as `#:xyzzy' in the example), when `#f' an error is
thrown for anything unknown.
`let-keywords' is like `let' (*note Local Bindings::) in that all
bindings are made at once, the defaults expressions are evaluated
(if needed) outside the scope of the `let-keywords'.
`let-keywords*' is like `let*', each binding is made successively,
and the default expressions see the bindings previously made.
This is the style used by `lambda*' keywords (*note lambda*
Reference::). For example,
(define args '(#:foo 3))
(let-keywords* args #f
((foo 99)
(bar (+ foo 6)))
(display bar))
-| 9
The expression for each default is only evaluated if it's needed,
ie. if the keyword doesn't appear in ARGS. So one way to make a
keyword mandatory is to throw an error of some sort as the default.
(define args '(#:start 7 #:finish 13))
(let-keywords* args #t
((start 0)
(stop (error "missing #:stop argument")))
(display bar))
=> ERROR: missing #:stop argument
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2006-12-13 21:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-11 15:37 let-keywords? Han-Wen Nienhuys
2006-12-11 23:35 ` let-keywords? Kevin Ryde
2006-12-11 23:57 ` let-keywords? Han-Wen Nienhuys
2006-12-13 21:28 ` Kevin Ryde [this message]
2006-12-14 11:20 ` let-keywords? Han-Wen Nienhuys
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lklbo58a.fsf@zip.com.au \
--to=user42@zip.com.au \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).