Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-18 Thread Vityou
Thanks, that makes sense. However, I tried doing this with a variable defined within a program, but it doesn't work. I would like the user to define their our `root` function to wrap everything, however, when I try to access it with `syntax-local-introduce` it isn't found. I have:

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Philip McGrath
The error is `set!` reporting that `doc` is undefined, because the `doc` identifier from `md-module-begin` is introduced hygienically. Also, I believe your pattern for `md-module-begin` has an extra set of parentheses. Here is a working version: #lang racket/base #lang racket/base (module lang

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Vityou
Stupid question, but how would I saving them in a global variable? So far I have this: (define-syntax handle (syntax-parser [(_ b:expr) #`(set! #,(syntax-local-introduce (datum->syntax #f 'doc)) (string-append #,(syntax-local-introduce (datum->syntax #f 'doc)) b))])) (define-syntax

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Shu-Hung You
I would try make-wrapping-module-begin too. Basically, it wraps all module-level forms that "calculates something" with the syntax object you gave it. For example, the following program ;; some-language.rkt #lang racket (provide (except-out (all-from-out racket)

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Vityou
Thanks for the example. I'm still somewhat new to racket, so I may have to study the example for a while before I understand it. The `make-wrapping-module-begin` that Alexis mentioned seems to do something similar, so I may end up using that due to it's simplicity. -- You received this

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-16 Thread Philip McGrath
In general, you can look for identifiers that are free-identifier=? to something from the grammar for "fully expanded programs" ( https://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29). That's a little abstract, though, so I've included an example. There might be more

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-16 Thread Vityou
How would I go about doing this? Is there a certain function that can tell if something is a top-level declaration? On Thursday, August 16, 2018 at 6:44:53 PM UTC-6, Philip McGrath wrote: > > You probably want to partially expand the expressions, collect the > definitions, and lift them to the

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-16 Thread Alexis King
You might find make-wrapping-module-begin from syntax/modbeg useful here: http://docs.racket-lang.org/syntax/module-helpers.html#%28def._%28%28lib._syntax%2Fwrap-modbeg..rkt%29._make-wrapping-module-begin%29%29 Alexis > On Aug 16, 2018, at 18:58, Vityou wrote: > > I'm attempting to make a

Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-16 Thread Philip McGrath
You probably want to partially expand the expressions, collect the definitions, and lift them to the module level. -Philip On Thu, Aug 16, 2018 at 11:58 PM, Vityou wrote: > I'm attempting to make a language similar to scribble. I'm using the > `make-at-reader` that scribble provides, and have

[racket-users] How to handle define forms in a scribble-like language

2018-08-16 Thread Vityou
I'm attempting to make a language similar to scribble. I'm using the `make-at-reader` that scribble provides, and have my module-begin as this: (define-syntax md-module-begin (syntax-parser [(_ (expr1 ...)) #'(#%module-begin (define doc (parse-markdown (string-append (begin expr1) ...)))