;; lambda needs an environment that's passed at run time, so requires ;; an interpreter modification which i don't think is a good idea ;; atm. so, postponed until i know a non-invasive way to do it. ;; here's the code i had. ;; add this line the parser: ;;; lambda: delayed parsing ; ((eq? 'lambda atom) ; (make-lambda resolve)) ;; create a function which will compile at run time a parametrized ;; program. this will do the following ;; '(A B C) '(foo A bar B baz) lambda ;; -> '(alloc bind-C bindB bindA (foo) duck A (bar) duck B drop baz) ;; where tail call elimination requires the context to be tropped ;; before baz is executed. ;; using 'vector' the code becomes ;; -> '(3 vector (foo) duck A (bar) duck B drop baz) (define (make-local-deref index) (lambda stack stack)) (define (make-lambda resolve) (lambda (text params . stack) (let* ;; split text in body and tail ((rtext (if (null? text) '(nop) ;; need sentinel (reverse text))) (tail (car rtext)) (body (reverse (cdr rtext))) ;; create the local dictionary (locals (map cons params ;; params tagged with sequence number (map make-local-deref (sequence increment 0 (length params))))) (resolve-local (lambda (symbol) (let ((id (assoc->cdr ids symbol))) (if (not id) symbol (make-local-deref id))))) ;; first pass: compile all local words (let ((local-resolve ...)) (pack (parse-cat local-resolve text) stack)))))) ;; create a recursive sequence ussing a successor function ;; (sequence (lambda (x) (+ x 1)) 0 5) (define (sequence succ init n) (unfold (lambda (x) (= x n)) identity succ init)) (define (identity x) x) (define (inc n) (+ n 1))