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

Fatal Exceptions #2933

Closed
OAGr opened this issue Jan 8, 2024 · 4 comments · Fixed by #2941
Closed

Fatal Exceptions #2933

OAGr opened this issue Jan 8, 2024 · 4 comments · Fixed by #2941
Labels
Language Regarding Squiggle language semantics, distributions and function registry Std Lib The standard library for Squggle

Comments

@OAGr
Copy link
Contributor

OAGr commented Jan 8, 2024

  • x Is new feature

Description of suggestion or shortcoming:

Maybe something like,

Common.raiseError(message: string)
or
Common.raiseErr(message:string)

This raises the error immediately.

Seems simple enough.

@OAGr OAGr added the Language Regarding Squiggle language semantics, distributions and function registry label Jan 8, 2024
@berekuk
Copy link
Collaborator

berekuk commented Jan 8, 2024

In most languages, raise/throw is a builtin keyword. Tbh I'm not sure why, maybe because it's not an expression and most typed languages don't have Typescript's never?

In Squiggle it seems fine to make it an expression; if ... then ... else throw is useful, and statement-level throw is not useful.

@OAGr OAGr added the Std Lib The standard library for Squggle label Jan 8, 2024
@OAGr
Copy link
Contributor Author

OAGr commented Jan 9, 2024

In most languages, raise/throw is a builtin keyword. Tbh I'm not sure why, maybe because it's not an expression and most typed languages don't have Typescript's never?

In Squiggle it seems fine to make it an expression; if ... then ... else throw is useful, and statement-level throw is not useful.

Sorry, I don't fully follow. Let's discuss tomorrow.

One nice thing about using a simple function is that it would be ~trivial to get started with.

@berekuk
Copy link
Collaborator

berekuk commented Jan 9, 2024

Sorry, I don't fully follow. Let's discuss tomorrow.

Second paragraph is not directly connected to the first, sorry for not making it clearer. I was just thinking out loud about the syntax.

In the approach where we add a keyword, there's the difference between:

f() = {
  x = 5
  throw "oops"
  ...
}

And:

f() = {
  x = checkCondition() ? 5 : throw "oops"
}

In the first example, throw is a statement. The theoretical benefit is that you don't need to pick a variable name.

In the second example, throw is an expression that's never used. (There's a parallel to Typescript here: in Typescript, if your function always throws, then its return type is never, and Typescript considers this type for several purposes, including the control flow analysis.)

Throw/raise is usually a statement, in Python or JS, but in current Squiggle there's no need for statement-level throw, because if you statement-level-throw then your function will always throw (we don't have early returns), and then you could just throw in the end expression.

@OAGr
Copy link
Contributor Author

OAGr commented Jan 9, 2024

Common.throw(str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Regarding Squiggle language semantics, distributions and function registry Std Lib The standard library for Squggle
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants