From: Trevor D. (Twylite) <tw...@cr...> - 2012-11-21 11:45:45
|
Hi, On 2012/11/21 12:57 PM, Donal K. Fellows wrote: > upvar #1 - Couple to coroutine-specific variable (i.e., not seen in > code before 8.6) This could be replaced by a mechanism to access coroutine-specific variables, or more generally to access dynamically scoped variables (with rules for how scopes propagate through coroutine creation). I won't go into details now; suffice to say that [upvar #1] can be made redundant by alternative approaches and may not warrant special attention. >> Recognizing that call-by-reference via upvar is a place where we kind of >> lose people, anyway, I have been toying with the idea of providing some >> syntax in proc arguments to say that the variable is by reference >> >> proc handle_flightplan_update {*row} { ... } > > Sounds very sensible. Saves me from having to propose it. :-) How would such a mechanism extend to args (if at all)? I'm thinking of interfaces similar to [binary scan]. > upvar #0 - Couple to global/namespace variable (but [global] and > [variable] are more common) I'm a fan of common machinery - it reduces the potential for subtle bugs. Is it possible to make all three of these use the same underlying code? Related: is it possible to refactor argument handling in Tcl 9 to be common across proc, apply, oo::method, etc? I think this question was touched on when discussing marshalling of parameters when resuming a coroutine. > Yes. I'm particularly interested in optimizing cases that will help a > lot of Tclers' code, and that means focusing on the practices that exist > and not just what's easy. It might even be possible to do something > better with [uplevel 1] (enabling much better code in custom looping > constructs, a fairly common practice) I do a lot of this sort of thing, using both [uplevel 1] and [tailcall]. I have a guess - completely unsupported by relevant facts ;) - that [tailcall] is easier to optimise than [uplevel 1], and that any code using [uplevel 1] can be rewritten in continuation-passing style using [tailcall try ...] and [apply]. Regards, Twylite |