Title: Standard IO in VW Smalltalk

by Thomas Gagné


Download the parcel in one of two formats!
EfiStdIO-1.4.3.zip
EfiStdIO-1.4.3.tgz

One of the most frustrating things learning Smalltalk for me was the absence of C's main(), indicating where the program started executing, and the end of that same function indicating the end of the program.

Even after learning Smalltalk I remained frustrated I couldn't create application I could execute from the command line that took advantage of UNIX's standard IO channels, known in C as the file pointers (FILE *) stdin, stdout, and stderr.

EfiStdIO is a parcel that creates the environment I was looking for, and provides parts of it for Windows users. It does a couple of things:

As helpful as that class was on its own it still didn't give me the main() I was looking for. That's what the class EfiMain is for.

Ignoring the mechanisms behind it, EfiMain's instance method, main:, gave me what I was looking for. An entry point into a program that provided the command line arguments as a vector. Now I had both my argc (argv size) and my argv. Simply put, I could now create the famous "Hello, world!" program quite simply:

main: argv
    self stdout nextPutAll: 'Hello, world!'; cr
EfiMain's contributions to making my life easy:


Updates

Date Comments
10/24/2002
  • One of the classes in the parcel is EfiInteractive, which when sent "#saveHeadless" creates an executable image called vwst.im, which is an interactive Smalltalk interpreter that accepts Smalltalk code from standard input. The code is buffered until a "!!" is entered on a line of its own--then the code is executed.

    Command line prompts and the welcome message can be turned off with a '-s' switch, and an alternate input file (ending with !!) can be specified with '-i filename'.

    Though that functionality existed in previous releases it had a bug in it. I wasn't copying EOL characters from the input stream to the buffered stream which sometimes caused syntax errors. That's been fixed and the new parcel has been updated.

  • If you prefer, you can download the .pcl and .pst files separately instead of both files in a single .tgz. .tgz

  • The Headless parcel must be loaded before loading the command line parcel.

February, 2003
  • I've learned how to create parcels!
  • Added Error subclass EfiMainError
  • Added #exit: for abnormal exits
April, 2003 Actually, I've made several improvements to the parcel because I use it all the time so it keeps getting better. Anway, I've learned better how to parcel it up. If you want the latest and greatest, let me know via email using tgagne at wideopenwest dot com.
June, 2004 1.4 is an interim release. What I really need to do is add this new servelet thing I'm using so programs stdio programs created as subclasses of EfiMain can be run as servlets inside VisualWave. Very cool. Very useful. I probably need to put it into a separate parcel with a dependency on WebToolkit. Stay tuned.

We have added (in the 1.4.2 version) a new class called EfiSubProcess which contains class methods for spawning subprocesses and returning the output as either a ByteString or ByteArray. This is used by the GNUPlot classes.
July, 2004 Well, I haven't finished the EfiServlet thing yet, but I have added a new feature to the #compile: and #compile:toClass: methods that makes it easier to create methods with embedded quotes inside them. For instance, if you want to create a method that uses literal strings. Since the argument to #compile: needs to be a string itself, use backquotes (`) instead of forward quotes ('). Life is so much simpler now.

You can find this feature in the latest 1.4.3 links at the top of this page.

Copyright © 2002, Thomas Gagné