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

5 Comments:

Anonymous Anonymous said...

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

30 May, 2006 08:22  
Blogger Arto Bendiken said...

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.

30 May, 2006 11:41  
Blogger orbitz said...

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...

30 May, 2006 13:06  
Anonymous hyperstruct said...

I did something in Emacs Lisp. It allows mixing Lisp and simple shell stuff like:

(message (format "echo returned %d" ($ echo "hello, shell!")))

And it moves a tiny step toward files as data objects, using "cd" to enter not only directories but also text files:

($ cd /etc/passwd)
($ chunk 0)
"root:x:0:0:root:/root:/bin/bash"
($ chunk "sys")
"sys:x:3:3:sys:/dev:/bin/sh"

No, it's not useable as an everyday shell, it's little more than a toy, though one I'd really like to spend some time on.

(Why not Common Lisp? Only because you want all the help you can get to cut down on typing parentheses or you'll soon miss bash, and I felt more like getting it from Emacs than looking into the terminal handling code of some Common Lisp implementation.)

21 June, 2006 11:59  
Blogger Partdavid said...

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.

07 March, 2008 14:34  

Post a Comment

<< Home