Re: define-datatype and scope



Marlene Miller skrev:

Is it an error because they decided we shouldn't refer to a datatype before
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)?

Because they (Flatt?) decided it should be that way.

The error is good, because I didn't realize the dependencies of the two
macros in separate files.

Agree.


But all macros have to be defined at the top. I
haven't figured out how to package things in Scheme.

I am not sure what you are thinking of here.
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"))

> ; - - - - - - - - - -
PLT Scheme, Language Standard (R5RS)

(define-syntax define-datatype
(syntax-rules ()


target
;((direct-target indirect-target) (direct-target v) (indirect-target v))

It looks like the identifier target is a top-level variable.

Yes, that's the way the book authors defined it. [They needed R5RS
compability, so they stricter requirements than Flatt].


;- - - - - - - - - -
PLT Scheme, Language: EOPL

(define-datatype target target?
(direct-target (v number?))
(indirect-target (v target?)))

target
;target: illegal use of syntax in: target

The identifier target is not a top-level variable? It is something else?

Yes.

(define-syntax define-datatype
(lambda (stx)
(syntax-case stx ()
[(_ name pred-name
(variant-name (field-name field-pred) ...)
...)
<a lot deleted>
(define-syntax name
(let ([cert (syntax-local-certifier)])
(make-dt (cert (syntax pred-name))
(list
(make-vt (cert (syntax variant-name))
(cert (syntax variant?))
(cert (syntax variant-accessor))
variant-field-count)
...))))
<more deleted>

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
with

(let ([dt (and (identifier? (syntax datatype))
(syntax-local-value (syntax datatype)
(lambda () #f)))])
(unless (dt? dt)
(raise-syntax-error
'cases
"not a datatype name"
stx
(syntax datatype)))

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)]
[vt
(ormap (lambda (dtv)
(let ([vt-name (vt-name-stx dtv)])
(and (module-identifier=? variant vt-name)
dtv)))
(dt-variants dt))]
[orig-variant (and vt (vt-name-stx vt))])
(unless orig-variant
(raise-syntax-error #f
(format "not a variant of `~a'"
(syntax-object->datum (syntax datatype)))
stx variant))


The source is at:

<http://ja.soegaard.net/planet/html/collects/eopl/datatype.ss>

--
Jens Axel Søgaard
.



Relevant Pages

  • Re: Calculations
    ... Check out the DateDiff function in the Visual Basic Help File ... Returns a Variant specifying the number of time intervals between two ... The DateDiff function syntax has these named arguments: ...
    (microsoft.public.word.newusers)
  • Re: DLookUp function comes up with only the first entry
    ... I would like the combo box in the sub-requirements ... Your syntax is incorrect. ... not the value IN the form control. ... The actual syntax will depend upon the datatype of the ...
    (microsoft.public.access.forms)
  • Re: Getting at variant containing safe array from COM object?
    ... >I ended up solving it myself but with a somewhat different syntax. ... >>>I have a COM object which has a method which returns a variant which ... >>> object GetNextEvent() ... >>> Grant Schenck ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DLookUp function comes up with only the first entry
    ... section on the form for Requirements, I have a section for sub-requirements. ... Your syntax is incorrect. ... not the value IN the form control. ... The actual syntax will depend upon the datatype of the ...
    (microsoft.public.access.forms)
  • Re: Disadvantages to using variant datatype?
    ... Public Function fncTotalByOther(av_CodeGroup As Variant, ... conversion on everything you do, and that is a ... Variants are also the most expensive datatype there is when it comes to ... Dealing with Nulls is sometimes daunting, ...
    (microsoft.public.access.formscoding)