For a functional programming assignment, I am writing a scheme macro that translates scheme code to coffeescript code. I am using guile on Linux Mint 12, and have (use-syntax (ice-9 syncase)) active.
Currently, I am trying to nest let-syntax in define-syntax and I keep getting an unexpected 'invalid syntax' error. Please excuse any poor programming habits as I am a scheme newbie. :)
My code:
(define-syntax coffee
(syntax-rules (define lambda)
; translate define function
((_ (define arg1 arg2))
(begin
(let-syntax ((temp
(syntax-rules ()
((_) (quote-replace-list 'arg1 'arg2))))))
(if (list? 'arg1)
(string-append (coffee (car 'arg1)) " = "
(comma-splice (cdr 'arg1)) " -> "
(coffee temp))
(string-append (coffee 'arg1) " = "
(coffee arg2)))))))
and my output:
guile> (load "hw2-retry.scm")
guile> (coffee (define (x y) (+ x y)))
ERROR: invalid syntax (let-syntax ((temp (syntax-rules () ((_)
(quote-replace-list (quote #) (quote #)))))))
ABORT: (misc-error)
After several of trying to research this error, I'm starting to think I am just not understanding something fundamental. I was sure you could nest a let-syntax inside a define-syntax. What am I doing wrong?
let-syntax
here has no body. You can tell this because the(let-syntax ...)
is indented at the same level as the(if (list? ...) ...)
. – dyoo