logical operations in if-implements Per Bothner (16 Jan 1999 06:02 UTC)
Re: logical operations in if-implements Marc Feeley (24 Mar 1999 04:54 UTC)
SRFI 0 philosophy [WAS: logical operations in if-implements] sperber@xxxxxx (24 Mar 1999 08:33 UTC)

logical operations in if-implements Per Bothner 16 Jan 1999 06:02 UTC

The if-implements macro provides some of same functionality
of the C pre-processor.  I.e.:

	(if-implements  FEATURE-ID DEFINITION)

corresponds to:

	#ifdef FEATURE_ID
	DEFINITION
	#endif

However, cpp allows a much more general expression language.
Most of the time, one does not need it, but it is occasionally useful.
It is easy to generalize if-implements to conditionals:

	(if-implements (and FEATURE1 FEATURE2) DEFS1 DEFS2)
is equivalent to:
	(if-implements FEATURE1 (if-implements FEATURE2 DEFS1 DEFS2) DEFS2)

and
        (if-implements (or FEATURE1 FEATURE2) DEFS1 DEFS2)
is equivalent to:
	(if-implements FEATURE1 DEFS1 (if-implements FEATURE2 DEFS1 DEFS2))

and
	(if-implememnts (not FEATURE) DEFS1 DEFS2)
is equivalent to:
	(if-implements FEATURE DEFS2 DEFS1)

In other words:  Though and, or and not do not provide more power,
they may provie some convenience.

That leads to a more general idea of a compile-time expression
evaluation using names from a special compile-time name-space
- which of course is what cpp offers.

For example, if version 2.00 of implementation foo is known to have a bug
for which we know a work-around, we can do:
	(if-implements (and foo (= foo-version 200)) work-around)

Thus a proposal for a more general concept:

(if-defined <compile-time-expression> <form-1> <form-2>)

This evaluates <compile-time-expression> at macro-substitution time,
in an implementation-defined namespace that includes all the
names of R5RS.  (However, only constants and side-effect free
functions are allowed.)  Any names in <compile-time-expression>
that are not defined in the implementation namespace are assumed
to be #f.  (It follows that it is an error to use an undefined
name in function position or an arithmetic operation.)

This subsumes if-implemented, as well as the expression evaluation
features of cpp.  I do not propose a way for the user #define new names,
though an implemenation might allow names to be specified on the
command line, or when loading a new module.

	--Per Bothner
Cygnus Solutions     xxxxxx@cygnus.com     http://www.cygnus.com/~bothner