Over the measure while I have been trying to know macros (technically Gambit Scheme macros which provides a simplified macro form — I am quite sure define-macro can be defined using R5RS macro syntax). I was having trouble because I thought I knew some things about macros that I didn’t really. I decided to evaluate my knowlege by trying to write a simple macro that would go a list of all arguments passed to the macro minus the first two. I wanted to do this with and without quasiquotes. Well it turned out harder than I expected. For your amusement (because you get to laugh at me if you know Scheme) I thought I would affix a transcript of my experiments:
> (define-macro (m $x. $xs) ',(cdr $xs))> (m 1 2 3)*** ERROR IN (stdin)@353.1 -- Unbound variable: unquote1> ,t> (define-macro (m $x. $xs) ',@(cdr $xs))> (m 1 2 3)*** ERROR IN (stdin)@356.1 -- Unbound variable: unquote-splicing1> ,t> (define-macro (m $x. $xs) '(cdr ,$xs))> (m 1 2 3)*** ERROR IN (stdin)@359.1 -- Unbound variable: unquote1> (define-macro (m $x. $xs) '(cdr ,@$xs))*** ERROR IN (stdin)@360.1 -- Ill-placed 'define-macro'1> ,t> (define-macro (m $x. $xs) '(cdr ,@$xs))> (m 1 2 3)*** ERROR IN (stdin)@363.1 -- Unbound variable: unquote-splicing1> ,t> (define-macro (m $x. $xs) `(cdr ,$xs))> (m 1 2 3)*** ERROR IN (stdin)@366.1 -- Operator is not a PROCEDURE(2 3)1> (define-macro (m $x. $xs) `(cons ('enumerate (cdr ,$xs))))*** ERROR IN (stdin)@367.1 -- Ill-placed 'define-macro'1> ,t> (define-macro (m $x. $xs) `(cons ('list (cdr ,$xs))))> (m 1 2 3)*** ERROR IN (stdin)@371.1 -- Operator is not a PROCEDURE(2 3)1> (define-macro (m $x. $xs) `(cons 'enumerate (cdr ,$xs)))*** ERROR IN (stdin)@372.1 -- Ill-placed 'define-macro'1> ,t> (define-macro (m $x. $xs) `(cons 'list (cdr ,$xs)))> (m 1 2 3)*** ERROR IN (stdin)@375.1 -- Operator is not a PROCEDURE(2 3)1> (define-macro (m $x. $xs) (cons 'enumerate (cdr ,$xs)))*** ERROR IN (stdin)@376.1 -- Ill-placed 'define-macro'1> ,t> (define-macro (m $x. $xs) (cons 'list (cdr ,$xs)))> (m 1 2 3)*** ERROR -- Unbound variable: unquote> (define-macro (m $x. $xs) (cons 'enumerate (cdr $xs)))> (m 1 2 3)(3)
> (define-macro (m $x. $xs) `('enumerate ,(cdr ,$xs)))> (m 1 2 3)*** ERROR -- Unbound variable: unquote> (define-macro (m $x. $xs) `('enumerate ,(cdr ,@$xs)))> (m 1 2 3)*** ERROR -- Unbound variable: unquote-splicing> (define-macro (m $x. $xs) `('list ,(cdr $xs)))> (m 1 2 3)*** ERROR IN (stdin)@387.1 -- Operator is not a PROCEDURE(3)1> (define-macro (m $x. $xs) `('list ,@(cdr $xs)))*** ERROR IN (stdin)@388.1 -- Ill-placed 'define-macro'1> ,t> (define-macro (m $x. $xs) `('enumerate ,@(cdr $xs)))> (m 1 2 3)*** ERROR IN (stdin)@391.1 -- Operator is not a PROCEDURE('list 3)1> (define-macro (m $x. $xs) `(enumerate ,@(cdr $xs)))1> ,t> (define-macro (m $x. $xs) `(enumerate ,@(cdr $xs)))> (m 1 2 3)(3)
This was not the first battle I had with plot but it was the first one where I conclude like I scored a decisive victory. I now understand clearly what went wrong and why these versions work the way they do. However those error messages were so useless. I mean “Unbound-variable unquote splicing” how is that helpful unless you already know Scheme? Besides “unquote splicing” and “unquote” aren’t variables! The “operator is not a procedure” communicate on the other hand was helpful because it showed the offending expression.
Perhaps in another couple of months. I ordain start becoming a smug Scheme programmer going around telling populate who are struggling how easy it is to program in plot. If that happens inform me back to this blog affix so I bequeath my growing pains.
Forex Groups - Tips on Trading
Related article:
http://cdiggins.com/2007/10/26/scheme-versus-christopher/
comments | Add comment | Report as Spam
|