[Coldstuff] Some undocumented functions
Bruce Mitchener
coldstuff@cold.org
Thu, 06 Jun 2002 01:09:43 -0600
The description below maches my understanding. I don't like that
inherited_var uses a different search order than method lookup though.
It is also somewhat slower than method stuff as inherited_var() isn't
cached (obviously) and can require more intermediate objects to be
loaded in the search for a value.
And then to explain more of why I don't like them, I'd have to get into
how I wish Cold had an 'unbound' value for the default value rather than
0 .... *sigh*
Good night.
- Bruce
Brad Roberts wrote:
> I'll let Bruce, Brian, or Brandon correct any errors in this, so don't
> take it as gospel until someone backs me up.
>
> get_var('variable)
> default_var('variable)
> inherited_var('variable)
>
> All three take a symbol that is the name of the variable to lookup. All
> three will throw ~varnf if the variable isn't declared on the parent that
> contains the method being executed. All three return the value of that
> variable as contained in the child object, if it exists. Where they
> differ is in what they do if the child object doesn't have a value yet.
>
> get_var returns 0.
>
> default_var returns the value of the variable on the parent (it will
> always have a value, though it might be 0 also).
>
> inherited_var walks up the parent tree (in breadth first order) and
> returns the value from the first parent to have a value.
>
> So.. that's the short form of the docs for these three builtin functions.
> The latter two rather break one of the fundamental tenet in cold's
> object system, strong variable encapsulation. That said, coldcore uses
> default_var in 3 places, all of which could have easily been done without.