[Top][All Lists]

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

[Chicken-users] Re: Problems with run-time evals involving srfi-17..

From: felix
Subject: [Chicken-users] Re: Problems with run-time evals involving srfi-17..
Date: Sun, 23 May 2004 00:45:21 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Daniel B. Faken wrote:

  (this is with chicken 1.51)

A lot of my code uses run-time evals (I'm passing code around a network) and srfi-17 (generalized set!). The right combination of features to use in chicken has always been a little obscure to me, but I've bumbled along by requiring almost everything almost everywhere.. but now, I can't get this simple code to run:

Well, using macros at runtime is rather unintuitive, I admit.

(declare (uses extras srfi-1 srfi-4
               eval syntax-case) (run-time-macros))
(require-extension chicken-more-macros)

;(install-highlevel-macro-system 'r5rs 'srfi-0 'extensions)
(require-extension srfi-17)

(define node-var-table (make-hash-table))
(define node-var
   [lambda (name) (hash-table-ref node-var-table name)]
   [lambda (name val) (hash-table-set! node-var-table name val)]) )

(set! (node-var 'tracker-node?) #t)
(set! (node-var 'gui-tracker-node?) #t)
(set! (node-var 'vrpn-node?) #t)

(eval `(set! (node-var 'vmd-node?) #t))

  ... at least, when compiled: I get (also with various modifications)
Error: invalid syntax: (set! (node-var (quote vmd-node?)) #t)

(even if I use -H2 and/or -run-time-macros for csc (which shouldn't
be necessary anyway))

The proper way to do it is like this:

(require-extension srfi-17)

(register-feature! 'srfi-17)

(define x (list 1 2 3))
(eval '(set! (cadr x) 99))
(print x)

If you want to use the hygienic macro system at runtime, I recommend
using the `-hygienic-at-run-time' option, unless the non-standard macros
are needed. Should that be the case, the best way is:

(require-extension syntax-case)
(install-highlevel-macro-system 'extensions)

The `register-feature!' above is all that's needed to tell the macro-expander
at runtime that non-identifiers should be allowed, the runtime-support code is 
already loaded.
(the `register-feature!' is in fact unnecessary and should be done by 
I have changed the srfi-17 egg accordingly)

The run-time-macros declaration only works for lowlevel macros.

Another point: your invocation of `install-highlevel-macro-system' is slightly
incorrect: you should pass _either_ 'r5rs or 'extensions, the two options are 
exclusive (I have added a clarification to the manual, since this wasn't that 
from the documentation).

 It works in csi unless I uncomment that
(install-highlevel-macro-system..), which causes this mysterious error:
; loading /home/dfaken/.csirc ...
; loading /home/dfaken/lib/chicken/ ...
; loading htcam/tst.scm ...
; loading /home/dfaken/lib/chicken/share/chicken/chicken-more-macros.scm ...
Error: unbound variable: srfi-17

Passing 'r5rs to `install-highlevel-macro-system' assumes you only want
R5RS (and it ignores the 'extensions), so `require-extension' is not recognized.

  Is (require-extension ..) valid during eval-time?  I've used (require..)
in the past with no problems.

I recommend not to use require-extension at run-time.

Are there any other gotcha's for using macros at run-time vs. compile-time? (I think I've seen all the sections in the manual)

Yes, there are several, but I think you already got caught by most of them. ;-)
The basic problem is that Chicken uses two different, mostly incompatible
macro systems.

  Does anyone else do a lot of run-time macro-needing evals? :)

Normally I use the low-level macro system, exclisively and do the equivalent of

(declare (run-time-macros))
(include "chicken-more-macros")
(include "chicken-match-macros")  ; if needed

This includes all macro definitions in the compiled code and also will define
them at run-time for being used with eval.


reply via email to

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