lab 48 - symbol

NAME

lab 48 - symbol

NOTES

I'm clearing out the backlog and found this lab's code, which is really a continuation of earlier labs on the lispy-shell (26, 27, 28). I felt that where I was going with lab 28 wasn't working out, or was just going to end up looking like scsh (if I was lucky, and as smart as Olin Shivers).

This attempt is more a mathematica-like-shell, and for a while was looking better, in that it fit in better with the existing sh, but now I've decided against it too. I'm posting it here just to record what I've done. I'll try and explain at the end why I don't like this approach anymore.

In Mathematica everthing is an expression of the form

f[x,y]

which translates quite easily into the shell expression

f x y

Because of Inferno sh's command blocks, we can directly support the nesting in expressions:

% Head {f x y}
f
% Head {f;x;y}
List
# a sequence of commands {f;x;y} is 
# represented as {List f x y} in "FullForm"

And so, because of command blocks and this simple represenation of expressions, any arbitrarily complex structure can be represented in sh syntax and a sh module that implemented the core set of Mathematica commands could be used to symbolically manipulate that data.

Here are a few more to give you an idea.

% Length {a;b;c;d;e;f;g}
7
% Rest {a;b;c;d}
{b;c;d}
% Apply f {a;b;c;d}
{f a b c d}
% Map f {a;b;c;d}
{f a; f b; f c; f d}
% Nest f a 3
{f {f {f a}}}

Another crucial idea of Mathematica is its peculiar "infinite evaluation" system; it keeps evaluating an expression until it no longer changes. I implemented IEval builtin which takes the output of a command and evaluates it again until the output is the same as the input.

% IEval {Point 1 2 3}
{Point 1 2 3}

But I stopped short of implementing the evaluation system described in the Mathematica docs. It was at this point that I realized what I was doing was just a pipeline from sh to sh, and that maybe the commands should read standard input for symbolic data. And then maybe they should be programmable using regular expressions and accept an arbitrary text stream instead of specifically structured text based on sh syntax. And at that point I'm back with the UNIX philosophy of software tools.

So I arrived at the point where even though symbol would fit within sh it might not fit within Inferno. From this exercise I think I have a better appreciation of the existing set of Inferno software tools. It is not always obvious how they are applied to a problem. But sometimes one needs to take a long trip around the computer science field before one can understand their generality, and that a command block is just quoted text; and quoted text is just a text stream.

FILES

caerwyn.com/lab/48

Comments

Popular posts from this blog

lab 110 - inferno archive edition

lab 107 - midiplay

lab 111 - wavloop