Reputation: 1141
Is there any solid way to pass parameter to proc
by reference(without using upvar
)?
Upvotes: 1
Views: 2124
Reputation: 137767
No. Not if you want to be able to modify the value inside the procedure and have that modification visible outside.
Tcl's procedures have their arguments passed strictly by value (the implementation actually passes by immutable reference, which is cheaper for complex structures, and uses a copy-on-write modification technique under the covers; it looks like pass-by-value) so you can't affect the outside world except by bringing it in with something like upvar
. Sometimes, the things you pass in might be a handle to a modifiable entry (e.g., a class instance, a DOM node) and then you'd be able to observe a difference from outside, but that's not actually modifying the thing that was passed in itself (the handle) but rather the thing that it references.
Upvotes: 4