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

Evaluation of subexpressions in Any.of #419

Open
usaoc opened this issue Dec 3, 2023 · 2 comments
Open

Evaluation of subexpressions in Any.of #419

usaoc opened this issue Dec 3, 2023 · 2 comments

Comments

@usaoc
Copy link
Collaborator

usaoc commented Dec 3, 2023

I have two questions:

  1. Should the subexpressions be evaluated whenever matching happens?
  2. If yes, should Any.of have a short-circuiting behavior?

The following program showcases the difference in behavior.

def bx :: Box.later_of(Any.of(block:
                                println("one")
                                1,
                              block:
                                println("two")
                                2)):
  Box(1)
bx.value
bx.value := 2
bx.value
  • If no to 1, then “one” and “two” will be printed;
  • If yes to 1,
    • If yes to 2, then “one”, “one”, “two” will be printed;
    • If no to 2, then “one”, “two”, “one”, “two” will be printed.
@usaoc
Copy link
Collaborator Author

usaoc commented Dec 3, 2023

Somewhat relatedly: evaluation of subexpressions in Real.{at_least,above,below,at_most} and {Real,Int}.in.

@mflatt
Copy link
Member

mflatt commented Dec 6, 2023

My first impression is that the answer to 1 should be "no", and the expressions should be evaluated when the definition is evaluated.

But that would implement that the environment of a function argument's annotation doesn't include earlier arguments. I can't remember whether that feature of the current implementaation is important and intentional for some purpose, or if it's just an artifact of the current expansion:

fun f(a, b :: Real.in(a, 10)):
  "ok"

f(1, 9)
f(1, 20) // => does not satisfy annotation

usaoc added a commit that referenced this issue Feb 18, 2024
In particular, do not *include* the annotation's predicate if
unchecked, which means the predicate is neither evaluated nor even
expanded.  I'm not sure whether this is intended, but it seems
consistent with how other forms behave.  This may deserve more
discussion at #419.
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