Re: Fw: Macro Question

Bent Phillipsen <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <CAD1yAUQbNa5yXAuh1VPEX_FR7sWnMxb9eQF79U7zb3k4XhiMAA@mail.gmail.com>
Hi again!

Let me for completeness add that the "fix" shown in the previous email is
more an explanation than a "solution" to the problem.

A "solution" (with the possibility of a default value and a specified
value) would be something like:

(module mm)

(define-class foo a)

(define-syntax identity
    (syntax-rules ()
        ((_ x) x)))

(define-syntax darn
    (syntax-rules ()
        ((_  ) (let ((v 1))
                    (instantiate::foo ((identity a) v))))
        ((_ x) (let ((v x))
                    (instantiate::foo ((identity a) v))))))

(print (darn))
(print (darn 10))


Best regards

Bent

2017-01-06 0:34 GMT+01:00 Bent Phillipsen <[email protected]>:

> Hello Joe!
>
> IMO this is expected behavior - but doesn't work, as the variable in let
> will be generated:
>
> ------------------------------------------------------------
> -----------------------------
>
> (define-syntax bad-macro
>         (syntax-rules ()
>                 ((_ val body) (let ((i val)) body))))
>
> (bad-macro 5 (* 2 i))  ;does not work - "i" in let will be a newly
> generated variable
>
>
> (define-syntax good-macro
>         (syntax-rules ()
>                 ((_ i val body) (let ((i val)) body))))
>
> (good-macro i 5 (* 2 i))  ;does work
>
> ------------------------------------------------------------
> -----------------------------
>
>
> So you probably need:
>
> (module mm)
>
> (define-class foo a)
>
> (define-syntax darn
>    (syntax-rules ()
>       ((_ a )
>        (let ((v 1))
>           (instantiate::foo (a v))))))
>
> (print (darn a))
>
> ... which compiles and gives the output:
>
> #|foo [a: 1]|
>
>
> Best regards
>
> Bent
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.