Skip to content

Add support for "try f" (when f is a function)#4186

Open
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:try-function
Open

Add support for "try f" (when f is a function)#4186
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:try-function

Conversation

@d-torrance
Copy link
Copy Markdown
Member

This returns a new compiled function closure that is equivalent to x -> try f x.

Closes #4184

This returns a new compiled function closure that is equivalent to
x -> try f x
@d-torrance d-torrance requested a review from mahrud April 8, 2026 19:42
@mahrud
Copy link
Copy Markdown
Member

mahrud commented Apr 10, 2026

I guess in the current behavior, something like try(x -> x/0) never fails until you actually run it, or unless there's a syntax error in which case try doesn't prevent the error either, so maybe this is fine?

Does this also allow select(5, try (x -> (x-1)^1) else false) for instance? (meaning, try that function, and if it fails instead of null return false). I imagine we can combine it with other try syntax as well.

Also, this is tangential, but I've always wanted this to work:

i5 : apply(5, x -> if even x then continue else x)
stdio:5:29:(3): error: unhandled continue command

It's really annoying that I have to use return instead and then remove null entries.

@d-torrance
Copy link
Copy Markdown
Member Author

Does this also allow select(5, try (x -> (x-1)^1) else false) for instance?

Not currently -- only try f is supported. I suppose implementing all the other variations of try wouldn't be too bad. I can give it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants