[plt-scheme] Example from "The Scheme Programming Language" fails
On Friday 27 June 2003 08:42 pm, Anton van Straaten wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> > The last example in chapter 8 of "TSPL" is a define-structure
> > macro that has an effect similar to define-struct. I was going
> > to use that example as a template and have it's backend be
> > make-struct-type.
> >
> > If I copy and paste the example into DrScheme with the MzScheme
> > language, and evaluate:
> >
> > (define-structure foo a b c)
> >
> > I get an error. (I won't include the error here since it really
> > only makes sense when when shown the the DrScheme REPL).
> >
> > Any ideas on how to modify that example so that it works? Or,
> > should it work as given?
>
> Reacting purely to the nature of the error message, I tried wrapping the
> four occurences of 'syntax' that are used in a list context, with a call to
> syntax->list. This seems to fix the example. Don't assume that this is a
> perfectly correct answer, though - I haven't tried to understand the
> example, and I don't know much about the syntax functions.
>
> The changed chunk of code is all contained in the following six contiguous
> lines:
>
> (syntax->list (syntax (field ...)))))
> ((assign ...)
> (map (lambda (x) (gen-id x "set-" (syntax name) "-" x "!"))
> (syntax->list (syntax (field ...)))))
> (structure-length (+ (length (syntax->list (syntax (field ...)))) 1))
> ((index ...) (let f ((i 1) (ids (syntax->list (syntax (field ...)))))
>
> > (I won't include the error here since it really only
> > makes sense when when shown the the DrScheme REPL).
>
> Don't let DrScheme's cool graphical wizardry throw you off: the plain text
> of the error was enough to diagnose the problem - it read: "map: expects
> type <list> as 2nd argument, given: #<syntax:21:17>". The highlighted code
> showed a call to map in which the 2nd argument - which should be a list -
> was actually a call to 'syntax', which (apparently) does not result in a
> list. That's all I based the above fix on.
>
> Anton
Thanks for looking at this Anton.
So I guess the question I have now is...
Is the "(syntax (field ...))" code supposed to "expand" into a list?
Shouldn't this example work straight out of the book though? Chapter 8 has no
reference to 'syntax->list'.
Ed