From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: doco srfi-2 and-let* Date: Sat, 17 May 2003 09:59:53 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87issao32e.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1053129683 8173 80.91.224.249 (17 May 2003 00:01:23 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 17 May 2003 00:01:23 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat May 17 02:01:20 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19Gp8a-00027V-00 for ; Sat, 17 May 2003 02:01:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19Gp8y-0001oK-0A for guile-devel@m.gmane.org; Fri, 16 May 2003 20:01:44 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19Gp89-0001Nn-00 for guile-devel@gnu.org; Fri, 16 May 2003 20:00:53 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19Gp7x-0000qR-00 for guile-devel@gnu.org; Fri, 16 May 2003 20:00:45 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19Gp7U-0008JG-00 for guile-devel@gnu.org; Fri, 16 May 2003 20:00:12 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h4H009Pc024381 for ; Sat, 17 May 2003 10:00:10 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h4H009Qg012176 for ; Sat, 17 May 2003 10:00:09 +1000 (EST) Original-Received: from localhost (ppp65.dyn228.pacific.net.au [203.143.228.65]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h4H007YZ017573 for ; Sat, 17 May 2003 10:00:08 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19Gp7C-0000Pm-00; Sat, 17 May 2003 09:59:54 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2379 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2379 I'd like to propose * srfi-modules.texi (SRFI-2): Rewrite and-let*, adding plain expression clauses and improving the examples. New text below. I quite like the first example, which I think is realistic and sensible. But the second is a bit of a contrivance and I'd be open to better ideas. SRFI-2 - and-let* ================= The following syntax can be obtained with (use-modules (srfi srfi-2)) - library syntax: and-let* (clause ...) body ... A combination of `and' and `let*'. Each CLAUSE is evaluated in turn, and if `#f' is obtained then evaluation stops and `#f' is returned. If all are non-`#f' then BODY is evaluated and the last form gives the return value. Each CLAUSE should be one of the following forms, `(symbol expr)' Evaluate EXPR, check for `#f', and bind it to SYMBOL. Like `let*', that binding is available to subsequent clauses. `(expr)' Evaluate EXPR and check for `#f'. `symbol' Get the value bound to SYMBOL and check for `#f'. Notice that `(expr)' has an "extra" pair of parentheses, for instance `((eq? x y))'. One way to remember this is to imagine the `symbol' in `(symbol expr)' is omitted. `and-let*' is good for calculations where a `#f' value means termination, but where a non-`#f' value is going to be needed in subsequent expressions. The following illustrates this, it returns text between brackets `[...]' in a string, or `#f' if there are no such brackets (ie. either `string-index' gives `#f'). (define (extract-brackets str) (and-let* ((start (string-index str #\[)) (end (string-index str #\] start))) (substring str (1+ start) end))) The following shows plain variables and expressions tested too. `diagnostic-levels' is taken to be an alist associating a diagnostic type with a level. `str' is printed only if the type is known and its level is high enough. (define (show-diagnostic type str) (and-let* (want-diagnostics (level (assq-ref diagnostic-levels type)) ((>= level current-diagnostic-level))) (display str))) The advantage of `and-let*' is that an extended sequence of expressions and tests doesn't require lots of nesting as would arise from separate `and' and `let*', or from `cond' with `=>'. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel