<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-CA link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Did you try to use a macro like the following<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>(define-syntax define-if-not<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (λ (stx)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (syntax-case stx ()<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> [(_ var val)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (with-syntax ([set!define (if (identifier-binding #'var
0)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> #'set!
<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> #'define)])<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (syntax<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'> (set!define var val)))])))<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span
lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
plt-scheme-bounces@list.cs.brown.edu
[mailto:plt-scheme-bounces@list.cs.brown.edu] <b>De la part de</b> Killian
McCutcheon<br>
<b>Envoyé :</b> December-13-08 8:02 AM<br>
<b>À :</b> plt-scheme@list.cs.brown.edu<br>
<b>Objet :</b> [plt-scheme] Avoiding "duplicate definition for
identifier" errors<o:p></o:p></span></p>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I'm having problems with duplicate definition for identifier
errors when using modules.<o:p></o:p></p>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>I have a small DSL for defining some data that looks a bit
like this:<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(mission 20 rendezvous<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> person "Jimmy"<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> place "beach")<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(mission 21 deliver<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> item "peanuts"<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> person "Boris")<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>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:<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(module mission-dsl scheme<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>(define-mission-type rendezvous<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (person <string>)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (place <string>))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(define-mission-type deliver<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (item <string>)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (person <string>))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>.)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>This expands to something like this:<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(define rendezvous (lambda (num . args)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> ;; Code for constructing fields from arg
list based on<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> ;; type constructor in mission type
definition<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> ...))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>;; These are required so the person defining the missions in
the DSL does not need to explicitly quote the field names<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>(define person 'person)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>(define place 'place)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(define deliver (lambda (num . args) ...))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(define item 'item)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>(define person 'person) ;; <== ERROR: duplicate
definition for identifier at: person in: (define-values (person) (quote
person))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>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:<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<div>
<p class=MsoNormal>(define-mission-type rendezvous<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (person <string>)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> (place <string>))<o:p></o:p></p>
</div>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>expand to this:<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(define rendezvous (lambda (num . args)<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal> ...))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>(if (unbound? 'person) (define person 'person)) ;;
There is no unbound? function<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>(if (unbound? 'place) (define place 'place))<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>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.<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>Any help would be appreciated<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal><o:p> </o:p></p>
</div>
<div>
<p class=MsoNormal>Sincerely<o:p></o:p></p>
</div>
<div>
<p class=MsoNormal>Killian<o:p></o:p></p>
</div>
</div>
</body>
</html>