[plt-scheme] create complex object @ compile time but made available @ run time?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Jun 13 10:42:26 EDT 2007

Ryan Culpepper wrote:

> The code you gave uses 'print-convert' (lib "pconvert.ss") to generate
> the syntax that would recreate the structure at run-time. It will
> usually work for simple structures. But here are some problems that you
> may encounter if you use that method for interesting values:
> 
> First, 'print-convert' produces uncompilable code (containing '...')
> when it can't convert a value. This happens for procedures, structs it
> cannot inspect, etc.
> 
> Second, 'print-convert' leaves syntax objects unconverted and unquoted.
> When you use 'datum->syntax-object' on an S-expression that contains
> embedded syntax objects, it doesn't quote them with an "extra layer" of
> syntaxness; it stops and leaves them intact. Here's what happens to the
> following value on the 'print-convert' trip:
> 
>     (list #'(+ 1 2)) ;; a list containing a single syntax object
>       --print-convert-->
>     `(,#'(+ 1 2))
>       --datum->syntax-object-->
>     #'`(,(+ 1 2))
>       --eval-->
>     (list 3)
> 
> These effects can be truly baffling, especially if evaluating the
> "expression" causes an error.

Nice examples.

> The only truly safe way I know of transferring values across phases is
> to write your own 'X->X-syntax' serializer.

Would it be possible to use print-convert as a starting point,
and write a "syntax-convert"? Where one assumes that structure
names bound in the syntax environment match names bound in the
runtime environment?

-- 
Jens Axel Søgaard






Posted on the users mailing list.