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

From: Andre Mayers (andre.mayers at usherbrooke.ca)
Date: Sat Dec 13 08:34:25 EST 2008

Did you try to use a macro like the following


(define-syntax define-if-not

  (λ (stx)

    (syntax-case stx ()

      [(_ var val)

       (with-syntax ([set!define (if (identifier-binding #'var 0)




            (set!define var val)))])))


De : plt-scheme-bounces at list.cs.brown.edu [mailto:plt-scheme-bounces at list.cs.brown.edu] De la part de Killian McCutcheon
Envoyé : December-13-08 8:02 AM
À : plt-scheme at list.cs.brown.edu
Objet : [plt-scheme] Avoiding "duplicate definition for identifier" errors


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? function

(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/7d77905a/attachment.html>

Posted on the users mailing list.