Scripting Support
One of the things people have talked about a bunch recently is better support for scripting using Smalltalk. With that in mind, I'd like to point out a bit of work on helping to do that, in the suitably named package "Scripting Support" in the public Store. This includes a number of different things. It's fairly experimental - we want to see if this is what's actually needed/useful. So feedback is definitely appreciated. I note that the term "scripting" is somewhat vague. To clarify what we mean, this doesn't do anything to help you, say, write entire programs in files without having to use "chunk" or XML format. Rather it lets you control the environment from the command line better.
There are already some ways to run code from the command line in VisualWorks, e.g. -doit, -evaluate, but they don't entirely do what you want. So this adds the ability to just run a file from the command line, e.g.
vm scripting.im dostuff.st
or, if you have command line arguments, you can do them before the program, and put a -- option to indicate the program file. The program can also treat the rest of the line after it as arguments, which will show up in a variable named "arguments".There's also a "-e" option that just runs its (single-line) argument as a doit. You can have several of these. This is a lot like -doit, except that it (and providing a script file) will automatically quit the image after running, and the environment in which they run. (If you're curious, I just looked at what Ruby had for command-line arguments, because I had it installed on the laptop at th time)
All scripts are run in a ScriptRunner which lets them run in a workspace-like environment in which all namespaces are visible by default. Ambiguous names will resolve to using one of the names and continuing, rather than causing an exception. Undeclared variables will be declared in the script runner's namespace. And exceptions will dump a short stack and quit that particular script, but run other commands if there are any.There's also an interactive console, of sorts. So invoking the image with -i will give you a command-prompt, and you can type Smalltalk expressions to be run as scripts. You can even use \ to continue on to the next line. And to get out of it, you just type ObjectMemory quit. Note that one limitation of this that we have to fix is that while it's waiting for input at the prompt, the VM is blocked. This is a problem if you want to do complicated background processing, but is surprisingly not that noticeable for basic use. We think we have a fix for that, but it requires some validation.
The ScriptRunner also provides a couple of convenience methods
for use in scripts.
#include: runs the named script by filing it in
#use: parcelName makes sure that the parcel is loaded.
#print: prints its argument to the output of the script
(normally standard out)
Finally, this package adds & as a concatention operator. This is just playing around with possibilities, but a number of the collection operations in Smalltalk are quite awkward to type out in scripts. So this tries to do some of the collection building stuff in more of a Do What I Mean kind of way. So, e.g.
1 & 2 ==> #( 1 2)
#( 1 2 ) & 3 ==> #( 1 2 3)
and other interesting stuff.
Comments
Re: Scripting Support
[Vicky] September 28, 2012 23:13:36.808
I'm not denying the power of Windows Powershell or cmpnariog the relative merits of things like ksh, csh, bash etc versus Powershell. My point is about the general method of performing system administration. At the end of the day you're left with a bunch of scripts you have to execute even if this is through the .NET framework. Okay, I accept that Windows now has both GUI and Shell based admin, however can I SSH into a Windows box and run the Powershell scripts?
Re: Scripting Support
[Vicky] September 28, 2012 23:13:39.868
I'm not denying the power of Windows Powershell or cmpnariog the relative merits of things like ksh, csh, bash etc versus Powershell. My point is about the general method of performing system administration. At the end of the day you're left with a bunch of scripts you have to execute even if this is through the .NET framework. Okay, I accept that Windows now has both GUI and Shell based admin, however can I SSH into a Windows box and run the Powershell scripts?
Re: Scripting Support
[Vicky] September 28, 2012 23:13:44.449
I'm not denying the power of Windows Powershell or cmpnariog the relative merits of things like ksh, csh, bash etc versus Powershell. My point is about the general method of performing system administration. At the end of the day you're left with a bunch of scripts you have to execute even if this is through the .NET framework. Okay, I accept that Windows now has both GUI and Shell based admin, however can I SSH into a Windows box and run the Powershell scripts?