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: doc srfi-0 cond-expand Date: Mon, 19 Jul 2004 09:12:31 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87658k3o68.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1090192643 4198 80.91.224.253 (18 Jul 2004 23:17:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 18 Jul 2004 23:17:23 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jul 19 01:17:14 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BmKu9-0001PQ-00 for ; Mon, 19 Jul 2004 01:17:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BmKwo-0002sU-5z for guile-devel@m.gmane.org; Sun, 18 Jul 2004 19:19:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BmKwZ-0002sJ-HL for guile-devel@gnu.org; Sun, 18 Jul 2004 19:19:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BmKwW-0002rw-Rw for guile-devel@gnu.org; Sun, 18 Jul 2004 19:19:42 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BmKwW-0002rh-Ol for guile-devel@gnu.org; Sun, 18 Jul 2004 19:19:40 -0400 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BmKtY-0007ee-O6 for guile-devel@gnu.org; Sun, 18 Jul 2004 19:16:37 -0400 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86]) by mailout1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6INGZ4u030469 for ; Mon, 19 Jul 2004 09:16:35 +1000 Original-Received: from localhost (ppp2DA0.dyn.pacific.net.au [61.8.45.160]) by mailproxy1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i6INGMap029054 for ; Mon, 19 Jul 2004 09:16:34 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1BmKpc-0000lp-00; Mon, 19 Jul 2004 09:12:32 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (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: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3867 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3867 Some new words below for cond-expand, a bit more concise, and emphasising that this is really meant for a portable scheme program. A couple more examples would be good, if anyone can think of something vaguely realistic. 2.1.1 SRFI-0 - cond-expand -------------------------- This SRFI lets a portable Scheme program test for the presence of certain features, and adapt itself by using different blocks of code, or fail if the necessary features are not available. A program designed only for Guile will generally not need this mechanism, such a program can of course directly use the various documented parts of Guile. -- syntax: cond-expand (feature body...) ... Expand to the BODY of the first clause whose FEATURE specification is satisfied. It is an error if no FEATURE is satisfied. Features are symbols such as `srfi-1', and a feature specification can use `and', `or' and `not' forms to test combinations. The last clause can be an `else', to be used if no other passes. For example, define a private version of `alist-cons' if SRFI-1 is not available. (cond-expand (srfi-1 ) (else (define (alist-cons key val alist) (cons (cons key val) alist)))) Or demand a certain set of SRFIs (list operations, string ports, `receive' and string operations), failing if they're not available. (cond-expand ((and srfi-1 srfi-6 srfi-8 srfi-13) )) The Guile core defines features `guile', `r5rs', `srfi-0' and `srfi-6' initially. Other SRFI feature symbols are defined once their code has been loaded with `use-modules', since only then are their bindings available. The `--use-srfi' command line option (*note Invoking Guile::) is a good way to load SRFIs to satisfy `cond-expand' when running a portable program. Testing the `guile' feature allows a program to adapt itself to the Guile module system, but still run on other Scheme systems. For example the following demands SRFI-8 (`receive'), but also knows how to load it with the Guile mechanism. (cond-expand (srfi-8 ) (guile (use-modules (srfi srfi-8)))) It should be noted that `cond-expand' is separate from the `*features*' mechanism (*note Feature Tracking::). Feature symbols in one mechanism are unrelated to those in the other. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel