Re: Io chokes on sample code
gatesphere <[email protected]> Sun, 26 Feb 2012 02:31:18 -0500
| Newsgroups | gmane.comp.lang.io |
|---|---|
| Message-ID | <[email protected]> |
That code would work perfectly in a script. However, in the REPL, you
need to put semicolons between statements sometimes. Within parentheses
is one of those times. So, corrected code in the REPL is as follows:
Io> Account := Object clone do(
... balance := 0.0;
... deposit := method(v, balance = balance + v);
... withdraw := method(v, balance = balance - v);
... show := method(writeln("Account balance: $", balance))
... )
-->Jake
On 2/26/2012 12:13 AM, Duke Normandin wrote:
>
>
> io
> Io 20110905
> Io> Account := Object clone do(
> ... balance := 0.0
> ... deposit := method(v, balance = balance + v)
> ... withdraw := method(v, balance = balance - v)
> ... show := method(writeln("Account balance: $", balance))
> ... )
> ==> Account_0x866af20:
> balance = method(...)
> type = "Account"
>
> Io> myAccount := Account clone
> ==> Account_0x867a010:
>
> Io> myAccount show
>
> Exception: Account does not respond to 'show'
> ---------
> Account show Command Line 1
>
> Why the error?
>
> Does it have something to do with the do( ) construct?
>
> The example I use is from:
> http://www.iolanguage.com/about/samplecode/
>
>