Re: [racket-users] Catching duplicate identifiers.

2017-07-19 Thread Jens Axel Søgaard
To take care of shadowing you need to keep track of which identifiers are declared in each internal definition context. Here is one way to do it. /Jens Axel #lang racket ;;; ;;; Declarations ;;; ;; This is a demonstration of how to write a declaration (or definition) ;; form, that can raise a sy

Re: [racket-users] Catching duplicate identifiers.

2017-07-18 Thread Matthias Felleisen
Why don’t you intercept the exception in the error handler and rewrite the error message? Racket already disallows duplicate names in the same scope, which seems to be what you want, except that you don’t like the way the errors are reported. > On Jul 18, 2017, at 5:47 PM, Sam Waxman wrote

Re: [racket-users] Catching duplicate identifiers.

2017-07-18 Thread Sam Waxman
Thanks both for your replies, but it doesn't look like either of these will do exactly what I want. While the code keeping track of id's that you wrote comes close, it doesn't allow for shadowing. I still want racket to do everything that it used to do, so the program (define a 3) (let () (d

Re: [racket-users] Catching duplicate identifiers.

2017-07-18 Thread Jens Axel Søgaard
#lang racket (require (for-syntax syntax/parse syntax/id-set)) (begin-for-syntax (define defined-ids (mutable-free-id-set)) (define (already-defined? x) (free-id-set-member? defined-ids x)) (define (define-it! x) (free-id-set-add!defined-ids x))) (define-syntax (def stx)

Re: [racket-users] Catching duplicate identifiers.

2017-07-18 Thread Matthias Felleisen
#lang racket (define my-favorite-numbers '(1 2 3)) (define (duplicate-exists? n) (member n my-favorite-numbers)) (duplicate-exists? 3) (duplicate-exists? 4) > On Jul 17, 2017, at 3:43 AM, Sam Waxman wrote: > > Hello, > > In the regular #racket, the following program > > (define a 1)

[racket-users] Catching duplicate identifiers.

2017-07-17 Thread Sam Waxman
Hello, 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