[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] tinkering with the reader

From: felix winkelmann
Subject: Re: [Chicken-users] tinkering with the reader
Date: Wed, 15 Dec 2004 09:43:41 +0100

On Wed, 15 Dec 2004 09:17:45 +0100, Michele Simionato
<address@hidden> wrote:
> I was looking at the example for set-reader-syntax! in the manual:
> Apart from the fact that hex(e0) == 224, and not 240, it works ;-)


> However I did some experiment like this:
> (print '(1 2 %e0e0e0 3))
> If I run this from the interpreter the reader works, but if I compile
> the script it does
> not:
> Any hint on why it is so and how to fix that?

It's compile-time vs. run-time issue all over again.

The reader is extended at run-time, in your example. But the
compiler (which reads your code at compile-time, i.e. before
it runs) doesn't know about the new syntax. So we must
somehow inform the compiler about the new syntax. 
`eval-when' won't work in this case, since the source is read in
completely before compilation (and perhaps embedded
expressions to be evaluated). So we must "extend" the compiler:

$ cat pcreader.scm
  (set-read-syntax! #\%
           (lambda (port)
             (apply vector
               (map (cut string->number <> 16)
                    (string-chop (read-string 6 port) 2) ) ) ) )
$ cat example.scm
(print '%f0f0f0)
$ csc example.scm -extend pcreader.scm

(compiler extensions are loaded before the main code is read
in and may optionally be compiled (as .so's)).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]