From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: let-keywords? Date: Thu, 14 Dec 2006 08:28:37 +1100 Message-ID: <87lklbo58a.fsf@zip.com.au> References: <8764cihuq2.fsf@zip.com.au> <457DF066.1060508@xs4all.nl> NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1166045350 14892 80.91.229.10 (13 Dec 2006 21:29:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Dec 2006 21:29:10 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Dec 13 22:29:07 2006 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1Guber-0008Mo-VT for guile-devel@m.gmane.org; Wed, 13 Dec 2006 22:28:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Guber-0000Mt-B3 for guile-devel@m.gmane.org; Wed, 13 Dec 2006 16:28:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Guben-0000Lt-P2 for guile-devel@gnu.org; Wed, 13 Dec 2006 16:28:53 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Gubel-0000K4-PR for guile-devel@gnu.org; Wed, 13 Dec 2006 16:28:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gubel-0000Jf-I3 for guile-devel@gnu.org; Wed, 13 Dec 2006 16:28:51 -0500 Original-Received: from [61.8.2.215] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.52) id 1Gubeg-0000ww-Jb for guile-devel@gnu.org; Wed, 13 Dec 2006 16:28:51 -0500 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.2.162]) by mailout1.pacific.net.au (Postfix) with ESMTP id CFE465A1E5A; Thu, 14 Dec 2006 08:28:41 +1100 (EST) Original-Received: from localhost (ppp245A.dyn.pacific.net.au [61.8.36.90]) by mailproxy1.pacific.net.au (Postfix) with ESMTP id 173038C08; Thu, 14 Dec 2006 08:28:41 +1100 (EST) Original-Received: from gg by localhost with local (Exim 4.63) (envelope-from ) id 1GubeZ-0007s6-87; Thu, 14 Dec 2006 08:28:39 +1100 Original-To: hanwen@xs4all.nl Mail-Copies-To: never In-Reply-To: <457DF066.1060508@xs4all.nl> (Han-Wen Nienhuys's message of "Tue, 12 Dec 2006 00:57:26 +0100") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6332 Archived-At: 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