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

clarify variable scope, as in... #47

Closed
ldemailly opened this issue Jul 19, 2024 · 3 comments · Fixed by #102
Closed

clarify variable scope, as in... #47

ldemailly opened this issue Jul 19, 2024 · 3 comments · Fixed by #102

Comments

@ldemailly
Copy link
Member

can read from any scope but only write in current one

@ldemailly
Copy link
Member Author

f2=func() {
       log("called f2", n) // log output
       n
}
f1=func() { // function
    log("called f1", n) // log output
    n=n-1
    log("n in f1 now", n)
    f2() // still bound to top-level env not this one
 }
n=5
f1()

maybe f2() called into f1() should refer to f2's env not the env it was created in...?

or have some option

or have upvar

or have &

@ldemailly
Copy link
Member Author

ldemailly commented Aug 2, 2024

it's kind of nice as is, so far, all pure functions that we memoized automatically in #72

might reopen and add & later

@ldemailly ldemailly closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2024
@ldemailly ldemailly reopened this Aug 4, 2024
@ldemailly
Copy link
Member Author

Ok so while trying to trigger an error when a function parameter is a CONSTANT identifier, I stepped on this again

Decided to do the following (in #102 ) :

The environment when calling into a function body is either:

  • Based on the environment when the function was defined (capture), ie previous behavior
    or
  • Based on the current environment if the function is the same (ie recursing) [which is itself based on time of definition per above when it's the first call]

Note this only works for direct recursion, a->b->a would use env of a as when defined, not the first a
(which maybe is dicey)

ldemailly added a commit that referenced this issue Aug 4, 2024
todo: might have messed up the rebase conflicts
ldemailly added a commit that referenced this issue Aug 5, 2024
…ment. Fixed bug with macro environment. Added pprof. (#102)

* ALL_CAPS are now constants - manual tested for all but recursion which is oddly not triggering

* Add comments, rename IsConstantIdentifier-> more go style Constant()

* fix mixup between macro env and eval state env; add tests for constant; allow resetting to same exact value; tinygo workaround for tinygo-org/tinygo#4382

* fix foo++ returning foo+1 instead of foo (only return error if FOO++)

* fix usage of N in pi.gr; log setting constant as info

* big change in recursion environment, see comments and #47 (comment)

todo: might have messed up the rebase conflicts

* add test for presence/absence of == Macro ==> step

* linters

* Adding examples showing huge perf regression

* adding pprof option to main() and found the issue with recursion not using self

* unrelated fix for wasm/web share: preserve the tabs

* replace 2 log.Fatalf by return log.FErrf for consistency

* Apply suggestions from code review

Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>

* add missing import

---------

Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant