[racket] Defining a typed language

From: Alexander D. Knauth (alexander at knauth.org)
Date: Mon Oct 27 05:43:38 EDT 2014

I had made a pull request about this that was almost the same, but something really weird was happening with require that I don’t understand.  

I had tried it with (datum->syntax stx ‘(require a-typed-lang/more)), and that worked, as long as a-typed-lang/main.rkt _didn’t_ require a-typed-lang/more.

So it didn’t work if (require a-typed-lang/more) was in a-typed-lang/main.rkt, it didn’t work, but commenting that out made it work again.  

Does anyone know what’s happening here?

https://github.com/AlexKnauth/racket-typed-lang/commit/da05d39e3f3f6349fe1e4508214e798f23d6e08e#diff-17746ffaeb9e57be950d8d7212288771L4

On Oct 26, 2014, at 9:36 PM, E. Moran <l-rkt at agate7blue.fastmail.fm> wrote:

> On Mon Oct 20 07:08:54 EDT 2014, Konrad Hinsen wrote:
>> I have put the code on Github for easier access:
>> 
>>  https://github.com/khinsen/racket-typed-lang
>> 
>> Once this works, it can serve as a template for others.
> 
> Thanks for posting this...  I was just wondering whether you've considered using
> datum->syntax here.  It'd maybe not be the most elegant solution,
> but it would at least give you a working language.
> 
>  -- a-typed-lang/main.rkt -------------
> 
>  #lang typed-racket/minimal
> 
>  (require typed/racket
>           (only-in typed/racket
>                    [#%module-begin tr:module-begin]
>                    [require tr:require]))
> 
>  (provide (except-out (all-from-out typed/racket) #%module-begin)
>           (rename-out [module-begin #%module-begin]))
> 
>  (define-syntax (module-begin ix)
>    (syntax-case ix ()
>      [(_ rest ...)
>       (with-syntax
>         ([rix
>           ; tr:require keeps the meaning that it has in this module, but the
>           ; s-exp as a whole lands in the *caller's* lexical context...
>           (datum->syntax ix (list #'tr:require 'a-typed-lang/more))])
>         #'(tr:module-begin
>             rix
>             rest ...))]))
> 
>  -- a-typed-lang/more.rkt -------------
> 
>  #lang typed/racket
> 
>  (provide foo)
> 
>  (: foo (Integer -> Integer))
>  (define (foo x)
>    (* 2 x))
> 
>  -- example.rkt -----------------------
> 
>  #lang a-typed-lang
> 
>  (: x Integer)
>  (define x 42)
> 
>  (displayln x)
> 
>  (displayln (foo x))
> 
>  (displayln (impersonator? foo))
> 
> The above works under v5.3.4, anyway.
> 
> Hope this helps...  Evan
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.