Re: Assignment Operators
Jeremy Tregunna <[email protected]> Wed, 16 May 2012 15:16:49 -0600
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
Radical, but I like our method of assignment in Acute (warning: may contain dragons). Think of this psuedo-c code: (&foo).set(1); This above code would be seen as this: Get the address of some fictitious "foo" variable, and then set its value to 1. "foo" need not be in scope; if it's not, it would pick a location and return that. This works best in cases where you expose the underlying structure of your slot table in a meaningful way. You can make that intermediary an object, and return that from the 'address of' operator. We're going to take a similar approach in Acute, though details aren't entirely fleshed out at the moment, so we're sticking with having only one form of assignment until that is known; setSlot. The benefit of the above is also that assignment now takes only one argument. This was the last of the "Io Calculus" core primitives that we hadn't been able to factor out into a single argument method. Remember though too, : has been made special in the mainline Io. Using it in an identifier like that can have unforeseen consequences when interacting with the objective-c bridge. This is already a problem requiring a whitespace between an identifier and := already. We need to be nice to our users, and reduce their cognitive load, not add to it. Regards, Jeremy Tregunna On Wednesday, 16 May, 2012 at 3:07 PM, Kurtis Rainbolt-Greene wrote: > > So while I like :: and : for setterSlot and setSlot symbols, ::: for setterSlot, :: setSlot, and : for updateSlot seems like overkill. Suggestions? > > On Wed, May 16, 2012 at 3:23 AM, Jan-Paul Bultmann <[email protected] (mailto:[email protected])> wrote: > > > > > > It is there so that you can easily update Object members. > > Take for example the following. > > > > A := Object clone do( > > x := 5 > > nonlocal := method( > > x = 10 > > ) > > > > local := method( > > x := 10 > > ) > > > > First case you assigned `A x` a new value. > > Second case you created a local variable. > > > > Cheers Jan > > > > On May 16, 2012, at 8:21 AM, Kurtis Rainbolt-Greene wrote: > > > > > > So I've been using Io for a bit now, writing a package manager, > > > writing a few packages. I even wrote a syntax definition file for > > > Sublime Text 2. > > > > > > One thing I've noticed since writing that defintion file is that it > > > doesn't seem like Io needs the "=" character in the assignment > > > operators. > > > > > > Consider the following: > > > > > > ``` io > > > Version := Object clone do( > > > major ::= 0 > > > minor ::= 0 > > > patch ::= 0 > > > > > > asString := method( "#{major}.#{minor}.#{patch}" ) > > > ) > > > ``` > > > > > > Pretty simple object, right? Now imagine if you didn't need the `=` characters. > > > > > > ``` io > > > Version: Object clone do( > > > major:: 0 > > > minor:: 0 > > > patch:: 0 > > > > > > asString: method( "#{major}.#{minor}.#{patch}" ) > > > ) > > > ``` > > > > > > Smaller, slightly easier to read, and no confusion with the `==`, > > > `!=`, `+=`, `-=`, `>=`, `<=`, `~=`, `&=`, or `||=` operators that > > > usually crop up in programming languages. > > > >