[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

logical operations in if-implements

This page is part of the web mail archives of SRFI 0 from before July 7th, 2015. The new archives for SRFI 0 contain all messages, not just those from before July 7th, 2015.



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     bothner@xxxxxxxxxx     http://www.cygnus.com/~bothner