mit-scheme -- run a script and exit
Asked Answered
P

4

9

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 ?

Peper answered 13/7, 2014 at 6:23 Comment(1)
Possible duplicate of How do I execute a .scm script (outside of the REPL) with MIT-Scheme?Slocum
F
5

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

Feebleminded answered 13/7, 2014 at 17:57 Comment(0)
L
8

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
}
Lorielorien answered 29/11, 2016 at 14:41 Comment(0)
F
5

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

Feebleminded answered 13/7, 2014 at 17:57 Comment(0)
C
4

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
 }
Chape answered 16/7, 2021 at 15:24 Comment(0)
A
2

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
}
Archiplasm answered 20/5, 2017 at 3:34 Comment(1)
If you aren't an Emacs person, I suggest using Dr. Racket with the sicp package for a full IDE experience instead of a script like this. See https://mcmap.net/q/265725/-what-is-the-best-scheme-implementation-for-working-through-sicpArchiplasm

© 2022 - 2024 — McMap. All rights reserved.