[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] MORE ON OTCL



On Thu, 6 Jul 2000, A. Jain wrote:

> I checked it out and found surprisingly that the passing is by "VALUE" 

Well, yes, but you were using ordinary instance variables, right?

 
> But then refer to "ns-sat.tcl"
> For example in the procedure add-interface

it's an instproc, not a procedure. 'method' is probably a better term.


> local variables are set
> equal to instance variables AND later on the pointer updates are made to
> local variables ONLY. 

"pointer updates"? This isn't C. I don't see a pointer anywhere.


> AND since the passing is by value that means the pointers of instance
> variables are not updated. 
> 
> THEn WHERE ARE THEIR(instance vars) POINTERS UPDATED ???? 
> AND WHAT"S THE NEED FOR UPDATING THE POINTERS OF LOCAL VARIABLES WHEN
> THEIR CHANGE IS NOT GLOBALLY REFLECTED ????

Hey, no fair; that's a different question to your previous email.
AND STOP SHOUTING.

You didn't say that your chosen instance variables were _objects_ in
your previous mail (i.e. created with set blah [new [bibble]], such
as:

set phy_tx_($t) [new [lindex $args 6]] )


You're referring to part of add-interface in ns-sat.tcl:

Node/SatNode instproc add-interface args {
[..]
        #
        # Local Variables
        #
        #set nullAgent_ [$ns_ set nullAgent_]
        set linkhead $linkhead_($t)
        set phy_tx $phy_tx_($t)
        set phy_rx $phy_rx_($t)
        set mac $mac_($t)
        set ifq $ifq_($t)
        set ll $ll_($t)
        set drophead $drophead_($t)
        set iif $iif_($t)

Now, as far as I can tell, that's a convenient shorthand used in the
code that is written later, nothing more (so that 'Local Variables'
comment is probably a bit of a misnomer - local alias shorthand, more
like, since typing the local aliases of $phy_tx_($t) etc. is
tedious). Try appending:

	puts $linkhead
        puts $linkhead_($t)

immediately after that load of set commands, recompile and see what
results. You'll see the same object identifiers printed twice,
indicating that here you're, er, passing actual objects by reference
this time. 

This is different from say fiddling with the example given in the 
instvar docs: ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/object.html

abagel proc taste {} {
	$self instvar flavor
	set localflavor $flavor
	puts $localflavor
	set localflavor banana
	puts $localflavor
	return $flavor
}
% abagel set flavor sesame
sesame
% abagel taste
sesame
banana
sesame

...good old assigning of contents and passing by value.


If it makes you feel better you could have:
	set linkhead "$linkhead_($t)"

I suppose, to indicate a just-think-of-me-as-a-text-substitution
relationship; that and a few more comments could give the casual
reader a better idea of what's going on here.

set does very different things depending on what it's doing them to.


> PLS ANSWER IT SOON,

OH, YOU'LL SOON DROP THE 'SOON'.
I'M GOING TO LIE DOWN NOW. OTCL'S GIVEN ME A HEADACHE.

L.

<[email protected]>PGP<http://www.ee.surrey.ac.uk/Personal/L.Wood/>