Lyman S. Taylor wrote:
> In article <5j65el$...@
helix.cs.uoregon.edu>,
> Juan Jose Flores Romero <
j...@cs.uoregon.edu> wrote:
>
> >USER(8): (defmacro swap (x y)
> > `(let ((temp ,x))
> > (setq ,x ,y)
> > (setq ,y temp)))
> >SWAP
>
> This isn't hygienic. The following:
>
> (swap temp b )
> or
> (swap a temp)
>
> won't work... You'll need a unique temporary variable to
> solve this problem.
>
> (defmacro swap ( x y )
> (let (( temp (gensym)))
> `(let ((,temp ,x ))
> (setq ,x ,y)
> (setq ,y ,temp))))
Racket:
(define-syntax-rule (swap x y)
(let ((temp x))
(set! x y)
(set! y temp)))
(define temp 2)
(define a 22)
(swap temp a)
(list temp a)
=> '(22 2)