Hi,
Yes this is very do-able. Here's a basic Genyris version:
> df sys:procedure-missing(&rest args)
: for line in (left (apply os!exec args))
: u:format "%a\n" line
:
<LazyProcedure: <anonymous lambdaq>> # LazyProcedure
Which lets us do this :
> ls -l /
:
total 180
drwxr-xr-x 4 root root 4096 2012-05-10 11:51 bin
drwxr-xr-x 5 root root 4096 2012-08-17 02:40 boot
drwxr-xr-x 2 root root 4096 2011-01-17 02:06 cdrom
drwx------ 2 root root 4096 2011-02-12 20:57 Desktop
drwxr-xr-x 16 root root 4580 2013-05-25 17:52 dev
How does this even work? Lets break it down:
Genyris interpreter has a hook called sys:procedure-missing which is called
if a function unbound. Similar to Ruby's method_missing. So we define our
own sys:procedure-missing which passes the args to a call to the operating
system. Because we've defined the function as a 'df' the arguments are not
evaluated (ie all quoted). The os!exec function returns the stdout from the
command as a list which is then printed.
We could add evaluation of arguments with , (comma) ,@ (comma-at) which are
standard Lisp syntax.
Not sure if Scheme has a method_missing equivalent. A serious shell would
comprise its own REPL - the above is just a bit of a hack.
Cheers,
Bill
On 24 May 2013 02:15, Ben Booth <benwbo...@gmail.com> wrote:
> I read on the guile user mailing list that version 0.2 of scsh for guile
> has been released. This got me thinking what a real lisp-powered
> interactive shell would need in order to be useful:
>
>
> 1. A modified version of sweet-expressions, where barewords are treated as
> string literals instead of symbols. Bareword string literals could be used
> along with normal quoted string literals
>
> 2. Some way to designate what is a symbol. Bash uses $var or "$var" for
> variable substitution. A scheme shell could use , and ,@ (the unquote and
> unquote-splicing operators) for this purpose. The REPL would then need to
> convert barewords to strings, and then quasiquote the parsed S-expr before
> evaluating it
>
> 3. If a bareword or a string literal is at the head of a list, it should
> automatically be interpreted as a function name
>
> 4. If a function is called that does not exist in the current scope, the
> *runtime* needs to call a dispatch function to search for a command in
> $PATH that matches the function name and execute it. Any arguments would be
> coerced into strings, and the command would return either an exit code, or
> stdout/stderr filehandles, or maybe both. If no matching command is found
> in $PATH, throw an exception. This kind of runtime missing method dispatch
> can be done in perl and ruby, but I'm not sure about guile
>
> 5. Requiring the user to hit enter twice after each command is too onerous
> for an interactive shell. One-line commands could be typed without any
> indentation, and thus only require hitting enter once. Multi-line commands
> would then require indentation, and pressing enter twice to execute the
> command. By distinguishing between one-line commands and multi-line
> commmands, you can easily enter one-line commands quickly, but still use
> multi-line commands when necessary
>
> 6. It would be great if such a "sweet shell" (swsh) could be packaged in a
> repository for easy access. Does anyone know the current status of the
> guildhall?
>
> I'm not sure how much work it would take to tweak sweet-expressions to do
> this, but it would make for a killer app. I've always wanted an interactive
> shell that could use macros, and guile seems like the perfect fit.
>
> Ben
>
> On Aug 6, 2012, at 10:44 AM, Ben Booth <benwbo...@gmail.com> wrote:
>
> > Transitioning it to guile would be easy for us, though not really
> necessary. The guile folks might like it, though.
> >
> > One nice benefit of porting scsh to guile is that guile is already
> installed on most linux systems. It would also be nice to have native
> 64-bit support, although I think the reason it's 32-bit-only has to do with
> its system call api bindings.
> >
>
>
>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
> _______________________________________________
> Readable-discuss mailing list
> Readable-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/readable-discuss
>
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss