-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Use current environment for user-defined functions #125
Comments
I disagree. If you'd like a function to be able to change in the future, use two parameters like this:
Though it can be tedious to type two parameters every time. Perhaps a better solution would be the ability to set function defaults like this:
|
I initially implemented it like this, because I thought that it might be a good idea (and "mutability is bad"). However, most scripting languages (and I tend to think of Insect as a simple scripting language) would imitate the mutable behavior: Python: >>> a = 2
>>> def f(x): return a * x
...
>>> a = 3
>>> f(1)
3 JavaScript: > var a = 2;
> function f(x) { return a*x; }
> a = 3;
> f(1)
3 It's even possible to define the function
Things get even more weird (in my opinion) if two functions are involved. At function definition, Insect captures the entire environment - including all function definitions:
Coming back to your point: A way to secure a function definition from being changed in the future would be to only use constants, not global variables. (JavaScript): > const a = 2;
> function f(x) { return a*x; }
> a = 3;
TypeError: Assignment to constant variable. Currently, Insect only supports built-in constants (like |
@fattredd Any thoughts on this? |
This change makes sense to me. @sharkdp has your opinion on this issue changed? If not, let's add it in v5.9.0. |
Sounds good. My opinion has not changed. |
This is the current behavior:
However, it would probably be more useful if the current environment would be used at call-time:
The text was updated successfully, but these errors were encountered: