Marc,
How do I pipe commands into Gambit on "all" unices?
The "-e" argument is not universal so I may just want to pipe to Gambit's stdin.
The following just brings you a REPL with no input made to it, and you do the typing - does Gambit use some very exotic means of console input, or does it empty its read buffer at start?? If so why, and how do I make it simply use "stdin"?
cat << 'eof' | gsc
(display "Hello world\n") ,q
eof
Thanks
Afficher les réponses par date
This does not work too:
$ *cat << 'eof' | gsc /dev/stdin*
*(display "Hello world\n")* *,q*
*eof*
*** ERROR IN c#targ-start-dump -- Permission denied (#<procedure #2> "/dev/stdin.c")
2016-07-13 13:22 GMT+08:00 Adam adam.mlmb@gmail.com:
Marc,
How do I pipe commands into Gambit on "all" unices?
The "-e" argument is not universal so I may just want to pipe to Gambit's stdin.
The following just brings you a REPL with no input made to it, and you do the typing - does Gambit use some very exotic means of console input, or does it empty its read buffer at start?? If so why, and how do I make it simply use "stdin"?
cat << 'eof' | gsc
(display "Hello world\n") ,q
eof
Thanks
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?
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@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?
Ah, great!
Also the separation you mentioned is nice, that the REPL indeed is intended to operate in a separate "controlling channel". It's interesting that different platforms even have IO API:s for that, I had no idea.
So for what I was looking for, that I missed was this section in the manual, was:
-
The REPL interaction channel will be standard input and standard output.
And the way to figure out how to use it is..
gsc [-:runtimeoption,…]
And "-" is a "debugging" option, documented by
The ‘d’ option sets various debugging options. The letter ‘d’ is followed by a sequence of letters indicating suboptions.
so hence "-:d-", so:
$ *echo '(display "Hello world\n"),q' | gsc -:d-* Gambit v4.8.0
Hello world
$
Great!
Totally unimportantly, could I enable REPL echoing of the input commands, or turn off REPL output altogether, from the command line?
So
$ *echo '(display "Hello world\n"),q' | gsc -:d- [somemorearg]* Gambit v4.8.0
(display "Hello world\n")
Hello world
,q
$
and
$ *echo '(display "Hello world\n"),q' | gsc -:d- - [somemorearg]* Hello world $
I’m not sure what you mean when you say the “-e” command line option is not universal. It should work on all platforms, regardless of the OS.
Marc
On Jul 13, 2016, at 1:22 AM, Adam adam.mlmb@gmail.com wrote:
Marc,
How do I pipe commands into Gambit on "all" unices?
The "-e" argument is not universal so I may just want to pipe to Gambit's stdin.
The following just brings you a REPL with no input made to it, and you do the typing - does Gambit use some very exotic means of console input, or does it empty its read buffer at start?? If so why, and how do I make it simply use "stdin"?
cat << 'eof' | gsc
(display "Hello world\n") ,q
eof
Thanks
Ah, yes of course -e works universally; I meant universal in the sense pluripotent, panacea, here, that is, that there are instances when you want to launch gsc with code parameters, but they don't fit well into a command line argument, so it's not universal in the sense that -e can't receive code as parameters also via stdin. Only that.
2016-07-13 22:28 GMT+08:00 Marc Feeley feeley@iro.umontreal.ca:
I’m not sure what you mean when you say the “-e” command line option is not universal. It should work on all platforms, regardless of the OS.
Marc
On Jul 13, 2016, at 1:22 AM, Adam adam.mlmb@gmail.com wrote:
Marc,
How do I pipe commands into Gambit on "all" unices?
The "-e" argument is not universal so I may just want to pipe to
Gambit's stdin.
The following just brings you a REPL with no input made to it, and you
do the typing - does Gambit use some very exotic means of console input, or does it empty its read buffer at start?? If so why, and how do I make it simply use "stdin"?
cat << 'eof' | gsc
(display "Hello world\n") ,q
eof
Thanks
You mean they don’t fit well in terms of length? If I recall correctly you can have a quoted command line argument that spans multiple lines:
% car script.sh #! /bin/sh
gsc -e ' (define n 1000) (define (f x) (* x x)) (pp (f n)) (pp "hello") '
Marc
On Jul 13, 2016, at 10:44 AM, Adam adam.mlmb@gmail.com wrote:
Ah, yes of course -e works universally; I meant universal in the sense pluripotent, panacea, here, that is, that there are instances when you want to launch gsc with code parameters, but they don't fit well into a command line argument, so it's not universal in the sense that -e can't receive code as parameters also via stdin. Only that.
2016-07-13 22:28 GMT+08:00 Marc Feeley feeley@iro.umontreal.ca: I’m not sure what you mean when you say the “-e” command line option is not universal. It should work on all platforms, regardless of the OS.
Marc
On Jul 13, 2016, at 1:22 AM, Adam adam.mlmb@gmail.com wrote:
Marc,
How do I pipe commands into Gambit on "all" unices?
The "-e" argument is not universal so I may just want to pipe to Gambit's stdin.
The following just brings you a REPL with no input made to it, and you do the typing - does Gambit use some very exotic means of console input, or does it empty its read buffer at start?? If so why, and how do I make it simply use "stdin"?
cat << 'eof' | gsc
(display "Hello world\n") ,q
eof
Thanks