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:

(define-for-syntax md-module-begin
  (syntax-parser
    [(_ (expr1 ...))
     #:with accumulated (syntax-local-introduce (datum->syntax #f 
'accumulated))
     #:with root (syntax-local-introduce (datum->syntax #f 'root))
     #`(wrapping-modbeg (define accumulated "")
                        expr1 ...
                        (define doc (root (parse-markdown accumulated)))
                        (provide doc)
                        (print doc))]))

For my module begin and:

**asdf**

@"asdf2"

@(define (root x . y) '(test "asdf"))

@(define x 5)
x Is @x

@(string-append "test " "string")
<asdf>123</asdf>

as an example program.  However, it complains that `root` is undefined.

On Friday, August 17, 2018 at 9:51:38 PM UTC-6, Philip McGrath wrote:
>
> 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 racket/base
>   (require syntax/wrap-modbeg
>            (for-syntax racket/base
>                        syntax/parse))
>   (provide (except-out (all-from-out racket/base)
>                        #%module-begin)
>            (rename-out [md-module-begin #%module-begin]))
>   (define-syntax handle
>     (syntax-parser
>       [(_ b:expr)
>        #:with doc (syntax-local-introduce (datum->syntax #f 'doc))
>        #`(set! doc (string-append doc b))]))
>   (define-syntax wrapping-modbeg
>     (make-wrapping-module-begin #'handle))  
>   (define-syntax md-module-begin
>     (syntax-parser
>       [(_ expr1 ...)
>        #:with doc (syntax-local-introduce (datum->syntax #f 'doc))
>        #'(wrapping-modbeg (define doc "")
>                           expr1 ...)])))
>
> (module example (submod ".." lang)
>   (provide doc)
>   "Example")
>
> (require (submod "." example))
>
> doc
>
>
>
> -Philip
>
> On Sat, Aug 18, 2018 at 3:36 AM, Vityou <[email protected] <javascript:>> 
> wrote:
>
>> 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 wrapping-modbeg
>>   (make-wrapping-module-begin #'handle))
>>   
>> (define-syntax md-module-begin
>>   (syntax-parser
>>     [(_ (expr1 ...)) #'(wrapping-modbeg (define doc "")
>>                                         expr1 ...)]))
>>
>> However, it complains that `set!` isn't defined.  I thought it would be 
>> defined since my module provides `racket/base`.
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to