Crawler Tractor doesn't work indefinitely for macros.

Started by Kazimir Majorinc, October 15, 2009, 06:14:59 AM

Previous topic - Next topic

Kazimir Majorinc

(define (crawler-tractor )
   (begin (println "Hi for the " (inc counter) ". time. ")
          (push (last crawler-tractor) crawler-tractor -1)
          (when (> (length crawler-tractor) 3)
                (pop crawler-tractor 1))))


works indefinitely, but


(define-macro (crawler-tractor )
   (begin (println "Hi for the " (inc counter) ". time. ")
          (push (last crawler-tractor) crawler-tractor -1)
          (when (> (length crawler-tractor) 3)
                (pop crawler-tractor 1))))


doesn't. Any chance for that? It appears that functions didn't lost lot of speed...



http://david.farmnet.com.au/files/2009/02/tractor_stilts.jpg">
http://kazimirmajorinc.com/\">WWW site; http://kazimirmajorinc.blogspot.com\">blog.

Lutz

You got it! The speed impact turns out to be hardly measurable and I love the tractor-crawler as much as you do. It well may be a unique feature of newLISP.



For the uninitiated:



The tractor-crawler code pattern runs infinite without looping or recursion by means of self-modifying code. Statements get continuously appended to the function and popped of at the beginning. The change necessary was additional stack cleanup in the macro block.