I wrote a macro which introduced an implicit binding <~ so that it could be 
used
in expressions at the use-site. Initially did it with

#+begin_src racket
  ;; inside syntax-parse
  (datum->syntax this-syntax #'<~)
#+end_src

followed by macro introduced expr that binds it, then the use-site 
macro-input
that uses it. Think (let/ec <~ macro-input-body).

Worked just fine when tested at top-level or module begin or in expression
position, but then suddenly broke when I wrote another define-like macro 
whose
body expanded into the macro above. Turns out scopes of <~ at use-site and 
one I
introduced in a macro didn't match, at least that's what I surmount from the
message below. I was originally going to ask if someone could teach me to 
read
these messages, but then I found ~syntax-debug-info~ in docs :) and IIUC the
message below tells me there are two identifier bindings where the error 
occurs
whose scope-sets share some scopes namely "common scopes ...", but neither 
one's
scope-set is a subset of the other hence the error. Am I reading it right?

#+begin_src racket
; /Users/russki/Code/tilda/prelude/tilda.rkt:303:20: <~: unbound identifier
;   in: <~
;   context...:
;    #(2212719 use-site) #(2212754 intdef) #(2212808 local)
;    #(2212809 intdef) [common scopes]
;   other binding...:
;    local
;    #(2212718 macro) [common scopes]
;   common scopes...:
;    #(2198084 module) #(2198091 module tilda) #(2212726 local)
;    #(2212727 intdef) #(2212737 local) #(2212738 intdef) #(2212741 local)
;    #(2212742 intdef) #(2212745 local) #(2212746 intdef) #(2212749 local)
;    #(2212750 intdef) #(2212753 local)
#+end_src

I fixed the above with some guesswork that amounted to replacing 
datum->syntax
with

#+begin_src racket
  (syntax-local-introduce #'<~)
#+end_src

which IIUC simply flips the scopes so now <~ is use-site and may as well be 
part
of the macro input. Right?

Suddenly I find myself playing games with hygiene and not really knowing the
rules.

Are there any tutorials that show you how to use things documented in Syntax
Transformers chapter of the Reference?

How do you debug these scope games?

How do you introduce or capture identifier bindings (break hygiene)?

Can you temporarily unbind an identifier (for the extent of some expr), so
basically remove or trim some scopes from identifiers that occur in macro 
input? I
suppose there are several possible cases here: 
- trim or replace scopes of ids whose sets match those at use-site, 
guessing this
  won't unbind "shadowing" identifiers (let or define introduced in your 
macro
  input) i.e. those with extra scopes in addition to use-site,
- how do we deal with those, could we trim ids whose scope sets are 
supersets of
  use-site?
- assuming I know how to do the above, do I walk the syntax tree and trim 
those
  scopes every time I find matching id or is there a better way?

At this point I'd like to better understand how to manipulate sets of 
scopes and
verify the result. Could someone kindly teach me or point out good reads or
examples?

Thanks

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