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
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
>
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
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.
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
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
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
7 matches
Mail list logo