Marlene Miller skrev:
> Is it an error because they decided we shouldn't refer to a datatype before Because they (Flatt?) decided it should be that way.
> it is declared, or is it an error because the datatype name is not a
> top-level variable (which can be referred to before it is defined)?
> The error is good, because I didn't realize the dependencies of the two Agree.
> macros in separate files.
> But all macros have to be defined at the top. I I am not sure what you are thinking of here.
> haven't figured out how to package things in Scheme.
Are you talking about your own macros or the macros
definining define-datatype ?
If the latter, you can use define-datatype in a non-EOPL
langauge like this:
(require (lib "datatype.ss" "eopl"))
> ; - - - - - - - - - -
Yes, that's the way the book authors defined it. [They needed R5RS
> PLT Scheme, Language Standard (R5RS)
> (define-syntax define-datatype
> (syntax-rules ()
> ;((direct-target indirect-target) (direct-target v) (indirect-target v))
> It looks like the identifier target is a top-level variable.
compability, so they stricter requirements than Flatt].
> ;- - - - - - - - - -
> PLT Scheme, Language: EOPL
> (define-datatype target target?
> (direct-target (v number?))
> (indirect-target (v target?)))
> ;target: illegal use of syntax in: target
> The identifier target is not a top-level variable? It is something else?
(syntax-case stx ()
[(_ name pred-name
(variant-name (field-name field-pred) ...)
<a lot deleted>
(let ([cert (syntax-local-certifier)])
(make-dt (cert (syntax pred-name))
(make-vt (cert (syntax variant-name))
(cert (syntax variant?))
(cert (syntax variant-accessor))
This means that name (i.e. target in the example) is bound in the
transfomer environment (that is, as syntax). It isn't bound to
a macro transformer, but to a value, a dt-structure, that represents
the datatype to be defined.
This value is used by the cases macro. As an example, it starts
(let ([dt (and (identifier? (syntax datatype))
(syntax-local-value (syntax datatype)
(lambda () #f)))])
(unless (dt? dt)
"not a datatype name"
which checks that the datatype has been defined previously.
Later we see check the check that a variant mentioned in
the use of cases actually is a variant of the datatype.
(let* ([variant (syntax variant)]
(ormap (lambda (dtv)
(let ([vt-name (vt-name-stx dtv)])
(and (module-identifier=? variant vt-name)
[orig-variant (and vt (vt-name-stx vt))])
(format "not a variant of `~a'"
(syntax-object->datum (syntax datatype)))
The source is at:
Jens Axel Sgaard