newLISP Fan Club

Forum => Whither newLISP? => Topic started by: Kazimir Majorinc on October 15, 2009, 06:14:59 AM

Title: Crawler Tractor doesn't work indefinitely for macros.
Post by: Kazimir Majorinc on October 15, 2009, 06:14:59 AM
(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...



(//%3C/s%3E%3CURL%20url=%22http://david.farmnet.com.au/files/2009/02/tractor_stilts.jpg%22%3E%3CLINK_TEXT%20text=%22http://david.farmnet.com.au/files/2009/%20...%20stilts.jpg%22%3Ehttp://david.farmnet.com.au/files/2009/02/tractor_stilts.jpg%3C/LINK_TEXT%3E%3C/URL%3E%3Ce%3E)
Title: Re: Tractor-crawler doesn't work indefinitely for macros.
Post by: Lutz on October 15, 2009, 07:50:33 AM
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.