I am trying to use smalltalk with smalltalk/x-jv branch. I have following simple code:
Object subclass: Myclass[
|mainval|
init [mainval := 555]
getmainval [^mainval]
]
gc := Myclass new.
gc init.
gc getmainval printNl.
I am trying to run it on command line with stc
command of smalltalk/x-jv, but it it not working. Following is the error:
$ ./stc testsrc.st
testsrc.st, line 1: Error: syntax error in 'class definition' near "Myclass" (char/token=286 / 0x11e) (fileIn expression)
Where is the problem and how can it be solved? Thanks for your help.
Edit - Adding information about
stc
andstx
I'm afraid you can't use the GNU Smalltalk code directly within Smalltalk/X(-jv branch). Also it would be nice to see what is your final goal during the Smalltalk question series.
What is important for you to understand that Smalltalk has been designed to work within the IDE if you want to build an application you should use the IDE provided. If you want to build a sample application there is even guide for that for Smalltalk/X. That, of course, do not mean you are unable to start a script from command line (Smalltalk/X is powerfull at shell).
That being said there is a Smalltalk/X highlighting package file for Sublime Text 3 done by myself hosted at BitBucket. I have created it mainly for Smalltalk and its embedded C highlighting.
First you are probably using
stx
executable and notstc
.stc
is a shorcut forsmalltalk-to-C
compiler.stc
produces a C code which can then be compiled by a C compiler into an object file which then can be linked with a final executable (together with other smalltalk classes and runtime).smalltalk
orstx
is a launcher that can execute smalltalk scripts or open a full-blown IDE. If you're familiar with Java, think ofstc
as ofjavac
andsmalltalk
orstx
as ofjava
.You can use the launcher provided called
smalltalk
(a bash script for *nix and batch/powershell for windows), which is using thestx.com
at the end, but providing some additional functionality.Use
smalltalk --help
the see the commandline options.First I will start with a simple one-liner which you can use:
on windows you if you use
smalltalk
you get more information:Now lets move to your scripting question
At the beginning the best way is to create the class in IDE and do a fileOut of it. You will then see the correct structure the
.st
file should have.I have create a simple file
script.st
for you (this is simlilar what you would get on a fileOut from IDE):How do you run such a sript?
The output will be:
555
If you want to script without "objects" (well everything is object in Smalltalk, but you don't define a class here) you can do simple
transcript.st
:again execute it as:
smalltalk --execute transcript.st
to get identical result.