[plt-scheme] Avoiding "duplicate definition for identifier" errors

From: Killian McCutcheon (entarter at gmail.com)
Date: Sat Dec 13 08:02:00 EST 2008

I'm having problems with duplicate definition for identifier errors when
using modules.
I have a small DSL for defining some data that looks a bit like this:

(mission 20 rendezvous
    person "Jimmy"
    place "beach")

(mission 21 deliver
    item "peanuts"
    person "Boris")

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:

(module mission-dsl scheme
(define-mission-type rendezvous
    (person <string>)
    (place <string>))

(define-mission-type deliver
    (item <string>)
    (person <string>))

This expands to something like this:

(define rendezvous (lambda (num . args)
     ;; Code for constructing fields from arg list based on
     ;; type constructor in mission type definition

;; These are required so the person defining the missions in the DSL does
not need to explicitly quote the field names
(define person 'person)
(define place 'place)

(define deliver (lambda (num . args) ...))

(define item 'item)
(define person 'person) ;; <== ERROR: duplicate definition for identifier
at: person in: (define-values (person) (quote person))

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:

(define-mission-type rendezvous
    (person <string>)
    (place <string>))

expand to this:

(define rendezvous (lambda (num . args)

(if (unbound? 'person) (define person 'person))  ;; There is no unbound?
(if (unbound? 'place) (define place 'place))

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.

Any help would be appreciated

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081213/749a0ace/attachment.html>

Posted on the users mailing list.