[gambit-list] Fix expansion of map and foreach

Bradley Lucier lucier at math.purdue.edu
Fri Jun 1 14:40:15 EDT 2012


Since you're moving the primitive expansion code to _t-univ.scm, this is
a good time to fix the expansions of map and foreach.

For example, consider the following source code:

(declare (standard-bindings)

(define (my-car x)
  (car x))

(define (map-car l)
  (map car l))

(define (map-my-car l)
  (map my-car l))

(define l '((1 2) . 4))

(pp l)

(pp 'map-car)

(pp (map-car l))

(pp 'map-my-car)

(pp (map-my-car l))

I'm not going to show the output of

heine:~/Desktop> gsc -c -expansion test-map.scm

but you get the following behavior in the interpreter and the compiler:

heine:~/Desktop> gsc test-map.scm
heine:~/Desktop> gsi test-map.scm
((1 2) . 4)
*** ERROR IN "test-map.scm"@20.5 -- (Argument 2) LIST expected
(map '#<procedure #2 car> '((1 2) . 4))
heine:~/Desktop> gsi test-map
((1 2) . 4)
*** ERROR IN | test-map.o3| -- (Argument 2) LIST expected
(map '#<procedure #2 my-car> '((1 2) . 4))

And, if you look at the generated C code, map-car unconditionally calls
generic car, while map-my-car optimistically expands the call to car.

In brief, map-car doesn't catch the error, and it's a lot slower than
map-my-car.  In my opinion, map-car and map-my-car should have the same

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://webmail.iro.umontreal.ca/pipermail/gambit-list/attachments/20120601/aaae06d1/attachment.html 

More information about the Gambit-list mailing list