Tuesday, May 30, 2006

Shell

The other day, araujo suggested Erlang might make a good shell. Shell as in, bash. Hrm, I thought, maybe...
I don't think Erlang would be flexible enough to make a decent shell. Take something like this:


for i in *; do echo $i; done


What would the Erlang equivalent look like?


lists:map(fun(X) -> print([X]) end, ls())


I just don't see it? I should hope it doesn't look like that but I don't know. On the other hand, I seem to have it pretty set in my mind that Common Lisp would make an excellent shell language. A few people have told me that CL would probably be too verbose and not work out well but, I don't know, it just seems so succinct and powerful. You could make a lot of macros to make your life easier. I sent an email to the Lisp At Light Speed blog dude to get his opinion but I figured I'd post it here too to see if anyone has any thoughts.


What I have in mind is basically an interactive shell, using Common
Lisp as its programming language. For instance something like:

for i in *; do echo $i; done

Might look like:

(loop for i in (ls) do (print i))

The second thing I would love to see is Monad/Powershell. Rather
than using text to pass data around, uses lists/objects/etc. (ls)
for instance gives a list of file objects to iterate over, and you
can extract things like the size and permissions and what not.

This raises a question though. In order to do this, just about every
standard program becomes obsolete. For instance, why use 'cut' when
you can simply split a string with a CL function. However some
things would still be very useful, such as ls, or grep, but these
now need to communicate via objects rather than just text, so those
will have ot be rewritten. In which cause it seems like they could
simply be packages and loaded into the shell, meaning you don't
have to deal with program startup times or what not. Is this a lot
of work to rewrite all of these programs, and does it mean that we
cannot usefully use third party programs that people write? You
can always drop down to using strings as communication I suppose.

That is the basic idea. So far a few people have suggested that
sexprs really aren't any better for this sort of thing. sexpr's
won't be any better than say...bash. Someone suggested that Factor
might be a better language for this. But it seems to me, with
Common Lisps powerful macro system, you can easily make most
operations incredibly simple? The most useful aspect would be using
objects to communicate. But even if this is a lot of work to
accomplish, it seems to me that simply using CL as a shell programming
language seems like it would be nice. Am I wrong here? Am I missing
something?


If CL would make a poor langauge, what would make a good language? Riastrach has suggested Factor. I don't know enough about factor to say that but I think I like CL better for this.

All I know is:

This is not the answer

4 comments:

  1. CL doesn't make a poor language, the shell makes a poor code-editor.

    Just beef up the abilities of the prompt to edit code and you have a good shell.

    Oh wait. That's emacs. /noss

    ReplyDelete
  2. What you envisioned already exists, though not in Common Lisp but rather in Scheme, the other big Lisp dialect. Check out Scsh, the Scheme Shell. It's pretty cool.

    ReplyDelete
  3. Yes I know of scsh but from what I've heard scsh is poor/incomplete/buggy. Does scsh handle things in terms of objects as Monad/Powershell does? That is the more interesting of the things I would like to see accomplished. What column the pid# is in becomes rather irrelevant when you are simply looking at a member of some class/object.

    I will look at scsh some more but from what I saw i didn't particuarlly find it al that impressive...

    ReplyDelete
  4. I know this is a year and half old post, but I have fleshed out some ideas about using the Erlang shell as a general utility shell.

    ReplyDelete