Io N00B - basic questions

View: New views
13 Messages — Rating Filter:   Alert me  

Io N00B - basic questions

by Windoze :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

HI all,

I've read most of the docs on Io, but am still unclear about these two
items:


What's the difference really between

*::=*

and

*:=*

The ' := ' is obvious, ' ::= ' not so.


And what's the difference between the coroutine syntax of

*@*thing

and

*@@*thing


thank you for the assistance,


GO IO !

Re: Io N00B - basic questions

by Jeremy Tregunna-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

::= is an operator for newSlot() which creates a setSlot which takes  
an argument and sets the value on the slot. While that doesn't make a  
lot of sense, consider this:

foo := 42

Creates a single slot, "foo" with the value 42.

Consider:

foo ::= 42

Creates a slot called "foo" with the value 42, and creates a "setFoo"  
which takes a single argument, the value to update the "foo" slot with.

The difference between @ and @@ is that @ returns a Future and fires  
off a coro into the "background". Consider:

blurgle := @bar

whatever bar is will be run in a coro and a future will be immediately  
returned to blurgle. If you access blurgle (lookup that slot) before  
bar is done running, the coro will pause and wait for bar to finish  
before returning the result.

If you run:

blurgle := @@bar

What will happen is blurgle will be nil immediately, and when you  
access blurgle you'll get nil until bar is finished running then  
you'll get the value of whatever bar evaluated to.

I hope this is clear.

On 21-Apr-09, at 10:36 AM, HowardP wrote:

>
>
> HI all,
>
> I've read most of the docs on Io, but am still unclear about these  
> two items:
>
>
> What's the difference really between
>
> ::=
>
> and
>
> :=
>
> The ' := ' is obvious, ' ::= ' not so.
>
>
> And what's the difference between the coroutine syntax of
>
> @thing
>
> and
>
> @@thing
>
>
> thank you for the assistance,
>
>
> GO IO !
>
>
>

Regards,

Jeremy Tregunna
jeremy.tregunna@...




Re: Io N00B - basic questions

by Windoze :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Jeremy - yes this is helpful.

> Consider:
> foo ::= 42
> Creates a slot called "foo" with the value 42, and creates a "setFoo"
which takes a single argument, the value to update the "foo" slot with.

Then is a 'setWhatever' like a property encapsulation?  In other words, if I
use the " *::= *" operator/message, I *must* then use it for subsequent
access to the 'foo' (or 'Whatever') slot?  Or is " ::= " just allowing
access to more of what goes on under the hood, that is " *:= " hides* the
setWhatever, whereas "::=" bubbles it up so to speak?

If I'm not totally off here, does that then mean then I'd have to use

setFoo := 99   to get foo to be 99 - and that

foo:=99  would be something else / or raise an exception?

( I'll test this of course, but thought it would be good to post the info
anyway, as several of my programming pals are also fuzzy on this too. )

Re: Io N00B - basic questions

by spir :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Le Tue, 21 Apr 2009 10:47:12 -0700,
HowardP <how2paut@...> s'exprima ainsi:

> Thanks Jeremy - yes this is helpful.
>
> > Consider:
> > foo ::= 42
> > Creates a slot called "foo" with the value 42, and creates a "setFoo"
> which takes a single argument, the value to update the "foo" slot with.
>
> Then is a 'setWhatever' like a property encapsulation?  In other words, if I
> use the " *::= *" operator/message, I *must* then use it for subsequent
> access to the 'foo' (or 'Whatever') slot?  Or is " ::= " just allowing
> access to more of what goes on under the hood, that is " *:= " hides* the
> setWhatever, whereas "::=" bubbles it up so to speak?
>
> If I'm not totally off here, does that then mean then I'd have to use
>
> setFoo := 99   to get foo to be 99 - and that
>
> foo:=99  would be something else / or raise an exception?
>
> ( I'll test this of course, but thought it would be good to post the info
> anyway, as several of my programming pals are also fuzzy on this too. )

Io> x := Object clone
==>  Object_0x9d7df60:

Io> x a ::= 1
==> 1
Io> x
==>  Object_0x9d7df60:
  a                = 1
  setA             = method(...)

Io> x setA(2)
==>  Object_0x9d7df60:
  a                = 2
  setA             = method(...)

Io> x a = 3
==> 3
Io> x
==>  Object_0x9d7df60:
  a                = 3
  setA             = method(...)

Io> x a := 4
==> 4
Io> x
==>  Object_0x9d7df60:
  a                = 4
  setA             = method(...)


While I wouldn't guess about the intention of Io developpers, I personly consider '::=' as a nicety that also sets a setter.
set* does not build a kind of property. Note:

Io> x m ::= method("m running")
==> m running
Io> x
==>  Object_0x9d7df60:
  a                = 4
  m                = method(...)
  setA             = method(...)
  setM             = method(...)


Denis
------
la vita e estrany

Re: Io N00B - basic questions

by Jeremy Tregunna-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm not sure what you're trying to get at Denis. Can you elaborate?

On 21-Apr-09, at 4:33 PM, spir wrote:

> Le Tue, 21 Apr 2009 10:47:12 -0700,
> HowardP <how2paut@...> s'exprima ainsi:
>
>> Thanks Jeremy - yes this is helpful.
>>
>>> Consider:
>>> foo ::= 42
>>> Creates a slot called "foo" with the value 42, and creates a  
>>> "setFoo"
>> which takes a single argument, the value to update the "foo" slot  
>> with.
>>
>> Then is a 'setWhatever' like a property encapsulation?  In other  
>> words, if I
>> use the " *::= *" operator/message, I *must* then use it for  
>> subsequent
>> access to the 'foo' (or 'Whatever') slot?  Or is " ::= " just  
>> allowing
>> access to more of what goes on under the hood, that is " *:= "  
>> hides* the
>> setWhatever, whereas "::=" bubbles it up so to speak?
>>
>> If I'm not totally off here, does that then mean then I'd have to use
>>
>> setFoo := 99   to get foo to be 99 - and that
>>
>> foo:=99  would be something else / or raise an exception?
>>
>> ( I'll test this of course, but thought it would be good to post  
>> the info
>> anyway, as several of my programming pals are also fuzzy on this  
>> too. )
>
> Io> x := Object clone
> ==>  Object_0x9d7df60:
>
> Io> x a ::= 1
> ==> 1
> Io> x
> ==>  Object_0x9d7df60:
>  a                = 1
>  setA             = method(...)
>
> Io> x setA(2)
> ==>  Object_0x9d7df60:
>  a                = 2
>  setA             = method(...)
>
> Io> x a = 3
> ==> 3
> Io> x
> ==>  Object_0x9d7df60:
>  a                = 3
>  setA             = method(...)
>
> Io> x a := 4
> ==> 4
> Io> x
> ==>  Object_0x9d7df60:
>  a                = 4
>  setA             = method(...)
>
>
> While I wouldn't guess about the intention of Io developpers, I  
> personly consider '::=' as a nicety that also sets a setter.
> set* does not build a kind of property. Note:
>
> Io> x m ::= method("m running")
> ==> m running
> Io> x
> ==>  Object_0x9d7df60:
>  a                = 4
>  m                = method(...)
>  setA             = method(...)
>  setM             = method(...)
>
>
> Denis
> ------
> la vita e estrany
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Regards,

Jeremy Tregunna
jeremy.tregunna@...




Re: Io N00B - basic questions

by Friedrich Weber-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

the implementation of newSlot (which is the equivalent method to ::=)
does just create a very simple setter method:
http://github.com/stevedekorte/io/blob/master/libs/iovm/io/A2_Object.io#L337
You currently don't have to use the setter method, you can also use =
(which is updateSlot), but the setter method is handy for chaining.
Assuming that you did `myObject a ::= nil; myObject b ::= nil; myObject
c ::= nil` before:

myObject setA(123) setB(456) setC(789)

is the same as

myObject a = 123
myObject b = 456
myObject c = 789

but shorter :)

Regards,

Friedrich

Re: Io N00B - basic questions

by Samuel A. Falvo II :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Apr 21, 2009 at 2:14 PM, Friedrich Weber
<fred.reichbier@...> wrote:
> myObject setA(123) setB(456) setC(789)
>
> is the same as
>
> myObject a = 123
> myObject b = 456
> myObject c = 789
>
> but shorter :)

myObject do(
  a = 123
  b = 456
  c = 789
)

is shorter still.  ;)

--
Samuel A. Falvo II

Re: Io N00B - basic questions

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2009-04-21, at 2:21 PM, Samuel A. Falvo II wrote:

> On Tue, Apr 21, 2009 at 2:14 PM, Friedrich Weber
> <fred.reichbier@...> wrote:
>> myObject setA(123) setB(456) setC(789)
>
> myObject do(
>  a = 123
>  b = 456
>  c = 789
> )
>
> is shorter still.  ;)

In characters, the set style is 38 and the = style is 41.

BTW, it's considered good style in Io to always use setters outside of  
an object, and to use them preferentially within an object.


Re: Io N00B - basic questions

by Windoze :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Apr 21, 2009 at 2:53 PM, Steve Dekorte <steve@...> wrote:

> In characters, the set style is 38 and the = style is 41.

Steve, you lost me on that --- are you referring to an Io internal dispatch
table index?

thanks, btw, for this wonderful language!

- Howard in Florida

Re: Io N00B - basic questions

by Guy Hulbert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-21-04 at 15:30 -0700, HowardP wrote:
> > In characters, the set style is 38 and the = style is 41.   Steve,
> you lost me on that --- are you referring to an Io internal dispatch
> table index?

That was my initial reaction but he's just counting characters.

--
--gh



Re: Io N00B - basic questions

by spir :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Le Tue, 21 Apr 2009 16:59:55 -0400,
Jeremy Tregunna <jeremy.tregunna@...> s'exprima ainsi:

>
> I'm not sure what you're trying to get at Denis. Can you elaborate?
>
> On 21-Apr-09, at 4:33 PM, spir wrote:
>
> > Le Tue, 21 Apr 2009 10:47:12 -0700,
> > HowardP <how2paut@...> s'exprima ainsi:
> >
> >> Thanks Jeremy - yes this is helpful.
> >>
> >>> Consider:
> >>> foo ::= 42
> >>> Creates a slot called "foo" with the value 42, and creates a  
> >>> "setFoo"
> >> which takes a single argument, the value to update the "foo" slot  
> >> with.
> >>
> >> Then is a 'setWhatever' like a property encapsulation?  In other  
> >> words, if I
> >> use the " *::= *" operator/message, I *must* then use it for  
> >> subsequent
> >> access to the 'foo' (or 'Whatever') slot?  Or is " ::= " just  
> >> allowing
> >> access to more of what goes on under the hood, that is " *:= "  
> >> hides* the
> >> setWhatever, whereas "::=" bubbles it up so to speak?
> >>
> >> If I'm not totally off here, does that then mean then I'd have to use
> >>
> >> setFoo := 99   to get foo to be 99 - and that
> >>
> >> foo:=99  would be something else / or raise an exception?
> >>
> >> ( I'll test this of course, but thought it would be good to post  
> >> the info
> >> anyway, as several of my programming pals are also fuzzy on this  
> >> too. )
> >
> > Io> x := Object clone
> > ==>  Object_0x9d7df60:
> >
> > Io> x a ::= 1
> > ==> 1
> > Io> x
> > ==>  Object_0x9d7df60:
> >  a                = 1
> >  setA             = method(...)
> >
> > Io> x setA(2)
> > ==>  Object_0x9d7df60:
> >  a                = 2
> >  setA             = method(...)
> >
> > Io> x a = 3
> > ==> 3
> > Io> x
> > ==>  Object_0x9d7df60:
> >  a                = 3
> >  setA             = method(...)
> >
> > Io> x a := 4
> > ==> 4
> > Io> x
> > ==>  Object_0x9d7df60:
> >  a                = 4
> >  setA             = method(...)
> >
> >
> > While I wouldn't guess about the intention of Io developpers, I  
> > personly consider '::=' as a nicety that also sets a setter.

Here I mean: "::=" creates a setter, but does not force its use: as shown by the example, you can still write '=' or even ':=' for the same slot (name).

> > set* does not build a kind of property.

First, because of the above (property is usually encapsulation).

Note:
> >
> > Io> x m ::= method("m running")
> > ==> m running
> > Io> x
> > ==>  Object_0x9d7df60:
> >  a                = 4
> >  m                = method(...)
> >  setA             = method(...)
> >  setM             = method(...)

Here, '::=' creates a setter for a method slot. Which is indeed just a slot for Io. Properties are usually (AFAIK) meant for controlling access to data instead.
Hem, actually this may be a wrong interpretation of mine. Even when called (as opposed to read or written like any other slot) methods need first be looked up. So that encapsulation through getter/setter may well apply to them like to pure data slots.
Critics welcome ;-)

Denis
>
> Regards,
>
> Jeremy Tregunna
> jeremy.tregunna@...



------
la vita e estrany

Re: Io N00B - basic questions

by Windoze :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> you lost me on that --- are you referring to an Io internal dispatch
>> table index?
>
> That was my initial reaction but he's just counting characters.
>
> --gh

Oh now, that is funny - I was expecting some complicated thing...
When the answer was in fact something like "42" <g>

> Even when called (as opposed to read or written like any other slot)
methods
> need first be looked up. So that encapsulation through getter/setter may
well
> apply to them like to pure data slots. Critics welcome ;-)
> Denis

Well, we all learn to code from examples. Maybe a couple more short snippets
would help --- I still don't get it (OK, maybe I'm dense... haha)

thanks - interesting thread.

Re: Io N00B - basic questions

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 2009-04-21, at 3:30 PM, HowardP wrote:
> On Tue, Apr 21, 2009 at 2:53 PM, Steve Dekorte <steve@...>  
> wrote:
> > In characters, the set style is 38 and the = style is 41.
>
> Steve, you lost me on that --- are you referring to an Io internal  
> dispatch table index?

Just the number of characters in each solution - sorry for the  
confusion.

>  thanks, btw, for this wonderful language!

You're welcome and welcome to the Io community :-)

- Steve