[gambit-list] How pipe from shell to gsc ('s repl)?

Marc Feeley feeley at iro.umontreal.ca
Wed Jul 13 09:23:44 EDT 2016


On Unix, Gambit’s REPL interacts with the user using the “controlling terminal”.  If you redirect stdin by using a Unix pipe, then the REPL and (current-input-port) will not refer to the same input port.  This makes it possible to use the REPL to debug programs which read the standard input and write to the standard output, even when these have been redirected, for example:

% cat myprog.scm
;; File: "myprog.scm"

(let* ((x (read))
      (y (read)))
 (step)
 (pretty-print (+ x y))
 (pretty-print (read)))
% echo "11 22 999" | gsi myprog.scm
*** STOPPED IN "myprog.scm"@6.4
> ,e
y = 22
x = 11
> ,c
33
999

The -:d- runtime option, which runs the REPL interaction on stdin/stdout, can be used for situations where REPL commands need to be read from stdin.  Here are a few examples:

% echo "(pp (read)) hello-world (pp (+ 11 22))" | gsi -:d-
Gambit v4.8.5

> hello-world
> 33
> 
*** EOF again to exit
% echo "(pp (read)) hello-world (pp (+ 11 22))" | gsi -:d- -
> hello-world
> 33
> 
*** EOF again to exit
% echo "(pp (read)) hello-world (pp (+ 11 22))" | gsi -:d- - > out
% cat out
> hello-world
> 33
> 
*** EOF again to exit

Note that with the -:d- runtime option, the REPL’s output channel is stdout, so you can redirect the output to a file.  Also note the “-” command line argument to gsi which is used here to avoid the Gambit REPL banner.

On Windows, there is a similar concept called the “console”.  So Gambit interacts using the console, which is different from stdin/stdout.

Marc

> On Jul 13, 2016, at 1:47 AM, Adam <adam.mlmb at gmail.com> wrote:
> 
> I understand that Gambit has slightly special stdin/stdout IO routines because of its async design.
> 
> However I guess that not is a reason for it to be so quirky that it would break Unix piping behavior.
> 
> Also Unix piping is a totally reasonable usecase.
> 
> Piping the *output* seems to work better though, this works on at least two unices: gsc -e '(display "Hello world\n")' > myfile (In the past I saw some weird output-related behavior, that CTRL+Z not really suspended a process on Linux and the Gambit process would keep running and outputting as usual, but I believe it was fixed at some point.)
> 
> Now back to stdin piping:
> 
> Can Gambit be made to conform without additional arguments, or are arguments or hacks needed, what's the big picture, challenges and needs here, how fix?
> 
> 




More information about the Gambit-list mailing list