[gambit-list] Pasting into REPL good; including file bad

William James w_a_x_man at yahoo.com
Sun May 1 05:02:41 EDT 2011

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)
    ((not n) lst)
    ((and (positive? n) (pair? lst))
      (cons (car lst) (firstn (- n 1) (cdr lst))))
    (else '())))

(define (nthcdr n lst)
    ((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.

More information about the Gambit-list mailing list