unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* doc srfi-0 cond-expand
@ 2004-07-18 23:12 Kevin Ryde
  2004-08-15 22:06 ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Ryde @ 2004-07-18 23:12 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc srfi-0 cond-expand
  2004-07-18 23:12 doc srfi-0 cond-expand Kevin Ryde
@ 2004-08-15 22:06 ` Marius Vollmer
  2004-08-17 23:54   ` Kevin Ryde
  0 siblings, 1 reply; 4+ messages in thread
From: Marius Vollmer @ 2004-08-15 22:06 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> Some new words below for cond-expand,

Nice.  We might also want to add some more words on how cond-expand is
implemented, including docs for cond-expand-provide.

Very briefly: cond-expand-provide adds a feature symbol to a given
module and cond-expand looks at each 'used' module whether one of them
has the requested feature.

Thus, cond-expand can behave differently in different modules and the
list of provided SRFIs is not a global property.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc srfi-0 cond-expand
  2004-08-15 22:06 ` Marius Vollmer
@ 2004-08-17 23:54   ` Kevin Ryde
  2004-08-18 10:15     ` Marius Vollmer
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Ryde @ 2004-08-17 23:54 UTC (permalink / raw)
  Cc: guile-devel

Marius Vollmer <mvo@zagadka.de> writes:
>
> Very briefly: cond-expand-provide adds a feature symbol to a given
> module ...

Documenting that would depend on documenting "module" objects though
wouldn't it?


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: doc srfi-0 cond-expand
  2004-08-17 23:54   ` Kevin Ryde
@ 2004-08-18 10:15     ` Marius Vollmer
  0 siblings, 0 replies; 4+ messages in thread
From: Marius Vollmer @ 2004-08-18 10:15 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <mvo@zagadka.de> writes:
>>
>> Very briefly: cond-expand-provide adds a feature symbol to a given
>> module ...
>
> Documenting that would depend on documenting "module" objects though
> wouldn't it?

Hmm, would it?  Wouldn't it suffice to say that the usual thing to use
for the module is (current-module) and leave it at that?


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-18 10:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-18 23:12 doc srfi-0 cond-expand Kevin Ryde
2004-08-15 22:06 ` Marius Vollmer
2004-08-17 23:54   ` Kevin Ryde
2004-08-18 10:15     ` Marius Vollmer

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).