Page 1 of 1

Crawler Tractor doesn't work indefinitely for macros.

Posted: Thu Oct 15, 2009 1:14 pm
by Kazimir Majorinc

Code: Select all

(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

Code: Select all

(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...

Image

Re: Tractor-crawler doesn't work indefinitely for macros.

Posted: Thu Oct 15, 2009 2:50 pm
by 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.