Re: Lush as a shell

Yann LeCun <[email protected]> Sun, 12 Feb 2006 12:21:18 -0500
Newsgroups gmane.lisp.lush.devel
Organization Courant Institute, NYU
Message-ID <[email protected]>
You can easily write (in Lush) a new read-eval-print loop that doesn't
require parentheses and double quotes, so that you could type:

  cd /usr/local

instead of:

  (cd "usr/local")

People tend to dislike having to type extra character at the shell
prompt. So I don't think you can ask them to type #$ in front of every
command or (cmd "args") around every command at the prompt.

On the other hand, people don't mind (too much) typing extra stuff
when they are programming, because it improves readability and
maintainability. 

So, writing stuff on the command line might require a new, more
compact syntax. But writing scripts can be done with the usual Lush
REPL syntax.  What we need is more functions and macros to support
that. The function "sh" and all the functions defined in
libc/shell.lsh are helpful, but probably not sufficient.

The sh function returns a list of strings, each of which contains
one line of the standard output of the command being called.
For example:

 ? (cd "/usr/include/ncurses")
 = "/usr/include/ncurses"
 ? (ls)
 = ("curses.h" "cursesapp.h" "cursesf.h" "cursesm.h" "cursesp.h" "cursesw.h" 
"cursslk.h" "eti.h" "etip.h" "form.h" "menu.h" "ncurses.h" "ncurses_dll.h" 
"panel.h" "term.h" "termcap.h" "unctrl.h")

sh can take an optional argument which must be a list of strings.
That list of strings will be piped (as lines of a file) to the
standard input of the command called by sh:

 ? (sh "sort -r" (sh "grep -v curs" (ls)))
 = ("unctrl.h" "term.h" "termcap.h" "panel.h" "menu.h" "form.h" "etip.h" 
"eti.h")

The advantage over regular shell scripts is that you can 
manipulate those lists of strings with any Lush function.

The disadvantage is that those lists of strings are held in RAM.
However, with the amount of RAM and virtual memory available in
today's computers, few people care about this anyomore.

  -- Yann


On Sunday 12 February 2006 10:16 am, Raymond Martin wrote:
> Hi Yann,
>
> > [snip]
> > Turning Lush into an actual command line shell would not be
> > very complicated.
>
> The current meaning of Lush can still apply in the long run if its use is
> more synonymous with normal shells, something I would really like to see
> happen.
>
> Look at what the tclsh (Tcl shell) does, lets commands fall through to the
> underlying shell when it does not understand them. That's interesting, but
> I don't think it would play well with the Lush REPL. It's not absolutely
> necessary, although I believe it would make Lush more appealing to
> system/network administrator types.
>
> Lush already has a number of commands for working like a shell or with the
> filesystem, but currently there is a naming conflict with a few UNIX
> utilities (e.g. df, set, ?) and commands require a string for parameter
> passing. There is the #$<shellcmd>, but it doesn't work for me right now
> (?).
>
> I haven't look at it for a while, but I did manage to get around the string
> for parameter passing. I made an RPM command which I can invoke, for
> example, as
>
> ? (rpm -qi <rpm-package>)
>
> That works, but I did not take it too far.
>
> Being able to invoke shell commands like that or in the same way with #$
> (e.g. #$ rpm -qi <rpm-package>) goes some way to making shell programming
> easier and less encumbered in Lush. Perhaps a particular namespace,
> package, or operational mode is useful in this situation.
>
> Raymond
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Lush-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/lush-devel



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642