On Saturday 01 February 2003 07:09 am, Brian Candler wrote:
> Actually, this could be solved in the current scenario, simply by searching
> for a 'leftvol=' method before falling back to a local variable assignment.
>
> The efficiency cost, however, would be unbearable. Imagine the simple
> statement:
>
>     x = 0

and also a much more subtle problem arises involving inheritence. so subtle in 
fact i can't recall how it actually occurs, but it was point out by david 
balck i think some time ago. this fallback idea just dosen't work either, 
despite how slow it might be.


> Furthermore, consider cases like this:
>
>     if ... some condition
>        ...
>        flag = true
>     end
>
>     flag && do_something
>
> In the current model, 'flag' is always available at the final statement, as
> a known local variable, with value 'nil' if not assigned. If it were
> dynamically created, then the final statement might crash altogether. If
> there were any chance of this happening, you would have to add 'flag=nil'
> at the top of the code, effectively a declaration of the variable.

another good point.

> You could of course resolve this by making local variables have a distinct
> syntax from method calls - say $variable. Oops, we wouldn't want that :-)

:-) yes, sometimes i think it would just have been better if local variables 
were prefixed with say, %x = 1.

my idea of scope.x = 1 dosen't help this ambiguity either really.

hmmm.... you know what. here's the thing. it really is all about scope. $ 
specifies a global scope, @ an object scope (@@ the class scope), and no 
prefix means the local scope. that's for variables. but for methods it's 
different. what would a global method be?, "ClassName." is the prefix used 
for class methods, and no prefix means object scoped methods (a shortcut for 
'self.') ...no prefix the source of the ambiguity.

by contrast we certainly don't do around calling $bar() or @bar() or @@bar() 
as method calls. nor do we use ClassName.x or self.x to mean a class 
variable.

so here's a chart:

		variable		method
global	$			(what?)
class	@@			ClassName.
object	@			self. (or none)
local		(none)		(n/a)

so i guess i just like to wonder if there could be a better chart.


-- 
tom sawyer, aka transami
transami / transami.net