Subject: Re: (map (define aa bb) '(a b c d) '(1 2 3 4))
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1996/11/10
Newsgroups: comp.lang.scheme
Message-ID: <5646nk$e1c@tokyo.engr.sgi.com>

John L. Stein <stein@seas.ucla.edu> wrote:
+---------------
| Whats wrong with (map (define aa bb) '(a b c d) '(1 2 3 4)) ?
| I wnat to get a =1 , b = 2, etc.
+---------------

0. Since you're probably doing this only for side-effects, using
   "for-each" instead of "map" would save some consing.

1. You're using "map" wrong. It's first argument must be a function
   (closure), not a "form", e.g.:

      (map cons '(a b c d) '(1 2 3 4)) ==> ((a . 1) (b . 2) (c . 3) (d . 4))

2. Anyway, "define" isn't a function, so you can't pass it to "map"
   (or "for-each").

3. Anyway, functions can't (in general) define top-level variables.

Of course, if you allow "eval" (*ugh!* *gross!* *slow!*), you could
always do this:

   (for-each (lambda (x y) (eval `(define ,x ,y))) '(a b c d) '(1 2 3 4))


-Rob

-----
Rob Warnock, 7L-551		rpw3@sgi.com
Silicon Graphics, Inc.		http://reality.sgi.com/rpw3/
2011 N. Shoreline Blvd.		Phone: 415-933-1673  FAX: 415-933-0979
Mountain View, CA  94043	PP-ASEL-IA