[gambit-list] Fix expansion of map and foreach

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


Marc:

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)
	 (extended-bindings)
	 (block))

(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)
map-car
*** 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)
map-car
(1)
map-my-car
*** 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
code.

Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20120601/aaae06d1/attachment.htm>


More information about the Gambit-list mailing list