Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 9:42 AM, Matthias Felleisen  wrote:
> 
> 
> 
>> On Jun 3, 2019, at 12:33 PM, Kevin Forchione  wrote:
>> 
>> Oh! I see! That solves the expansio issue! Wonderful. You’ve opened up a 
>> whole new set of possibilities for me. Thanks, Matthias.
> 
> 
> I am glad I sent my solution a second time :)

Me, too. For some reason the bundling of my emails appeared only to present 
your suggestion of using syntax-parameters and perusing of docs and not the 
code! It made your follow-up comments cryptic though I didn’t realize I was 
missing something until the “OR” in your prior email. Going back through the 
bundle the earlier code was there. The “Or” solution, however, brought home to 
me that you can nest the syntax-parameterize calls. :) 

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/34F49B72-5C89-4994-9288-43DB336E2DBE%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Matthias Felleisen



> On Jun 3, 2019, at 12:33 PM, Kevin Forchione  wrote:
> 
> Oh! I see! That solves the expansio issue! Wonderful. You’ve opened up a 
> whole new set of possibilities for me. Thanks, Matthias.


I am glad I sent my solution a second time :) 

-- 
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/4727251D-33B3-4C88-A99E-F13F4E417AD6%40felleisen.org.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 9:09 AM, Matthias Felleisen  wrote:
> 
> 
> Or, 
> 
> #lang racket
> 
> (require (for-syntax ) racket/stxparam)
> 
> (define-syntax-parameter return (syntax-rules ()))
> (define-syntax-parameter false (syntax-rules ()))
> 
> (define-syntax fn
> (syntax-rules ()
>   [(_ (arg ...) body ...)
>(λ (arg ...)
>  (let/cc fn-exit
>(syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])
>  (syntax-parameterize ([false (syntax-rules () [(_) (return #f)])])
>body ...]))
> 
> ((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
> ((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f
> 

Oh! I see! That solves the expansio issue! Wonderful. You’ve opened up a whole 
new set of possibilities for me. Thanks, Matthias.

-- 
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/F77FB88D-5D84-4F67-87F5-8F53717DFF61%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Matthias Felleisen


Or, 

#lang racket

(require (for-syntax ) racket/stxparam)

(define-syntax-parameter return (syntax-rules ()))
(define-syntax-parameter false (syntax-rules ()))

(define-syntax fn
 (syntax-rules ()
   [(_ (arg ...) body ...)
(λ (arg ...)
  (let/cc fn-exit
(syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])
  (syntax-parameterize ([false (syntax-rules () [(_) (return #f)])])
body ...]))

((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f



-- 
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/B99E2A20-68EE-46C3-B8F4-2066F3C063CD%40felleisen.org.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Matthias Felleisen
#lang racket

(require (for-syntax ) racket/stxparam)

(define-syntax-parameter return (syntax-rules ()))

(define-syntax fn
  (syntax-rules ()
[(_ (arg ...) body ...)
 (λ (arg ...)
   (let/cc fn-exit
 (syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])
   body ...)))]))

(define-syntax false
  (syntax-rules ()
[(_) (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

-- 
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/18038548-A78C-487B-A2A8-7F1C864903BF%40felleisen.org.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 8:51 AM, Matthias Felleisen  wrote:
> 
> 
> My code run your examples. Whay is missinng? 
> 
Here’s what I’ve been trying to run.

#lang racket

(require (for-syntax racket/syntax)
 racket/stxparam)

(define-syntax-parameter false
  (lambda (stx)
  (raise-syntax-error (syntax-e stx) "can only be used inside lambda.")))

(define-syntax (fn stx)
  (syntax-case stx ()
[(_ (arg ...) body0 body ...)
 (with-syntax ([return (format-id #'body0 "~a" #'return)])
   #'(λ (arg ...) (let/cc return
(syntax-parameterize ([false #'return]) body0 body 
...]))

((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
((fn (x y) (when (< x y) (false)) y) 2 30)


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/CC4AB8E6-76E4-43C3-9D2D-497F7467B858%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Matthias Felleisen


My code run your examples. Whay is missinng? 



> On Jun 3, 2019, at 11:36 AM, Kevin Forchione  wrote:
> 
> 
> 
>> On Jun 3, 2019, at 4:54 AM, Alex Knauth  wrote:
>> 
>> 
>> 
>>> On Jun 3, 2019, at 1:02 AM, Kevin Forchione  wrote:
 On Jun 2, 2019, at 7:13 PM, Matthias Felleisen  
 wrote:
> On Jun 2, 2019, at 9:41 PM, Kevin Forchione  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/4F2802CF-7FF0-4C44-8843-97D6FC448239%40felleisen.org.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione


> On Jun 3, 2019, at 4:54 AM, Alex Knauth  wrote:
> 
> 
> 
>> On Jun 3, 2019, at 1:02 AM, Kevin Forchione > > wrote:
>>> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen >> > wrote:
 On Jun 2, 2019, at 9:41 PM, Kevin Forchione >>> > 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.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Alex Knauth


> On Jun 3, 2019, at 1:02 AM, Kevin Forchione  wrote:
>> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen > > wrote:
>>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione >> > 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?

Alex Knauth

> 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/ECF4DCD1-C651-42BC-8138-5314640F2862%40knauth.org.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-02 Thread Kevin Forchione


> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen  wrote:
> 
> 
> 
>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione > > 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 (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…

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/C4425B12-9C1F-4159-B4BA-D09C89419CB9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-02 Thread Matthias Felleisen


> On Jun 2, 2019, at 9:41 PM, Kevin Forchione  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



#lang racket

(require (for-syntax ) racket/stxparam)

(define-syntax-parameter return (syntax-rules ()))

(define-syntax fn
  (syntax-rules ()
[(_ (arg ...) body ...)
 (λ (arg ...)
   (let/cc fn-exit
 (syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])
   body ...)))]))

(define-syntax false
  (syntax-rules ()
[(_) (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

-- 
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/7A495B17-F49A-41BE-8DED-8EC34D4FE61F%40felleisen.org.
For more options, visit https://groups.google.com/d/optout.


[racket-users] macros and let/cc

2019-06-02 Thread Kevin Forchione
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!

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/957E342B-2DCB-4413-9577-8B9F3B1F66BD%40gmail.com.
For more options, visit https://groups.google.com/d/optout.