| From: MichaelL_at_frogware.com
| Date: Fri, 10 Nov 2006 00:27:50 -0500
|
| (I was interested in feedback on the following before submitting a formal
| comment.)
|
| Would it make sense for "case" to be defined in terms of backquote rather
| than quote? The problem is that the use of quote makes references to
| constants impossible. For example, this doesn't work:
|
| (define some-const 'xxx)
|
| (case some-val
| [(some-const)
| ...])
|
| If "case" were defined in terms of backquote, though, this would be
| possible:
|
| (define some-const 'xxx)
|
| (case some-val
| [(,some-const)
| ...])
In SCM (
http://swiss.csail.mit.edu/~jaffer/SCM), the QASE syntax
provides this and unquote-splicing as well.
QASE enables SIMSYNCH (
http://swiss.csail.mit.edu/~jaffer/SIMSYNCH)
logic designs to refer to symbolic names rather than numerical
constants, while providing control over those numerical assignments
(unlike some implementations of enumerations).
I suspect that QASE can't be defined using just R5RS-macros (SCM does
DEFMACRO). Is it possible using R6RS macros?
-- Special Form: qase key clause1 clause2 ...
`qase' is an extension of standard Scheme `case': Each CLAUSE of a
`qase' statement must have as first element a list containing
elements which are:
* literal datums, or
* a comma followed by the name of a symbolic constant, or
* a comma followed by an at-sign (_at_) followed by the name of a
symbolic constant whose value is a list.
A `qase' statement is equivalent to a `case' statement in which
these symbolic constants preceded by commas have been replaced by
the values of the constants, and all symbolic constants preceded by
comma-at-signs have been replaced by the elements of the list
values of the constants. This use of comma, (or, equivalently,
`unquote') is similar to that of `quasiquote' except that the
unquoted expressions must be "symbolic constants".
Symbolic constants are defined using `defconst', their values are
substituted in the head of each `qase' clause during macro
expansion. `defconst' constants should be defined before use.
`qase' can be substituted for any correct use of `case'.
(defconst unit '1)
(defconst semivowels '(w y))
(qase (* 2 3)
((2 3 5 7) 'prime)
((,unit 4 6 8 9) 'composite)) ==> composite
(qase (car '(c d))
((a) 'a)
((b) 'b)) ==> _unspecified_
(qase (car '(c d))
((a e i o u) 'vowel)
((,_at_semivowels) 'semivowel)
(else 'consonant)) ==> consonant
Received on Fri Nov 10 2006 - 10:50:36 UTC