chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Re: first experiments with "simple-macros"


From: felix winkelmann
Subject: [Chicken-users] Re: first experiments with "simple-macros"
Date: Wed, 3 Aug 2005 08:47:16 +0200

On 8/2/05, Michele Simionato <address@hidden> wrote:
> 
> 1. First of all, Andre's paper and other documentation should be 
>    boundled with the egg. Also, I would like this policy to be valid for 
>    all eggs. 

Good point. I will try to think of something.

> 
> 2. Various constructs which work in regular Chicken does not work once 
>    the simple-macros egg is loaded; for instance define-values:
> 
> #;1> (use simple-macros)
> ; loading /usr/local/lib//simple-macros.so ...
> #;2> (define-values (x y) (values 1 2))
> Error: unbound variable: y#top
> 
> Notice that the error message is pretty confusing (it seems that 
> simple-macros is renaming *all* names, not only the names inside
> macros defined with define-syntax). Should I assume that
> only R5RS forms are recognized? It seems likely, Chicken extensions 
> such as '->string' are not recognized either, however 'print', which is not

The toplevel has by default the "scheme" and "chicken" modules
imported. The "chicken" module exports everything that is provided
by the "library" and "eval" library units. To use stuff from "extras", say:

(use (module extras))
(import extras)

[Note the separation of loading/linking and import]

> 
> 3. ,x does not work in the REPL; however macroexpand "somewhat" works,
> so it should  be easy to fix.

Hm. ",x" Works for me. What output do you get?

> 
> 4. I was playing with the module system. As an exercise, I wanted to define
> a
>    macro to import identifiers prefixed by the module name. So I tried
>   
>   (define (symbol-append . symbols)
>     (string->symbol (apply string-append (map symbol->string symbols))))
> 
>   (define-syntax (import-with-prefix module-name)
>     #`(import ,module-name (lambda (sym) (symbol-append ',module-name ':
> sym))))
> 
>   (module m1 (a b)
>     (define a 1)
>     (define b 2))
> 
>   (import-with-prefix m1)
> 
> But is does not work. m1:a and m1:b are not imported
> 

I asked Andre and he sent me this:

===================================
 Sorry, this should be better documented.  The way you have written it,
 the symbols will be imported into the macro definition site.  We need to
 write the macro as if IMPORT appeared at the use site of IMPORT-WITH-SYNTAX,
 as follows:

  (module helper (import-with-prefix)

    (define (symbol-append . symbols)
      (string->symbol (apply string-append (map symbol->string symbols))))


    (define-syntax import-with-prefix
      (lambda (form)
        (let ((import-use-site (datum->syntax (car form) 'import))
              (module-name (cadr form)))
          #`(,import-use-site ,module-name
                              (lambda (sym) (symbol-append ',module-name
                                                           ':
                                                           sym))))))
    ) ; module

  ======================================

> 
>   (macroexpand '(import-with-prefix m1))
> 
> gives 
>   
>   (kffd:load-module (quote m1))
> 
> which is anyway incorrect, since nor a nor b are imported. 

That's ok. The import has already been performed at macroexpansion-
time.

> 
> 5. Further observations will likely follow later on. 
> 

Keep in mind that this is really quite experimental (it isn't officially
announced yet). We are working on the bleeding edge here... ;-)


cheers,
felix




reply via email to

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