Thank you for more examples!

I want to learn some basic macro programming in Chicken. However, it seems
there are multiple macro definition APIs in Chicken: define-syntax,
syntax-rules, syntax-case, define-macro. Which one should I start with?

Also, I have heard that, different from Lisp, macro programming in Scheme
is not recommended. Is it true?

Thank you!

Jinsong

On Fri, May 29, 2015 at 7:44 PM, Michele La Monaca <
mikele.chic...@lamonaca.net> wrote:

> On Fri, May 29, 2015 at 3:10 AM, Jinsong Liang <jinsongli...@gmail.com>
> wrote:
> > Thank you Michele! This is a nice example.
>
> Nice but maybe not very useful:
>
> (apply-syntax or (#f (+ 1 2) (print "hello")))
>
> is just a longer and more cumbersome version of
>
> (or (#f (+ 1 2) (print "hello")))
>
> A far more valuable macro is the following:
>
> (define-macro apply-any
>   (lambda (_ lst)
>     (eval `(cons ',_ ,lst))))
>
> (define l '(#f (+ 1 2) (print "hello")))
> (apply-any or l)
>
> => 3
>
> (let ((x 9)) (apply-any or '(#f (+ x 1) (print "hello"))))
>
> => 10
>
> (apply-any + (list 1 2 3))
>
> => 6
>
> Regards,
> Michele
>
> _______________________________________________
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to