In the regular #racket, the following program

(define a 1)
(define a 2)

will result in a syntax error letting you know that you have a duplicate 
identifier. I would like to make my own define that throws a custom error 
message in this case. I.e.

(define-syntax (my-define stx)
  (syntax-parse stx
    [(_ id:id expr) (begin
                    (if (duplicate-exists? id) 
                        (syntax-error "Oh no!") 
                   #'(define id expr)]))

I know there's a lot of functions like bound-identifier=? and 
check-duplicate-identifier, but they seem to all be geared towards the user 
putting in all the identifiers in question as function arguments. In this case, 
I need a function like

(duplicate-exists? id)

that just takes in the single identifier, and checks to see if, in the scope 
the function is invoked, there's a duplicate identifier already there. I just 
can't seem to figure out how to write that function.

Thanks in advance!

You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to