Re: [racket-users] Re: Help implementing an early return macro

2020-10-28 Thread Dominik Pantůček
Hi racketeers, I would second this suggestion. Although it might look slightly un-rackety at first sight, for certain types of code flow it does the job really well. And most importantly - I am using escape continuations in much wilder setup (yes, futures) and it imposes no noticeable

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread David Storrs
I'm not sure if this is exactly what you want, but the handy module (which I still need to split up into less of a Fibber McGee) includes handy/try. This would let you do the following: #lang racket (require handy/try) (define x (random 100)) ; these are obviously silly functions that are only

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Hendrik Boom
On Wed, Oct 28, 2020 at 03:54:29AM -0700, Jack Firth wrote: > So I'm a little tired of writing code like this: > > (define x ...) > (cond > [(take-shortcut? x) (shortcut x)] > [else >(define y (compute-y x)) >(cond > [(take-other-shortcut? x y) (other-shortcut x y)] > [else >

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Sam Caldwell
Ryan's solution is almost certain to be nicer, but if you do find yourself needing internal definition contexts now or in the future, this is similar to a case I ran into while adding `define` to a language implemented with Turnstile. I wrote a blog post outlining the solution [1], which I

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Ryan Culpepper
This is a nice example of a macro design pattern that I think of as "partial expansion with trampolining". You don't need to deal with the internal definition context API, because you can return definitions to the macro expander, let it handle their interpretation, and then resume your work.

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Philip McGrath
The most similar example that comes to mind is the way `for`-like forms handle the `body-or-break` nonterminal to support `#:break` and `#:final`. In particular, I think you would end up needing something analogous to these semantics for definitions

Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Laurent
I've also had the same issues for a long time, and condd was almost good enough, but the #:do is too specific. But recently I'm using something much simpler (no continuation) and straightforward: cond/else https://github.com/Metaxal/bazaar/blob/master/cond-else.rkt By contrast to other

[racket-users] Re: Help implementing an early return macro

2020-10-28 Thread Alex Harsanyi
Are you looking for `let/ec`? (let/ec return (define x (random 10)) (unless (even? x) (log-info "x wasn't even, x = ~a" x) (return -1)) (define y (random 10)) (unless (even? y) (log-info "y wasn't even, y = ~a" y) (return -1)) (+ x y)) Alex. On Wednesday, October 28,

[racket-users] Help implementing an early return macro

2020-10-28 Thread Jack Firth
So I'm a little tired of writing code like this: (define x ...) (cond [(take-shortcut? x) (shortcut x)] [else (define y (compute-y x)) (cond [(take-other-shortcut? x y) (other-shortcut x y)] [else (define z ...) (cond ...)])]) That is, I have some logic and that logic

[racket-users] 2nd Call for Contributions: BOB 2021 [Feb 26, Deadline Nov 13]

2020-10-28 Thread Michael Sperber
Racket talks are extremely welcome at BOB! BOB Conference 2021 "What happens when we use what's best for a change?" http://bobkonf.de/2021/cfc.html Berlin, February 26 Call for Contributions