<html><body>
<p><tt>Thanks for your time and patience in answering my questions.</tt><br>
<br>
<tt>Gustaf Neumann &lt;neumann@wu-wien.ac.at&gt; wrote on 03/15/2006 02:46:58 AM:<br>
<br>
&gt; Scott Gargash schrieb:<br>
&gt; &gt;<br>
&gt; &gt; Hello,<br>
&gt; &gt;<br>
&gt; &gt; Is it possible to change the -setter command associated with a <br>
&gt; &gt; parameter at some point other than class definition?<br>
&gt; &gt;<br>
&gt; one can use the method &quot;parameter&quot; at any time to add/redefine <br>
&gt; parameters (see below).<br>
</tt><br>
<tt>The issue with using the &quot;parameter&quot; method is </tt><tt>that </tt><tt>it </tt><tt>changes the parameter definition class-wide, which is undesireable. I'd like to change a parameters -setter property on a per-instance basis. &nbsp;The intended class behavior is to use the default setter class wide at construction time, but after an instance is fully constructed, each instance should use an overridden -setter. &nbsp;Ideally the per instance -setter is directed to a instproc class. </tt><br>
<br>
<tt>Right now I have </tt><tt>define the </tt><tt>-setter property and have an instproc for the class that does the standard behavior, but then in the constructor I define a &quot;[self] proc&quot; to redefine the implementation of the -setter for that instance. &nbsp;</tt><br>
<br>
<tt># This is what I do currently</tt><br>
<tt>Class create A -parameter {{foo -setter myfoo}}</tt><br>
<tt>A instproc init {args} {</tt><br>
<tt>&nbsp; # [self] is valid so revector [my setfoo] to have sideeffects</tt><br>
<tt>&nbsp; [self] proc myfoo {p v} {</tt><br>
<tt>&nbsp; &nbsp; my set $p $v</tt><br>
<tt>&nbsp; &nbsp; #do side-effects</tt><br>
<tt>&nbsp; } </tt><br>
<tt>}</tt><br>
<tt># no side effects at construction time</tt><br>
<tt>A instproc myfoo {p v} {my set $p $v}</tt><br>
<br>
<tt>This works (I get the behavior I desire), but it means I have to 1) define a proc that duplicates the default behavior and 2) construct n identical copies of the implementation for the -setter proc, when really I can get by with the default behavior and one copy of the override behavior shared across all instances, just revectored the setter behavior once it's safe to do so. </tt><br>
<tt>&nbsp;</tt><br>
<tt># What I'd prefer</tt><br>
<tt>Class create A -parameter {foo}</tt><br>
<tt>A instproc init {args} {</tt><br>
<tt>&nbsp; # [self] is valid, revector [self]'s foo setter from default to the side-effectful variant</tt><br>
<tt>&nbsp; [self] parametercmd {foo -setter myfoo} </tt><br>
<tt>}</tt><br>
<tt>A instproc myfoo {p v} {</tt><br>
<tt>&nbsp; my set $p $v</tt><br>
<tt>&nbsp; # do side effects</tt><br>
<tt>}</tt><br>
<br>
<tt>Besides being more memory efficient, it seems to more clearly express my intent. As you say, a trace would work, but traces tend to look and feel a bit like magic.</tt><br>
<tt><br>
&gt; the difference in speed is due to the fact that the default <br>
&gt; setter/getter method is implemented in C,<br>
&gt; whereas the tailored functions are in tcl. it is certainly possible to <br>
&gt; program a tailored getter method<br>
&gt; in C as well, but i doubt that this is worth the effort.<br>
</tt><br>
<tt>As you may have inferred from my questions, performance is an issue for my application. &nbsp;I'm hoping to avoid having to drop into C (and XOTcl's native performance gives me hope, especially relative to snit), but I'm prepared to move to C if and when I have to. </tt><br>
<br>
<tt>I've seen the part of the tutorial about wrapping C-extensions with XOTcl, but is there a reference/tutorial for extending XOTcl in C? &nbsp; How would I go about reimplementing a method in C? &nbsp;Can I just use the vanilla Tcl API or do I need to compile/link against XOTcl also? </tt><br>
<br>
<tt>One thing that has confused me so far is the &quot;namespace on demand&quot; concept. &nbsp;Where are instance variables stored if not in a namespace?</tt><br>
<br>
<tt>% Object a</tt><br>
<tt>::a</tt><br>
<tt>% a set foo 123</tt><br>
<tt>123</tt><br>
<tt>% namespace exists a</tt><br>
<tt>0</tt><br>
<br>
<tt>Where does Object a's foo variable reside? </tt><br>
<br>
<tt>If I wanted to implement a method as a C function, how does the C function find the value of &quot;[a set foo]&quot; via the Tcl API? I.e., what would I pass as the varname to Tcl_GetVar()? &nbsp;Or do I need XOTcl's C API to look it up? &nbsp;Where do I install my C commands such that they are found automatically by XOTcl's method lookup alogrithm?</tt><br>
<br>
<tt>Is this sort of info spec'd by XOTcl or is it implementation defined? Is this what &quot;requireNamespace&quot; does? I've read the docs but I haven't really grokked it yet.</tt><br>
<br>
<tt>        Scott</tt></body></html>