[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Easy object slot access in 5.2
- From: Mark Hamburg <mark@...>
- Date: Sat, 19 Nov 2011 14:04:27 -0800
On Nov 19, 2011, at 8:40 AM, Tony Finch wrote:
> So you don't have to write self repeatedly in methods, you can write:
> function myclass.mymethod(_ENV, arg1, arg2)
> slot1 = arg1 + arg2
> slot2 = arg1 - arg2
> This requires you to import all the functions and modules you use into locals so they can be accessed as upvalues.
> f.anthony.n.finch <firstname.lastname@example.org> http://dotat.at/
Cute. I used to dislike this sort of thing, but it has a certain amount of resonance and leads to thoughts like the following:
* What if writing myclass:mymethod( arg1, arg2 ) seized _ENV in addition defining self (or knowing that we're inside a "method" global lookups went to self?
* Couple this with an import keyword that defines a local based on a require and you then are back to running global free most of the time.
* Maybe there's a notion of the current global scope but anything that defines such scopes also makes it easy to explicitly name them when needing to break out of the current global scope. (Which is really no longer a global scope. It's really just a scope for otherwise unbound names.)
But I can also see all sorts of ways this sort of cute approach to things makes things more fragile as well. For example, the above code ceases to do what you were expecting if you happen to define a local named slot1 or slot2. So, in the end, I probably just come down in favor of being more explicit most of the time (and if we're going to be less explicit, it should probably be in ways that make it easier to write DSL's).