[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] misc questions about macros
From: |
Hugo Arregui |
Subject: |
[Chicken-users] misc questions about macros |
Date: |
Mon, 4 Mar 2013 11:43:59 -0300 |
Hi guys,
I'm pretty new to macros, so I want to ask a couple of questions to
sort the things in my brain :-).
1) I think this is an issue regarding expansion time / runtime:
(define (aproc a)
(* 2 a))
(define-syntax amacro
(er-macro-transformer
(lambda (x r c)
(aproc 1))))
(print (amacro))
works great via csi, but when I try to compile it:
Error: during expansion of (amacro ...) - unbound variable: aproc
Call history:
<syntax> (##core#begin (print (amacro)))
<syntax> (print (amacro))
<syntax> (amacro)
<eval> (aproc 1) <--
Clarification: This is a simplification, I know I can do this:
(define-syntax amacro
(er-macro-transformer
(lambda (x r c)
'(aproc 1)))) ; I should rename this
But I'm trying to understand whats happening in the first example.
My questions are:
- I'm guessing the proc isn't available in expansion time. I'm right?
- How can make this work?
2) I have a macro called "jlambda-field", its signature is:
(jlambda-field (modifiers) type class field-name)
Now, if modifiers contains "static" keyword I want to delegate the
call to static-field macro, otherwise, delegate to field macro. As
static could be in any position in the list, I need to express a "list
contains" pattern. I express that in this way:
(define-syntax jlambda-field
(syntax-rules (static)
((_ (static) type class field-name)
(static-field () type class field-name))
((_ (static modifier ...) type class field-name)
(static-field (modifier ...) type class field-name))
((_ (modifier ... static) type class field-name)
(static-field (modifier ...) type class field-name))
((_ modifiers type class field-name)
(field modifiers type class field-name))))
This works perfect, but I want to ask, there is a simplified way to do this?
Thanks,
Hugo
- [Chicken-users] misc questions about macros,
Hugo Arregui <=