[racket] Extending syntax-parameters?

From: John Clements (clements at brinckerhoff.org)
Date: Wed Oct 17 01:28:54 EDT 2012

On Oct 16, 2012, at 7:16 PM, Eli Barzilay wrote:

> 20 minutes ago, J. Ian Johnson wrote:
>> I have a syntax parameter that is bound to a transformer. I want to
>> (at certain points) change the parameterization of this parameter to
>> a new transformer that depends on the old one.
>> 
>> I can't do this:
>> #'(syntax-parameterize ([p (syntax-parser
>>                            [pat (some-combination-of (syntax-parameter-value #'p) pat))])])
>>    blah)
>> 
>> Because the value fetched is the inner most one, but I want what it
>> is currently.
> 
> So you need to grab it outside of the new tansformer, just like with
> plain parameters and closures.

just like with plain parameters? that doesn't sound right to me:

#lang racket

(define p (make-parameter 3))

(parameterize ([p (+ 1 (p))])
  (p ))

… produces 4.

That is, the rhs of the parameter-binding is not in the extent of the new binding. 

Am I misunderstanding you?


John


> 
> 
> #lang racket/base
> 
> ;; for fun
> (require (for-syntax racket/base) racket/stxparam)
> (define-syntax-parameter foo #'0)
> (define-syntax (the-foo stx)
>  #`'#,(syntax-parameter-value #'foo))
> (define-syntax (foo-add stx)
>  (syntax-case stx ()
>    [(_ stuff body ...)
>     #`(syntax-parameterize ([foo #'(stuff #,(syntax-parameter-value #'foo))])
>         body ...)]))
> the-foo
> (foo-add 1 (foo-add 2 the-foo))
> 
> ;; IIUC, this is what you want
> (define-syntax-parameter bar (λ (stx) #'0))
> (define-syntax (bar-add stx)
>  (syntax-case stx ()
>    [(_ stuff body ...)
>     (let* ([cur (syntax-parameter-value #'bar)]
>            [new (λ (stx) #`(stuff #,(cur stx)))])
>       #`(syntax-parameterize ([bar #,new])
>           body ...))]))
> bar
> (bar-add add1 (bar-add list bar))
> 
> -- 
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4800 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121016/eeccd392/attachment-0001.p7s>

Posted on the users mailing list.