chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] syntax-case macros as extensions?


From: Raffael Cavallaro
Subject: [Chicken-users] syntax-case macros as extensions?
Date: Thu, 8 Mar 2007 17:30:29 -0500


On Mar 8, 2007, at 5:28 AM, felix winkelmann wrote:

 Then you have to
make those macros available at _compile-time_, or the
compiler will not see them. "(require ...)" loads code at run-time,
not at compile-time. Try "require-for-syntax".

A somewhat related question: I have some macros that are defined with define-syntax using the syntax-case extension. I can't seem to make these macros into an extension that is usable at runtime in csi. I can load the .scm file just fine, and then the macros work in csi, but If I try to compile these into an extension, when I load it I get unbound variable errors.

Here's a simple example:

----------- dotimes.scm ---------

(require-for-syntax 'syntax-case)

(define-syntax dotimes
  (syntax-rules ()
    ((dotimes (var limit) e ...)
     (let loop ((var 0))
       (if (< var limit) (begin e ... (loop (+ 1 var))))))))


---------- end dotimes.scm ----------------

;;; I suspect that I'm not quite doing the right thing in this setup file


---------- dotimes.setup ---------------

(compile -s dotimes.scm)
(install-extension 'dotimes "dotimes.so"
                    '((syntax) (require-at-runtime syntax-case)))

--------- end dotimes.setup -----------


;; when simply loaded, dotimes.scm works as expected:

      /    /      /
___ (___    ___ (     ___  ___
|    |   )| |    |___)|___)|   )
|__  |  / | |__  | \  |__  |  /

Version 2.6 - macosx-unix-gnu-x86 - [ libffi dload ptables applyhook ]
(c)2000-2007 Felix L. Winkelmann
#;1> (load "/scheme/dotimes.scm")
; loading /scheme/dotimes.scm ...
; loading /usr/local/lib/chicken/1/syntax-case.so ...
; loading /usr/local/lib/chicken/1/syntax-case-chicken-macros.scm ...
#;2> (dotimes (n 10) (display n))
0123456789


;; when required-for-syntax or used as an extension, it throws an unbound variable error:

      /    /      /
___ (___    ___ (     ___  ___
|    |   )| |    |___)|___)|   )
|__  |  / | |__  | \  |__  |  /

Version 2.6 - macosx-unix-gnu-x86 - [ libffi dload ptables applyhook ]
(c)2000-2007 Felix L. Winkelmann
#;1> (require-for-syntax 'dotimes)
; loading /usr/local/lib/chicken/1/dotimes.so ...
; loading /usr/local/lib/chicken/1/syntax-case.so ...
; loading /usr/local/lib/chicken/1/syntax-case-chicken-macros.scm ...
#;2> (dotimes (n 10) (display n))
Error: unbound variable: n

        Call history:

        <syntax>          (dotimes (n (quote 10)) (display n))
        <syntax>          (n (quote 10))
        <syntax>          (quote 10)
        <syntax>          (display n)
        <eval>            (dotimes (n (quote 10)) (display n))
        <eval>            (n (quote 10))  <--

;; same with require-extension instead of require-for-syntax:

      /    /      /
___ (___    ___ (     ___  ___
|    |   )| |    |___)|___)|   )
|__  |  / | |__  | \  |__  |  /

Version 2.6 - macosx-unix-gnu-x86 - [ libffi dload ptables applyhook ]
(c)2000-2007 Felix L. Winkelmann
#;1> (require-extension dotimes)
; loading /usr/local/lib/chicken/1/dotimes.so ...
; loading /usr/local/lib/chicken/1/syntax-case.so ...
; loading /usr/local/lib/chicken/1/syntax-case-chicken-macros.scm ...
#;2> (dotimes (n 10) (display n))
Error: unbound variable: n

        Call history:

        <syntax>          (dotimes (n (quote 10)) (display n))
        <syntax>          (n (quote 10))
        <syntax>          (quote 10)
        <syntax>          (display n)
        <eval>            (dotimes (n (quote 10)) (display n))
        <eval>            (n (quote 10))  <--


Any idea what I'm doing wrong in the setup?

regards,

Ralph


Raffael Cavallaro, Ph.D.
address@hidden





reply via email to

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