basic syntax questions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

basic syntax questions

LordGeoffrey
Hi
I am trying to get started with gnu-smalltalk, and i have a couple
trivial questions.
I can't find a sample st script that uses the [ ] delimiters rather than
the fileOut ! version.

The following code works. But if i move the definition of new into the
definition Account init is not called. Don't know why.
Also i do a snapshot at the end, is that the right approach?

The code>>
Object subclass: Account [
    | balance |
    hi [
        'hi i am ok' printNl
    ]
]
Account class extend [
    new [
        | r |
        <category: 'instance creation'>
        r := super new.
        r init.
        ^r
    ]
]
Account extend [
    init [
        <category: 'initialization'>
        balance := 0.
        'is initialized' printNl
    ]
    setBalance: newBalance [
        balance := newBalance
    ]
    getBalance [
        ^balance
    ]
]
ObjectMemory snapshot: 'account.im'




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: basic syntax questions

Paolo Bonzini-2
On Sat, Nov 14, 2009 at 03:24, LordGeoffrey
<[hidden email]> wrote:
> Hi
> I am trying to get started with gnu-smalltalk, and i have a couple trivial
> questions.
> I can't find a sample st script that uses the [ ] delimiters rather than the
> fileOut ! version.

Almost all of the code in the GNU Smalltalk tarballs use [ ] including the
tutorial.

> The following code works. But if i move the definition of new into the
> definition Account init is not called. Don't know why.

You need to declare new as

   Account class >> new [
     ...
   ]

if you move it into the definition of Account.

> Also i do a snapshot at the end, is that the right approach?

Yes, that's fine.  That's not necessary (you can load the code from
the command line every time -- later on you'd want to put it in a
package so it gets a .star file, maybe), but it's fine.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: basic syntax questions

Paolo Bonzini-2
On 11/16/2009 11:18 AM, LordGeoffrey wrote:
> How do access documentation or class information about the supplied
> packages, e.g. NCurses ?

Packages with good comments have documentation in info format.  For the
others, you can open them in VisualGST:

   gst-load NCurses
   gst-browser

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk