> On Jun 3, 2019, at 4:54 AM, Alex Knauth <alexan...@knauth.org> wrote:
> 
> 
> 
>> On Jun 3, 2019, at 1:02 AM, Kevin Forchione <lyss...@gmail.com 
>> <mailto:lyss...@gmail.com>> wrote:
>>> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen <matth...@felleisen.org 
>>> <mailto:matth...@felleisen.org>> wrote:
>>>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione <lyss...@gmail.com 
>>>> <mailto:lyss...@gmail.com>> wrote:
>>>> 
>>>> Hi guys,
>>>> I’ve been working with macros and let/cc and have a situation where I have 
>>>> the 2nd macro bound to the let/cc return of the first. No idea how I’d do 
>>>> that, but here’s an example of what I’m attempting to do:
>>>> 
>>>> #lang racket
>>>> 
>>>> (require (for-syntax racket/syntax))
>>>> 
>>>> (define-syntax (fn stx)
>>>>  (syntax-case stx ()
>>>>    [(_ (arg ...) body0 body ...)
>>>>     (with-syntax ([return (format-id #'body0 "~a" #'return)])
>>>>       #'(λ (arg ...) (let/cc return body0 body ...)))]))
>>>> 
>>>> (define-syntax (false stx)
>>>>  (syntax-case stx ()
>>>>    [(_) #'(return #f)]))
>>>> 
>>>> ((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
>>>> ((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f
>>>> 
>>>> My thought is that the 2nd macro doesn’t know about the 1st macro except 
>>>> perhaps through the six of compile time… so that if I had define-syntax 
>>>> working with a lambda I’d have all the pieces available in the (fn …) but 
>>>> not sure what tools I might use to accomplish that.
>>>> 
>>>> Any ideas are appreciated!
>>> 
>>> This situation calls for syntax-parameters in my mind: see docs, too — 
>>> Matthias
>> 
>> Hmmm. A cursory glance at some of the examples suggests I’ll have to do some 
>> exploring on this. One issue that it looks like I’ll have to work out is 
>> that “false” in my example needs to translate to “(return #f)” and I’m not 
>> sure at this stage where a syntax-parameterize statement would be positioned 
>> in the fn macro
> 
> It should go around the same set of expressions that the `return` identifier 
> would have been unhygienically bound in. For this example, that means around 
> `body0 body ...`, or in context:
> 
> (λ (arg ...) (let/cc k (syntax-parameterize ([return (.... #'k ....)]) body0 
> body ...)))
> 
>> (or how it would know to use it unless it could interrogate the body list 
>> looking for that value. That might be what I’d need to do here…
> 
> I'm not sure what you mean by interrogate the body, but if you're referring 
> to the syntax-parameterize needing access to the continuation bound by 
> let/cc, then your right. That's why in the example above, the 
> syntax-parameterize needs to be inside of the let/cc where `k` is bound, and 
> the new parameter value needs to refer to `k`. Is that what you meant?

That’s what I was thinking, but the transformation would have to be something 
more like:

(let/cc return
                        (syntax-parameterize ([false #'(return #f)]) body0 body 
...))))]))

And that doesn’t work. I imagine that would expand into ((return #f)). 

Kevin

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/135285AD-843C-4258-8034-EF9F59E27EB0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to