If Hello World is inadequate, what canonical program would better serve to demonstrate the salient features of a programming language?
...
One suggestion (from David Pearce) was Conway’s Game of Life: a simple simulation of finite automata. This seems like a good demonstration of most of the properties.
http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/
I don't see a shell version, so below is mine (well...it is not strictly shell, as it uses sort, uniq, grep, sed, and comm). It's written as a filter that takes as input live cell coordinates (one cell per line, X and Y coordinates separated by white space), and outputs the live cells of the next generation.<p>For example, on this input:<p><pre><code> -10 100
-10 101
-10 102
1000 5
1001 5
1002 5
</code></pre>
the output is:<p><pre><code> -11 101
-9 101
1001 4
1001 6
-10 101
1001 5
</code></pre>
Here is the code, for bash or similar shells:<p><pre><code> > alive.$$
while read cells
do
echo $cells >> alive.$$
set x $cells
x=$2
y=$3
echo $x $((y-1))
echo $x $((y+1))
echo $((x-1)) $((y-1))
echo $((x-1)) $y
echo $((x-1)) $((y+1))
echo $((x+1)) $((y-1))
echo $((x+1)) $y
echo $((x+1)) $((y+1))
done | sort | uniq -c > neighbors.$$
grep '^ *3' < neighbors.$$ | sed -e 's/^ *[0-9].//'
grep '^ *2' < neighbors.$$ | sed -e 's/^ *[0-9].//' > has2.$$
sort alive.$$ -o alive.$$
comm -12 has2.$$ alive.$$
rm has2.$$ neighbors.$$ alive.$$</code></pre>
If Hello World is inadequate, what canonical program would better serve to demonstrate the salient features of a programming language?<p><pre><code> Must it use variables?
Must it have flow control?
Must it actually compute something?
Must it use non-primitive data structures?
Must it exhibit use of the language’s code organisation features?
</code></pre>
These are some of the more generic properties that programs can have.<p>...<p>One suggestion (from David Pearce) was Conway’s Game of Life: a simple simulation of finite automata. This seems like a good demonstration of most of the properties.<p><a href="http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/" rel="nofollow">http://ejrh.wordpress.com/2012/05/10/beyond-hello-world/</a>
Brainfuck? Erlang? Coldfusion? Visual Basic (6/.NET)? Those are just a couple right off the top of my head.<p>It is quite cool, though, to see a common problem solved in such a wide variety of languages.<p>s/all languages/lots of languages/g
The APL version is mindbendingly awesome: <a href="http://www.youtube.com/watch?v=a9xAKttWgP4" rel="nofollow">http://www.youtube.com/watch?v=a9xAKttWgP4</a> <-- watch it!