shithub: femtolisp

ref: 4e18c3987bb3f2940be37db6ccb3d7986902e3a1
dir: /test/wt.lsp/

View raw version
(define-macro (while- test . forms)
  `((label -loop- (λ ()
                    (if ,test
                        (begin ,@forms
                               (-loop-))
                      ())))))

(define (tw)
  (set! i 0)
  (while (< i 10000000) (set! i (+ i 1))))

(define (tw2)
  (letrec ((loop (λ ()
                   (if (< i 10000000)
                       (begin (set! i (+ i 1))
                              (loop))
                     ()))))
          (loop)))

#|
interpreter:
while: 1.82sec
macro: 2.98sec

compiler:
while: 0.72sec
macro: 1.24sec
|#