Subject: Re: 'define-list' with mzscheme
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 18 Dec 2001 04:59:03 GMT
Newsgroups: comp.lang.scheme
Message-ID: <9vmien$14il9$1@fido.engr.sgi.com>
Barry Margolin  <barmar@genuity.net> wrote:
+---------------
| David N. Welton <davidw@dedasys.com> wrote:  [with indenting fixed --rpw3]
| >I figured it out:
| >(define-macro define-list
| >  (lambda (name . args)
| >    (eval `(define ,name ',args))))
| >does what I want.
| 
| A macro that contains EVAL is almost never right.  Macros
| are supposed to expand into what you want them to execute...
+---------------

Yup, exactly. Especially in this case, where EVAL is simply unecessary!

	> (define-macro define-list
	    (lambda (name . args)
	      `(define ,name ',args)))
	> (define-list foobar
	    "1"
	    "abcd"
	    'something
	    (blah (blah blah)))
	> foobar
	("1" "abcd" (quote something) (blah (blah blah)))
	> 

Note that MzScheme also has EXPAND-DEFMACRO-ONCE and EXPAND-DEFMACRO
primitives that help quite a lot when debugging low-level macros:

	> (expand-defmacro-once
	    '(define-list gorp a b (c . d) e))
	(define gorp (quote (a b (c . d) e)))
	> (expand-defmacro-once
	    (expand-defmacro-once
	      '(define-list gorp a b (c . d) e)))
	(#%define-values (gorp) (quote (a b (c . d) e)))
	> (expand-defmacro-once
	    (expand-defmacro-once
	      (expand-defmacro-once
	        '(define-list gorp a b (c . d) e))))
	(#%define-values (gorp) (#%quote (a b (c . d) e)))
	> 

or to see it all at once:

	> (expand-defmacro '(define-list gorp a b (c . d) e))
	(#%define-values (gorp) (#%quote (a b (c . d) e)))
	> 


-Rob

-----
Rob Warnock, 30-3-510		<rpw3@sgi.com>
SGI Network Engineering		<http://www.meer.net/~rpw3/>
1600 Amphitheatre Pkwy.		Phone: 650-933-1673
Mountain View, CA  94043	PP-ASEL-IA

[Note: aaanalyst@sgi.com and zedwatch@sgi.com aren't for humans ]