Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

re: onlisp with-gensyms and allf macro question

12 views
Skip to first unread message

WJ

unread,
May 7, 2012, 8:50:06 AM5/7/12
to
Antony Sequeira wrote:

> I am reading OnLisp trying to learn macros.
> I am having trouble with the following two
>
> ;;pp. 145
> ;;evaluate a body with bunch of symbols in list syms set to gensyms
> (defmacro with-gensyms (syms &body body)
> `(let ,(mapcar #'(lambda (s)
> `(,s (gensym)))
> syms)
> ,@body))
>
> ;;pp. 169
> ;;sets a bunch of varibales in args to the value val
> (defmacro allf (val &rest args)
> (with-gensyms (gval)
> `(let ((,gval ,val))
> (setf ,@(mapcan #'(lambda (a) (list a gval))
> args)))))

Racket:

(define-syntax-rule (set-all val var ...)
(begin
(set! var val) ...))

> (define x 0)
> (define y 0)
> (set-all 88 x y)
> x
88
> y
88
0 new messages