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

[Scheme-reports] R7RS syntax object questions



In studying the draft report and the various implementations, I have formed
several questions on which I would like the opinion of an expert.
If this is the wrong place to ask such questions please suggest a more
appropriate forum.

In the R7RS standard, are macros (i.e syntax objects) considered to be
first-class objects?
[First-class object being an entity that can be constructed at run-time,
passed as a parameter, returned from a subroutine, or assigned to a variable.]

For example would these examples be considered to be standard compliant R7RS
Scheme? The implementations to which I have access do not all behave
in the same way.

Storing a syntax object in a variable?

(define myand and)

Calling my stored object as I can the original?

(myand #t (+ 1 2 3))

Returning a syntax object from a procedure?

(define (return-op) and)
(define myop (return-op))
(myop #t (+ 1 2 3))

May I call a syntax in the same way I call a primitive procedure?

(and #t (+ 1 2 3))
((return-op) #t (+ 1 2 3))
((and and) #t (+ 1 2 3))

I have read the R7RS draft and I am having difficulty answering these questions.
I find that there are "Primitive Expressions" and "Derived Expressions" and
that derived expressions "can instead be defined as macros" but this does not
seem to be a requirement. The description of a procedure call although in
the Primitive Expression section does not appear to exclude syntax objects.

"A procedure call is written by enclosing in parentheses an expression
for the procedure to be called followed by espressions for the arguments
to be passed to it."

An expression that returns a syntax would appear to be allowed.

(define ops `(,* ,and))
((car ops) 2 3)
((cadr ops) #t #f)

What about (and and) which is an expression that returns a syntax.

((and and) #t (+ 1 2 3))

The WG1 charter asserts that "Self consistency is an important objective,"
and yet the boolean operators and arithmetic operators do not behave
consistently. In particular as a user of the language it is not obvious
which functions have been implemented as primitives and which as a syntax.

It appears to be valid to implement the "and" function as a primitive or
as a macro and curiously the boolean "not" function is listed with the
Standard Procedures making it inconsistent with the other boolean operators.

There is another situation in which the difference between primitive
procedures and syntax objects makes itself a nuisance and that is in
short-cicuit evaluation of the boolean operators. In the following
expression one might think that the "never" object was not evaluated:

(and #f never)

and yet if the "never" object is a syntax it would seem that it is evaluated.

(and #f and)

If these topics have been discussed previously I apologize and please
refer me to the earlier discussion,

Stephen Lewis


_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports