Crawler Tractor doesn't work indefinitely for macros.

Pondering the philosophy behind the language
Locked
Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Crawler Tractor doesn't work indefinitely for macros.

Post 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
Last edited by Kazimir Majorinc on Thu Oct 15, 2009 5:25 pm, edited 1 time in total.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

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

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

Locked