|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Question about the implementation of :=I've been wondering about := recently.
It is kind of like an operator, but not really since: Lobby foo := "bar" is apparently a message being sent to the Lobby with parameters foo and "bar". And moreover: foo := "bar" Still seems like a message sent to the Lobby, but Lobby doesn't appear to be part of the message stream. I don't know where in the code to look to see how this is done. Can someone direct me? Or just explain it? Thanks! -Harold |
|
|
Re: Question about the implementation of :=Operators are transformed in Io. There are two types: operators and
assignment operators. Assignment operators transform the operator into a different name, i.e., in the case of := it transforms it into setSlot taking the value on the left hand side; interning it into a string, and then what's on the right hand side as the second argument to setSlot. So: a := b is transformed into: setSlot("a", b) As for regular operators, precedence is applied and it inserts ( and ) where appropriate around the message name, i.e., 1 + 2 * 3 + 1 parses to: 1 +(2 *(8) +(1)) -- Jeremy Tregunna jtregunna@... On 11-Jun-08, at 1:53 PM, Harold Hausman wrote: > I've been wondering about := recently. > > It is kind of like an operator, but not really since: > Lobby foo := "bar" > > is apparently a message being sent to the Lobby with parameters foo > and "bar". > > And moreover: > foo := "bar" > > Still seems like a message sent to the Lobby, but Lobby doesn't appear > to be part of the message stream. > > I don't know where in the code to look to see how this is done. Can > someone direct me? Or just explain it? > > Thanks! > -Harold > > ------------------------------------ > > Yahoo! Groups Links > > > |
|
|
Re: Question about the implementation of :=--- In iolanguage@..., Jeremy Tregunna <jtregunna@...> wrote:
> Operators are transformed in Io. Given the ability to change the OperatorTable on the fly, when does this transformation happen? Is it immediately prior to executing a 'line' of code? (So, changes to operator precedence on the current line don't take effect until the next?) Does the code get re-parsed/parenthesized upon any change to the OperatorTable? |
|
|
Re: Question about the implementation of :=It happens on the fly. You change precedence, it won't effect anything
that has run, but only future code. -- Jeremy Tregunna jtregunna@... On 11-Jun-08, at 2:27 PM, phrogz42 wrote: > --- In iolanguage@..., Jeremy Tregunna <jtregunna@...> > wrote: >> Operators are transformed in Io. > > Given the ability to change the OperatorTable on the fly, when does > this transformation happen? Is it immediately prior to executing a > 'line' of code? (So, changes to operator precedence on the current > line don't take effect until the next?) Does the code get > re-parsed/parenthesized upon any change to the OperatorTable? > > > > ------------------------------------ > > Yahoo! Groups Links > > > |
|
|
Re: Question about the implementation of :=On Wed, Jun 11, 2008 at 12:00 PM, Jeremy Tregunna <jtregunna@...> wrote:
> Operators are transformed in Io. Where does this "transformation" take place? Is it in the parser, or some part of the interpreter? Thanks for your explanation, -Harold |
|
|
Re: Question about the implementation of :=It takes place in the lexer.
-- Jeremy Tregunna jtregunna@... On 11-Jun-08, at 3:36 PM, Harold Hausman wrote: > On Wed, Jun 11, 2008 at 12:00 PM, Jeremy Tregunna <jtregunna@... > > wrote: >> Operators are transformed in Io. > > Where does this "transformation" take place? Is it in the parser, or > some part of the interpreter? > > Thanks for your explanation, > -Harold > > ------------------------------------ > > Yahoo! Groups Links > > > |
|
|
Re: Question about the implementation of :=On Wed, Jun 11, 2008 at 1:43 PM, Jeremy Tregunna <jtregunna@...> wrote:
> It takes place in the lexer. > That statement may be true, but consider this (admittedly evil) construction: Io 20080120 Io> foo := method( OperatorTable addOperator("+", 1) ) ==> method( OperatorTable addOperator("+", 1) ) Io> bar := method( 1 + 3 * 2; foo; 1 + 3 * 2; Lobby getSlot("bar") message println; nil ) ==> method( 1 + 3 * 2; foo; 1 + 3 * 2; Lobby getSlot("bar") message println; nil ) Io> bar 1 +(3 *(2)) ; foo ; 1 +(3 *(2)) ; Lobby getSlot("bar") message println ; nil ==> nil As seen above, the precedence of the messages in this method were determined when creating it, not 'on the fly' as it is changed with 'foo'. If we continue on and redefine the method again, then the precedence is locked in the other way: Io> bar := method( 1 + 3 * 2; foo; 1 + 3 * 2; Lobby getSlot("bar") message println; nil ) ==> method( 1 + 3 * 2; foo; 1 + 3 * 2; Lobby getSlot("bar") message println; nil ) Io> bar 1 +(3) *(2) ; foo ; 1 +(3) *(2) ; Lobby getSlot("bar") message println ; nil ==> nil This has all been highly educational for me. The realization that assignment is a specific special case of the operator table that does something really specific is helpful in my thinking. Naturally, we took it to silly pathological land, but that was just for fun. Thanks again for your insights. -Harold |
| Free Forum Powered by Nabble | Forum Help |