Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from-just! with thunk for nothing case #5

Open
jackfirth opened this issue Feb 27, 2017 · 2 comments
Open

from-just! with thunk for nothing case #5

jackfirth opened this issue Feb 27, 2017 · 2 comments

Comments

@jackfirth
Copy link

I'd like to take a maybe and unwrap it by running a thunk when it's a nothing. from-just works with a plain value instead of a thunk, while from-just! doesn't let me override the nothing behavior. I can work around this easily but it seems like something that should be built in.

An #:on-nothing keyword argument to from-just! would let me do this while remaining backward compatible and not adding a third from-just function.

@lexi-lambda
Copy link
Owner

I don’t really like this very much, but the point you raise is reasonable. I don’t want to change from-just!, though, since the whole point of it having that ! at the end is to make it scary. I don’t want to add a safe case to from-just! because I think it would dilute the evilness.

In Haskell, this obviously isn’t a problem because Haskell is lazy. (Interestingly, this is one of the areas where we probably take laziness for granted in Haskell and forget how useful it is when debating strictness vs laziness.) However, Racket is strict, so sometimes from-just isn’t right.

Perhaps we could add support to from-just for this instead of from-just!? Unfortunately, case-lambda and case-> do not support keyword arguments, but it would be possible to construct an API that semantically has this contract:

(case-> (-> any/c maybe? any/c)
        (-> #:thunk (-> any/c) maybe? any/c))

How would you feel about that?

@jackfirth
Copy link
Author

That would work fine for me. The either-positional-or-keyword-arg thing is a bit odd, but I don't really see any way around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants