On Apr 4, 2015, at 11:22 AM, Jos Koot <jos.k...@gmail.com> wrote: > The following puzzles me: > > #lang racket > (define plus +) > (free-identifier=? #'+ #'plus) ; -> #f > > #lang racket > (define-syntax (a stx) > (syntax-case stx () > ((_) (datum->syntax stx (free-identifier=? #'+ #'plus))))) > (define plus +) > (a) ; -> #f > > #lang racket > (define plus +) > (define-syntax (a stx) > (syntax-case stx (+) > ((_ +) #'#t) > ((_ x) #'#f))) > (a plus) ; -> #f > > I am confused, because I expect #t to be produced in the three above cases. > Obviously I don't understand free-identifier=? well. > Can you help me with that?
Maybe you’re thinking of what happens when you use (define-syntax plus (make-rename-transformer #’+)) Instead of (define plus +) > As another question: the docs on syntax-case state: > > "An id that has the same binding as a literal-id matches a syntax object > that is an identifier with the same binding in the sense of free-identifier=?. > The match does not introduce any pattern variables." > > Why isn't or cant't the match introduce a pattern variable? > Without binding the literal-id as a pattern variable, > location information is lost, for example: > > #lang racket > (error-print-source-location #t) > (begin-for-syntax (error-print-source-location #t)) > (define-syntax (a stx) > (syntax-case stx (+) > ((_ +) (raise-syntax-error 'a "msg" stx #'+)))) ; <--- > (a +) > > raises a syntax-error as expected, but it highlights + in the line marked > <---, > not in the last line. > I would prefer the + in the last line to be highlighted. I mostly agree with that idea, but there is a reason why it doesn’t do that. If it did that, then I don’t think you could do things like put multiple of these in a single pattern, so for instance: (define-syntax (a stx) (syntax-case stx (+) [(_ + +) (raise-syntax-error ‘a “msg” stx #’+)])) (a +) It wouldn’t know which + to bind. The way I do this which feels a bit clunky like there should be a better solution: (define-syntax (a stx) (syntax-parse stx [(_ (~and + (~literal +)) (~literal +)) (raise-syntax-error ‘a “msg” stx #’+)])) To tell it specifically to bind it. To make it a little less verbose, you could define a pattern-expander that expanded to (~and + (~literal +)), but I’m not sure how to do better than that. -- 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.