Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling 'hello, world' GNU smalltalk

Whenever I set out to learn a language the first thing I do is produce an executable file written in that language (it could be a compiled program or a script) that when run prints 'hello, world' and a newline to stdout:

theironknuckle@beastbook:~/Code$ ./hello
hello, world

After about an hour of mucking around with GNU Smalltalk, I haven't found out how to do this.

(I know that the hello world program can be expressed from within a session as

'hello, world' printNl

This doesn't meet my stdout requirements)

I understand that there's no mainline in Smalltalk. So I'm quite intrigued by what sort of boilerplate could possibly be necessary to make it happen. Again, the file doesn't necessarily have to be compiled, but the end result of the exercise has to be smalltalk code that results in the above session extract.

PS. yesyesyes I know that I'm doing it wrong by not embracing the "image based programming" philosophy. I don't care. I'm not against learning how to work with the image and IDE and all that, but I really have minimal interest right now. What I care about is the Smalltalk language itself. Syntactically, philosophically and typographically it is rather beautiful. I feel comfortable learning programming languages from a commandline interpreter and a text editor. :)

like image 599
TheIronKnuckle Avatar asked Jun 15 '13 02:06

TheIronKnuckle


1 Answers

In GNU Smalltalk, there's pretty much no boilerplate. You could just put your single line in a .st file, and run it with gst hello.st

If you want to explore using a class instead of directly executed statements, then that's easy too, the following in a file passed to gst will do the trick:

Object subclass: Hello [
    greet [
            'Hello, World' displayNl
    ]
].
greeting := Hello new.
greeting greet.

Files passed to gst on the command line are parsed and executed in sequence, so you could split the above listing into two separate files - one to declare / compile the class, and the second to actually run it.

Once you've developed your program, you can use the -S flag to gst to snapshot the image after loading your classes, so that you don't have the compilation overhead each time, and can just run your startup statement instead.

gst also has shebang support, so you can put #! /usr/bin/gst -f at the top of your file if you don't want to pass it to gst manually. (See the documentation on invocation for more, including how to do it without hardcoding the location of gst)

like image 119
Stuart Herring Avatar answered Oct 28 '22 01:10

Stuart Herring