alinsoar
alinsoar

Reputation: 15803

mit-scheme -- run a script and exit

I want to evaluate a script from makefile and exit, like this

mit-scheme --load "fact.scm"

However, after it evaluates the file, it does not exit, and the repl appears; if I try the (exit) primitive, it asks for confirmation y/n. Is it possible to solve this ?

Upvotes: 10

Views: 3876

Answers (4)

Mark Reed
Mark Reed

Reputation: 95315

This works; at least under 11.2, I don't get any confirmation prompt on the (exit):

scheme --quiet --load filename --eval '(exit)'

I have this handy-dandy shell function that provides a pseudo-pythonic invocation experience: with no args it drops me into the REPL, but if there is an argument, the first one is taken as a script name and any subsequent args turn into (command-line-arguments). This is the definition; as written it works in bash, ksh, or zsh:

function scm {
  if (( $# )); then
    typeset prog=$1
    shift
    scheme --quiet --load "$prog" --eval '(exit)' -- "$@"
  else
    scheme
  fi
 }

Upvotes: 4

Ben
Ben

Reputation: 6348

You can add the --quiet argument to the mit-scheme command to suppress the default output. This is otherwise a crib of Charlie Forthmount's function (though it only loads one file):

run-mit-scheme () 
{ 
    echo | mit-scheme --quiet --load $1;
    # Add an extra newline
    echo
}

Upvotes: 2

Charlie Forthmount
Charlie Forthmount

Reputation: 89

Just let our command close stdin of the mit-scheme process automatically, e.g.

echo | mit-scheme --load sample.scm

We can expand it to a script function; here's my unskilled implementation:

function mschm () {
   IFS=""
   for arg in $@
       do
           echo | mit-scheme --load $arg
       done
}

Upvotes: 8

usr1234567
usr1234567

Reputation: 23394

For Unix mit-scheme reads the input files via redirection:

mit-scheme < /usr/cph/foo.in > /usr/cph/foo.out 2>&1 &

This is taken from the documentation http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-user/Command_002dLine-Options.html#Command_002dLine-Options

Upvotes: 5

Related Questions