I'm having problems with duplicate definition for identifier errors when using modules.<div><br></div><div>I have a small DSL for defining some data that looks a bit like this:</div><div><br></div><div>(mission 20 rendezvous<br>
</div><div> person "Jimmy"</div><div> place "beach")</div><div><br></div><div>(mission 21 deliver</div><div> item "peanuts"</div><div> person "Boris")</div><div><br></div>
<div><br></div><div>The DSL code sits in one file and is loaded by the scheme file which implements the DSL. To implement this DSL, I have a macro for defining mission types which allows me to do this:</div><div><br></div>
<div>(module mission-dsl scheme</div><div>.</div><div>.</div><div>.</div><div>(define-mission-type rendezvous</div><div> (person <string>)</div><div> (place <string>))</div><div><br></div><div>(define-mission-type deliver</div>
<div> (item <string>)</div><div> (person <string>))</div><div>.</div><div>.</div><div>.)</div><div><br></div><div>This expands to something like this:</div><div><br></div><div>(define rendezvous (lambda (num . args)</div>
<div> ;; Code for constructing fields from arg list based on</div><div> ;; type constructor in mission type definition</div><div> ...))</div><div><br></div><div>;; These are required so the person defining the missions in the DSL does not need to explicitly quote the field names</div>
<div>(define person 'person)</div><div>(define place 'place)</div><div><br></div><div>(define deliver (lambda (num . args) ...))</div><div><br></div><div>(define item 'item)</div><div>(define person 'person) ;; <== ERROR: duplicate definition for identifier at: person in: (define-values (person) (quote person))</div>
<div><br></div><div><br></div><div><br></div><div>So, Im wondering if there's a way to get around these duplicate definitions, maybe by checking if the identifier is bound in the define-mission-type macro before trying to define it, ie have this:</div>
<div><br></div><div><div>(define-mission-type rendezvous</div><div> (person <string>)</div><div> (place <string>))</div></div><div><br></div><div>expand to this:</div><div><br></div><div>(define rendezvous (lambda (num . args)</div>
<div> ...))</div><div><br></div><div>(if (unbound? 'person) (define person 'person)) ;; There is no unbound? function</div><div>(if (unbound? 'place) (define place 'place))</div><div><br></div><div><br>
</div><div><br></div><div>Ive looked for a way to do this, but haven't found anything. I really want to keep the DSL as simple as possible to make it easier for the person writing in it (not a programmer). This means, if at all possible, not having to prefix the field names with the mission type, and not having to quote the field names.</div>
<div><br></div><div>Any help would be appreciated</div><div><br></div><div>Sincerely</div><div>Killian</div>