[gambit-list] Pasting into REPL good; including file bad
Meng Zhang
wsxiaoys.lh at gmail.com
Sun May 1 08:46:20 EDT 2011
This would be help:
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2006-May/000690.html
nthcdr will be set at runtime, while macro will be evaluate before it.
--
Meng Zhang
Sent with Sparrow
On 2011年5月1日星期日 at 下午5:02, William James wrote:
> The followine code is accepted without error when pasted into
> the REPL, but generates this error when included from a file:
>
> *** ERROR -- Unbound variable: nthcdr
>
>
> (define (firstn n lst)
> (cond
> ((not n) lst)
> ((and (positive? n) (pair? lst))
> (cons (car lst) (firstn (- n 1) (cdr lst))))
> (else '())))
>
> (define (nthcdr n lst)
> (cond
> ((not n) lst)
> ((or (< n 1) (null? lst)) lst)
> (else (nthcdr (- n 1) (cdr lst)))))
>
> (define-macro (%with% sequential? var-val-list . body)
> (let ((paired
> (let recur ((lst var-val-list) (acc '()))
> (if (null? lst)
> (reverse acc)
> ;; In line below, nthcdr is unbound! ---------------------
> (recur (nthcdr 2 lst)
> (cons (firstn 2 (append lst '('()))) acc))))))
> (if sequential?
> `(let* ,paired , at body)
> `(let ,paired , at body))))
> (define-macro (with var-val-list . body)
> `(%with% #f ,var-val-list , at body))
> (define-macro (with* var-val-list . body)
> `(%with% #t ,var-val-list , at body))
>
> (define (foo)
> (with (a 2
> b 9)
> (println b)))
>
>
> This is with Gambit v4.6.1 under Windows.
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110501/93fbf812/attachment.htm>
More information about the Gambit-list
mailing list