If you are implementing a new language, this can be done by delegating
the "=-to-let" work to the macro-expander and let the reader simply
parenthesizing the input into s-expression form. In this approach, we
don't need to worry about being hygienic in the reader since the
actual work is done by the macro expander.

For example, we can make the reader turn the following input

; a-test.rkt
#lang my-let-lang
x = 5;
a = 8;
my-let = 10;
= = a + a;
u = x + my-let + = + = + = + = + =;
printf("u = ~a\n", u);

into some parenthesized form

(module a-test my-let-lang
    (= x 5) (= a 8) (= my-let 10) (= = (+ a a))
    (= u (+ x my-let = = = = =))
    (printf "u = ~a\n" u))

and implement a module-begin macro that turns the parenthesized body
into my-let.

(provide
 (rename-out [new-module-begin #%module-begin]))
(require
 (rename-in racket [#%module-begin racket-module-begin]))

(define-syntax (new-module-begin stx)
  (syntax-parse stx
    ; parse the s-exp-ized "=" syntax here
    [(_ (= x:id e:expr) ... body)
     #'(racket-module-begin
        (make-nested-my-let ((x e) ...) body))]))

--Shu-Hung

On Fri, Aug 18, 2017 at 9:21 AM, gfb <g...@cs.toronto.edu> wrote:
> Assuming the setup where you make a module syntax object and call 
> strip-context on it, you can add a scope to all the user's identifiers after 
> that so they're not considered “above” any of the language's identifiers. 
> Make a function to do the marking:
>
> (define marker (make-syntax-introducer #true))
>
> Then walk the syntax object tree and replace each user identifier ‘id’ with 
> (marker id 'add). Depending on your parsing setup, you could have a specific 
> non-terminal for places a user identifier occurs and have a very generic 
> syntax tree walker that looks for the non-terminal and adds the mark to the 
> identifier.
>
> If you make a second marker for all other identifiers you encounter, then 
> none of the user's identifiers will be “under” the language's bindings, and 
> error messages will be better if the user accidentally uses (without binding) 
> one of the language's names.
>
> --
> 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.

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