[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How could this be implemented?

From: Jon Wilson
Subject: How could this be implemented?
Date: Sun, 14 Jan 2007 16:50:07 -0600
User-agent: Thunderbird (X11/20070103)

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?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]