justin = {
main feed
,
music
,
code
= {
cockos
,
reaper
,
wdl
,
ninjam
,
jsfx
,
more
}
,
askjf
,
pubkey
};
Ask Justin Frankel
No reasonable question unanswered since 2009!
Suggested topics: programming, music, sleep, coffee, etc.
Note: please do not ask questions about REAPER features, bugs or scheduling, use the
forums
instead.
Name:
Ask:
Human (enter yes):
[
back to index
] | [
unreplied
] | [
replied
] | [
recent comments
] | [
all
]
Question:
If variables of a function are private to the function, then what's the use of local() when I cam put countless variables in the function that will still work without using local() to make them private since they are already private?
Asked by local() (102.176.65.x) on October 16 2025, 7:18pm
Reply on October 16 2025, 7:54pm:
assuming you're talking about eel2/jsfx -- variables are global by default _unless_ you specify local()
Comments:
Posted by local() (154.161.183.x) on October 16 2025, 8:29pm:
I saw this in jsfx manual, I mean if the function's variables are already private to the finction, what's the use of the local() when every variable in the function is already private to the function. "Note that the parameters for functions are private to the function, and will not affect global variables. If you need more private variables for a function, you can declare additional variables using a local() "
Posted by local() (154.161.159.x) on October 16 2025, 8:40pm:
To clarify my question more. Assuming I already have 10 variables inside a function. All these 10 variables are private to the function and won't interfere with global variables. But then I wanted to now add 10 more variables to the function. Since variables are private to fu actions, can't I just go straight ahead and add those 10 variables to the function directly. When then should I should local( inside the function to add more private variables when every variables I will add is already private.
Posted by
Justin
on October 17 2025, 1:13pm:
The variables are global by default! the documentation you quoted says "the parameters for functions are private" .. this means parameters, not variables! you are misreading the docs.
Posted by Mespotine (37.4.251.x) on October 17 2025, 2:18pm:
Or in short: the ones in the () after the functionname are local by default. Any additional variable is global unless you make them local. Is the same in Lua, probably other languages too.
Posted by local() (197.251.240.x) on October 17 2025, 7:43pm:
Yes, the ones in the bracket () after function name is what I was asking about. I assumed parameters of a function = the variables.
Posted by
Justin
on October 17 2025, 11:08pm:
parameters are the ones that are passed in by the caller. those are always local. if you want a temporary variable that is not at the global scope, then you use local() for that. so for example function foo(a,b) local(c) ( c = a*b; c+4 ) accesses no global variables.
Posted by local() (197.251.240.x) on October 18 2025, 12:37am:
Okay, thank you for the clarification.
Comment:
Your Name:
-- Site Owner's Name:
(for human-verification) Comment:
[
back to index
] | [
unreplied
] | [
replied
] | [
recent comments
] | [
all
]
Copyright 2025 Justin Frankel
.
|
RSS