0

I have a file called test.scm that looks like:

(display 5)

and when I go like this

cat test.scm | scheme

or like this

scheme < test.scm

or like this

cat test.scm | scheme > output.txt

I get

MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2011 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Sunday February 7, 2016 at 10:35:34 AM
  Release 9.1.1     || Microcode 15.3 || Runtime 15.7 || SF 4.41
  LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> 5
;Unspecified return value

1 ]=> 
End of input stream reached.
Moriturus te saluto.

What do I have to do to get the following?

5
Alex028502
  • 3,486
  • 2
  • 23
  • 50
  • Possible duplicate of [How do I execute a .scm script (outside of the REPL) with MIT-Scheme?](https://stackoverflow.com/questions/903968/how-do-i-execute-a-scm-script-outside-of-the-repl-with-mit-scheme) – Flux Dec 09 '17 at 03:15

1 Answers1

1

Tricky question. I have tried a little but I have problems getting it to behave like other Scheme implementations I currently use. If you are ok with the verbose output you can just do:

scheme --load "file.scm"

Now. I usually use plt-r5rs and plt-r6rs to just run stuff and raco exe to make an executable for my machine:

plt-r5rs r5rs-program.scm # interpreted r5rs
plt-r6rs r6rs-program.scm # interpreted r6rs
raco exe any-scheme-program.scm
./any-scheme-program # faster executable

I also use ikarus sometimes since its sometimes faster than compiled racket:

ikarus --r6rs-script r6rs-program.scm # jit compiled r6rs

In your question you are trying to use shell pipe and redirection. These redirect stdio/stdout/stderr from to file or pipe to another program and not scheme source code to be run. This works with both racket and ikarus:

cat file1 file2 | ikarus --r6rs-script r6rs-echo.scm | wc -l 
plt-r6rs r6rs-echo.scm < file | wc -l 
plt-r5rs wcl.scm < file > file-count.txt

Note that there are lots of other scheme implementations conforming to R5RS, R6RS and even R7RS that does this as well. It's been a while since I used mit-scheme and it certainly will be a good while before I start it again with so many other options.

Sylwester
  • 47,942
  • 4
  • 47
  • 79