A competition between scripting languages
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.




A competition between scripting languages.

This is still work in progress and is not finished yet.

Languages that qualify

Wikipedia defines a scripting language as "a programming language that supports scripts, programs written for a special run-time environment that can interpret (rather than compile) and automate the execution of tasks that could alternatively be executed one-by-one by a human operator." (Wikipedia - Scripting language)

For my purposes a scripting language is any language that has a program that can run code supplied on standard input. It means that it's all about the tools available and has nothing to do with the language itself.

Some examples:

2+2 Test

Here is a 2+2 test: Can I add 2+2 using a given language and make it print only the number 4 without any unnecessary output, and can I do it without having to change any state of the system? By changing the state of the system I mean writing anything to disk or installing any language packages that are not already installed by default. Ideally it should be possible to run the code provided on standard input, without any need to filter its output.

Why is it important for a language to pass the 2+2 test? Because then it can be used in shell scripts for some tasks that are hard, impossible or not efficient to do using only basic Unix tools. If a shell script can detect e.g. a Python runtime then it can use it for a specific task, with a fallback using the standard tools otherwise.

$ echo 'print 2+2' | perl -l

$ echo 'print 2+2' | ruby -l

$ echo 'print 2+2' | python

$ echo 'print(2+2)' | python3

$ echo 'print(2+2)' | lua

$ echo 'echo $((2+2))' | sh

$ echo '(prn (+ 2 2))' | clojure -

$ echo 'puts [expr 2+2]' | tclsh

$ echo 'console.log(2+2)' | node

$ echo 'main() { printf("%d\n", 2+2); }' | tcc -run -

Basically all of those are reasonably popular languages with easy to install binaries that can run programs piped through the standard input with no problems (like for example printing anything else than explicitly printed output) and no need to write any files on the file system.

An example of a failed test:

$ echo '(display (+ 2 2))' | guile
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.

There is a number 4 burried in there somewhere, but it clearly is meant to be run interactively and I see no easy way to make it print only 4.

I can use Guile to write just the number 4 using something like this:

$ t=`tempfile`; echo '(display (+ 2 2)) (newline)' > $t; guile --no-auto-compile $t; rm $t

but it is not as straightforward as with other languages and I have to write a file to the file system so I don't consider it a suitable runtime for the purpose of this experimrnts.

If any important language is missing here, please sumbit an issue.

System requirements

It will be written and tested on Ubuntu 14.04 but it should work on any standard Linux/Unix distribution. If it doesn't, please sumbit an issue.



Rafał Pocztarski - https://github.com/rsp


MIT License (Expat). See LICENSE.md for details.