In the REPL, (display (+ (read) 1))
works as expected.
When (display (+ (read) 1))
is placed in a source file, and the file is run as a script using mit-scheme --quiet < program.scm
(reference), mit-scheme never asks for user input and the program just terminates. Why?
To see the reason, place this in the source file instead:
(define n (read))
2
(display (+ n 1))
You get 3
, as expected.
This is all caused by the shell input redirection (i.e. <
). read
gets its input from the current input port by default. With shell input redirection, the current input port is the source file. Hence, (read)
does not prompt for user input because stdin is the source file.
To the best of my knowledge, there is currently no easy way to correctly run an MIT Scheme script directly from the command line (surprise! surprise! MIT Scheme is antiquated). Relevant mailing list discussion: [MIT-Scheme-devel] How to run a script and exit?.