tags 14482 notabug thanks Hi,
Sanel Zukan <[email protected]> skribis: > --------------------------------------- > > (define (partition-two lst) > (if (< (length lst) 2) > '() > (cons > (list (car lst) (cadr lst)) > (partition-two (cddr lst))))) > > (define-macro (letn bindings . body) > `(let* ,(partition-two bindings) > ,@body)) > > (define (println v) > (display v) > (newline)) > > (println > (letn (a 3 > b 4 > c 4 > d a > f (+ a b)) > (+ a b c d f))) > > --------------------------------------- > > It correctly prints result, but I'm getting also: > > --------------------------------------- > ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 > ;;; or pass the --no-auto-compile argument to disable. > ;;; compiling /home/sanel/letn.ss > ;;; WARNING: compilation of /home/sanel/letn.ss failed: > ;;; ERROR: Unbound variable: partition-two > 21 > --------------------------------------- That’s because ‘partition-two’ is only visible at run time, and not at macro-expansion time. To fix that, use the ‘eval-when’ form: --8<---------------cut here---------------start------------->8--- (eval-when (load compile eval) (define (partition-two lst) (if (< (length lst) 2) '() (cons (list (car lst) (cadr lst)) (partition-two (cddr lst)))))) --8<---------------cut here---------------end--------------->8--- (BTW, I recommend looking at R5RS ‘syntax-rules’ and R6RS ‘syntax-case’ hygienic macros.) Ludo’.
