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

Bind an expression to the "it" variable _before_ evaluating it #920

Merged
merged 2 commits into from
Sep 30, 2020

Conversation

robdockins
Copy link
Contributor

so we can cache the value via it's thunk. This prevents reevaluating
the term when the "it" variable is referenced later.

Fixes #881

so we can cache the value via it's thunk.  This prevents reevaluating
the term when the "it" variable is referenced later.

Fixes #881
Copy link
Contributor

@brianhuffman brianhuffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very straightforward to me.

Do you think a regression test would make sense for this? Maybe something with trace would work, or do you think that would be too fiddly?

@robdockins
Copy link
Contributor Author

Humm, yeah we could maybe do something with trace. I'll see if that makes sense.

@brianhuffman
Copy link
Contributor

That regression test is the same as what I was thinking of. The behavior in the current master is kind of weird:

Cryptol> traceVal "doing some work" (42 : Integer)
doing some work 42
42
Cryptol> it
doing some work 42
42
Cryptol> it
42
Cryptol> it
42

@robdockins
Copy link
Contributor Author

Yeah, it demonstrates that we already had the necessary mechanics in place. We basically do a magic let binding to it, which thunks it. That means after the first evaluation of it, the interpreter doesn't evaluate it again. We just needed to do things in the other order!

@robdockins robdockins merged commit 39abfc4 into master Sep 30, 2020
@RyanGlScott RyanGlScott deleted the reuse-it branch March 22, 2024 14:45
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

Successfully merging this pull request may close these issues.

Using it variable after evaluation recomputes values
2 participants