[plt-scheme] Running into syntax->datum error trying to build r6rs code

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun May 4 09:06:02 EDT 2008

At Sun, 4 May 2008 06:56:24 -0400, Ryan Newton wrote:
> Either using mzscheme directly, or plt-r6rs, I can build a leaf module  
> with no dependencies (compat.mzscheme.sls).
> 
> However, when I try to build a module that depends on that leaf node,  
> I then run into a syntax->datum error like the following:
> 
> [Compiling /afs/csail.mit.edu/u/n/newton/WaveScope/code/wavescript/src/ 
> ws/globals.sls]
>   [Compiling /home/newton/wavescript/src/ws/compat/compat.mzscheme.sls]
> syntax->datum: expects argument of type <syntax>; given {#<syntax:/afs/ 
> csail.mit.edu/u/n/newton/WaveScope/code/wavescript/src/ws/globals.sls: 
> 904:24> #<syntax:/afs/csail.mit.edu/u/n/newton/WaveScope/code/ 
> wavescript/src/ws/globals.sls:904:28> #<syntax:/afs/csail.mit.edu/u/n/ 
> newton/WaveScope/code/wavescript/src...
> 
> Any ideas?

On closer inspection, I see that `syntax->datum' didn't behave like
it's supposed to. Now fixed in SVN.


> As a side note, this model of installing everything in a collections  
> directory took a little getting used to.  Perhaps plt-r6rs should  
> simply take a -path argument for the root of the r6rs application  
> (like larceny).  The semantics might be the same as adding the path to  
> PLTCOLLECTS.

That sounds reasonable, so I've added `++path'.


> In any case, if I do let PLT use a separate collects directory (rather  
> than adding my current directory to PLTCOLLECTS) then I run into  
> trouble with "include".  I've used the include macro to break out  
> shared pieces from "compat.sls" (which differs across  
> implementations).  It seems that PLT's include demands a relative path  
> and won't accept an absolute one(?!).

If you use `(include <str>)', then <str> does indeed have to be a
portable, URL-style relative path, but `(include (file <str>))' lets
you provide an absolute-path <str> using the current platform's
conventions.

   http://docs.plt-scheme.org/reference/include.html


> Further, this relative path is  
> taken relative to the *collects* directory.

It should be relative to the enclosing file. I guess the problem is
that `plt-r6rs --install' doesn't see the `include', so it doesn't copy
over the included file.

I'm not sure how to fix that, other than to add a flag to `plt-r6rs
--install' to supply extra files.

You could also put the shared code in a library instead of using `include'.
That is, instead of

    ;; shared.ss:
    (define shared 7)

    ;; compat.mzscheme.sls:
    ....
    (include "shared.ss")

use

    ;; shared.ss:
    (library (... shared)
      (export include-shared)
      (import ....)
      (define-syntax (include-shared)
        (lambda (stx)
          (datum->syntax stx
                         '(define shared 7)))))


    ;; compat.mzscheme.sls:
    ....
    (import .... (.... shared) ....)
    ....
    (include-shared)

This approach is more verbose to get started, but it's less dependent
on implementation-specific details for files and paths.


Matthew



Posted on the users mailing list.