On Dec 7, 2013, at 10:54 PM, Fuchs Ira ihf@bit.net wrote:
Should it be possible (under OSX) to type:
echo (expt 2 10) | gsi and get the result 1024? I thought I read that this works in Unix but it does not work in OSX where it simply starts the interpreter and prompts for input.
It shouldn't work on either Unix or OS X. Gambit interacts with the user on the "controlling tty" (typically /dev/tty). This is not the same as the standard input. You can force Gambit to use the standard input (and output) using the -:d- runtime option. So you will get what you want with
% echo "(expt 2 10)" | gsi -:d-
But that also sends the REPL prompt and other garbage to the standard output. So it is better to use
% gsi -:d- -e "(pp (expt 2 10))"
or
% gsi -e "(pretty-print (expt 2 10))"
Now you may wonder why Gambit uses the controlling tty to run the REPL. The reason is that it allows using the REPL to debug programs which read from the standard input and write output to standard output (because the REPL I/O is done on a different port than the program's I/O). For example
% echo "10 20 99" | gsi -:dar -e "(pretty-print (+ (read) (red)))" *** ERROR IN (string)@1.26 -- Unbound variable: red
,(c read)
30
Here the program has an error (using red instead of read), and the debugging at the REPL asks the execution to continue with the value of the read variable instead of the red variable. The "30" is printed to standard output, so you could also have done:
% echo "10 20 99" | gsi -:dar -e "(pretty-print (+ (read) (red)))" > out *** ERROR IN (string)@1.26 -- Unbound variable: red
,(c read)
% cat out 30
Finally, you could also do
% echo "(expt 2 10)" | gsi -:d- -e "(pretty-print (eval (read)))"
If you must read the program from stdin.
Marc