[plt-scheme] hygienic macros
Have improved the random-choice macro to
(require-for-syntax (lib "1.ss" "srfi"))
(define-syntax random-choice
(lambda (x)
(syntax-case x ()
((_ expr ...)
(with-syntax (((index ...)
(iota (length (syntax-e (syntax
(expr ...)))))))
(syntax (case (random (length '(expr ...)))
((index) expr) ...)))))))
but having difficulties eliminating all but one of the
LENGTH computations so LENGTH is only calculated once.
Original macro (from ANSI Common Lisp, Paul Graham,
(pg. 170):
(defmacro random-choice (&rest exprs)
`(case (random ,(length exprs))
, at let ((key -1))
(mapcar #'(lambda (expr)
`(,(incf key) ,expr))
exprs))))
Michael Rice
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/