Thanks Mike, (need those old hlp files
this should work in Newlisp (only one macro needed )
(define (add2 x) (+ x 2))
(define (loop fun it value)
(if (zero? it) value
(loop fun (- it 1) (fun value))))
;; ------------------------------------------------------ only now defining the macro
(define-macro (lp from x to y fun)
(loop (eval fun) (eval (- y x -1)) (eval x)))
(not sure in Scheme, but both from and to should eval to nil and not halt the code giving an error - that me be important , in NewLISP everything undeclared evaluates to nil ...... (or maybe not, the macro doesn't use these -- again not sure this can be compiled (?)
> (lp from 1 to 4 add2)
9
best Rob
putting things together ....... using the loop function as a local
(define-macro (from x to y fun)
(let ((loop (lambda (fun it value)
(if (zero? it) value
(loop fun (- it 1) (fun value))))))
(loop (eval fun) (eval (- y x -1)) (eval x))))
> (from 1 to 5 add2) ;; from recursion -- if your prog does tail optimizing , most problems should be solved ?
11