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: Răzvan Rotaru
Subject: Re: [Chicken-users] struggling with macros
Date: Sun, 11 Nov 2012 14:24:17 +0100




On 11 November 2012 13:30, Peter Bex <address@hidden> wrote:
On Sun, Nov 11, 2012 at 01:23:13PM +0100, Răzvan Rotaru wrote:
> Hi,

Hi!

> I'm trying to write a simple _javascript_ DSL, and got stuck in the macros
> :). (I'm coming from lisp macros)  Take for example this one:
>
> (define-syntax js
>   (ir-macro-transformer
>     (lambda (expr inject compare)
>       (let ((body (cdr expr)) (next (cadr expr)))
>       (printf "next=~a~n" next)
>         (cond
>           [(string? next) (string-append "\"" next "\"")]
>           [(number? next) (number->string next)]
>           [(null? next) ""]
>           [(list? next) `(string-append (js ,(car next)) "("  ")")]
>           )))))
>
> It is supposed to handle numbers and function calls, without building the
> parameter list in the function calls.

It's doing this correctly, is it?

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?

I don't understand what you're trying to do here.

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)"

 
Răzvan

reply via email to

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