I&#39;m having a bit of trouble re-implementing a DSL using macros (I&#39;m a macro newbie). The DSL is very simple, looks like this:<div><br></div><div>(commands</div><div>&nbsp;&nbsp; &nbsp;player &quot;Please Sir! Can I have some more?&quot;</div>
<div>&nbsp;&nbsp; &nbsp;show-item &quot;soup&quot;</div><div>&nbsp;&nbsp; &nbsp;play-sound &quot;sfx_aghast&quot;</div><div>&nbsp;&nbsp; &nbsp;skip-next-wait</div><div>&nbsp;&nbsp; &nbsp;npc &quot;MORE!?!?&quot;</div><div>&nbsp;&nbsp; &nbsp;show-item &quot;scowl&quot;</div><div>&nbsp;&nbsp; &nbsp;wait-input)</div>
<div><br></div><div>Its a script for a game, with lists of commands that are performed in certain situations. Some of the commands take a string or a number as a parameter, others have no parameters. Now, the script is not written by a programmer, so to make it easier for the designer, I offered him this syntax where there are only parentheses around the whole form, and not around each individual command in the list. My solution without macros was to define commands as evaluating to symbols of the same name, and just pass all arguments to the&nbsp;commands&nbsp;function to a parsing function. It worked well, but there was a lot of repetitive code.</div>
<div>Now as an exercise I&#39;m reimplementing the DSL using macros. The commands are defined using a macro, which seems to work fine. Then I try to define the&nbsp;commands&nbsp;form like this:</div><div><br></div><div>(define-syntax (commands&nbsp;stx)</div>
<div>&nbsp;&nbsp;(syntax-case stx ()</div><div>&nbsp;&nbsp; &nbsp;[(_ unary arg rest ...)</div><div>&nbsp;&nbsp; &nbsp; (eq? 1 (procedure-arity (syntax-object-&gt;datum (syntax unary))))</div><div>&nbsp;&nbsp; &nbsp; (syntax (cons (unary arg) (_ rest ...)))]</div><div>&nbsp;&nbsp; &nbsp;[(_ nullary rest ...)</div>
<div>&nbsp;&nbsp; &nbsp; (eq? 0 (procedure-arity (syntax-object-&gt;datum (syntax nullary))))</div><div>&nbsp;&nbsp; &nbsp; (syntax (cons (nullary) (_ rest ...)))]</div><div>&nbsp;&nbsp; &nbsp;[(_ &#39;()) (syntax &#39;())]))&nbsp;</div><div><br></div><div><br></div><div>
<br></div><div>but that gives me the error:</div><div>&nbsp;</div><div>procedure-arity: expects argument of type &lt;procedure&gt;; given player</div><div><br></div><div>So Im guessing either the definitions of my commands aren&#39;t available in the compile-environment, or I have to jump through extra syntax hoops to get at them. I try to make do with second best:</div>
<div><br></div><div><div>(define-syntax (start stx)</div><div>&nbsp;&nbsp;(syntax-case stx ()</div><div>&nbsp;&nbsp; &nbsp;[(_ unary arg rest ...)</div><div>&nbsp;&nbsp; &nbsp; (or (string? (syntax-object-&gt;datum (syntax arg)))</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(number? (syntax-object-&gt;datum (syntax arg))))</div>
<div>&nbsp;&nbsp; &nbsp; (syntax (cons (unary arg) (_ rest ...)))]</div><div>&nbsp;&nbsp; &nbsp;[(_ nullary rest ...)</div><div>&nbsp;&nbsp; &nbsp; (syntax (cons (nullary) (_ rest ...)))]</div><div>&nbsp;&nbsp; &nbsp;[(_ &#39;()) (syntax &#39;())]))</div></div><div><br></div><div>
but that gives me the error:</div><div><br></div><div>commands: bad syntax in:&nbsp;commands</div><div><br></div><div>and highlights the recursive call to the macro in the first template. Thing is I don&#39;t know why, and the Dybvig paper &quot;Writing Hygienic Macros in Scheme with Syntax-Case&quot; seems to contain very similar code in the cond macros.</div>
<div><br></div><div>So basically I&#39;m flummoxed, and any help would be appreciated.</div><div><br></div><div>Cheers,</div><div>Killian</div>