unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How could this be implemented?
@ 2007-01-14 22:50 Jon Wilson
  2007-01-15  0:04 ` Per Bothner
  2007-01-15 10:13 ` Andy Wingo
  0 siblings, 2 replies; 11+ messages in thread
From: Jon Wilson @ 2007-01-14 22:50 UTC (permalink / raw)


Hi,
I've been toying with an odd little idea for a bit.  It would add a 
whole slew of symbols to guile's toplevel, but might well make it much 
more useful as a shell or as a system administration scripting 
language.  Suppose that we could run executable files found in the $PATH 
as if we were just calling a function?  So, to change our current 
working directory, we would just do:

(cd /)

Or, for instance, we might do:

(ls -a /home/fooguy/.gnome*)

The return value of such an expression would be a read-write port 
connected to stdin and stdout for the program running.  When eval found 
a symbol in the first spot of a list that it didn't know, it would 
convert the symbol to a string and search the $PATH just like, say, bash 
does.  If it found an executable there with a name matching the string, 
then it would execute that file.  The arguments would be handled thusly:

If the argument is a symbol, and it is bound to some value that we can 
see, then convert that value to a string and use the resulting string as 
the executable's argument.
If the argument is a symbol, but it is not bound to anything that we can 
see, then convert that symbol directly to a string and use for the 
executable.
If the argument is a list, try to execute that list as a function call, 
convert the result to a string, and use that.
If trying to execute the list results in executing another program from 
the $PATH, then pack up all the output (stdout) from the program into a 
string (or maybe tokenize it like the shell would... not sure here) and 
use that string.
If the argument is any other primitive data type, convert it to a string 
and use that.


I suppose it would make things easiest if we used the existing command 
interpreter (a la the system function, rather than the system* 
function).  Then we could just concatenate all the strings (with spaces 
in between) and pass them to (system all-our-strings) without worrying 
about how they should actually be broken up.

So, anyway, my primary question is: how could something like this be 
implemented?  It would involve a change, I suppose, to the evaluator.  
Could it be made as an extension to eval which is added when you load a 
module?  Perhaps more pertinent: Could it be written in guile scheme, or 
would it require messing with guile itself in C?  If it can't be written 
in guile scheme, should it be able to be written in guile scheme and how 
difficult would it be to add something like that (eval-extension) to 
guile?  Is this sort of thing what the evaluator-traps thingy is for?
Regards,
Jon


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-01-17  8:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-14 22:50 How could this be implemented? Jon Wilson
2007-01-15  0:04 ` Per Bothner
2007-01-15  1:37   ` Jon Wilson
2007-01-15  2:44     ` Jon Wilson
2007-01-15  2:50     ` Per Bothner
2007-01-15  3:34       ` Jon Wilson
     [not found]     ` <932b2f1f0701141859q4633322raf9b6370f7480396@mail.gmail.com>
2007-01-15  3:08       ` Jon Wilson
2007-01-15 19:31         ` Alan Bram
2007-01-15 10:13 ` Andy Wingo
2007-01-16 21:37   ` Jon Wilson
2007-01-17  8:30     ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).