chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] struggling with macros


From: Peter Bex
Subject: Re: [Chicken-users] struggling with macros
Date: Sun, 11 Nov 2012 14:38:16 +0100
User-agent: Mutt/1.4.2.3i

On Sun, Nov 11, 2012 at 02:24:17PM +0100, Răzvan Rotaru wrote:
> On 11 November 2012 13:30, Peter Bex <address@hidden> wrote:
> Yes, behaviour is correct, but implementation is not complete, hence the
> next version of js-macro.
> 
> > You're trying to use MAP on a macro.  That's not possible because
> > macros are not first-class (this is true in Common Lisp as well).
> >
> 
> Well, essentially what I have here is a macro calling itself. How can I do
> that?

Generally, you can't.  There are a few things you can do instead:
- Expand to a new call to (js ...) for each of the elements.
- Loop manually over the cdr inside the macro (maybe using map and
   an anonymous lambda).
- Move the real conversion work into a procedure.  This can be used
   by the macro, and the procedure can call itself.  This is a bit
   tricky because you'll need to define the procedure in a
   begin-for-syntax block or put it in a separate module and 
   require-for-syntax it.

> I am trying to build a javascript DSL, similar to parenscript. The code
> above is very simple and should behave like this:
> 
> (js 123) => "123"
> (js "123") => "\"123\""
> (js (1 2 3)) => "1(2, 3)"

> The first two are primitives, the last is a function call. For simplicity,
> I ignored the comma that separates parameters in the function call. So the
> output I'm expecting from my code is actually:
> 
> (js (1 2 3)) => "1(23)"

I think that should be pretty easy.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

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