How do I execute a .scm script (outside of the REPL) with MIT-Scheme?

怎甘沉沦 提交于 2019-11-28 19:08:37

scheme <file.scm should work (as long as you don't specify --interactive and stdin is not a terminal, scheme works non-interactively).

To run a scheme program using MIT Scheme:

scheme --quiet < program.scm

The --quiet option ensures that the output from your program is the only thing that is displayed (i.e. you won't see the REPL, as per your requirements).

EDIT: Due to the possibility that you may mistype < as >, resulting in the overwrite of your source code, I would suggest encapsulating the above command within a shell script or a shell function. For example:

runscheme () {
    scheme --quiet < "$1"
}

Then you can run runscheme program.scm without fear that your source code will be overwritten. (Special thanks to Paul Rooney for bringing this potential mistake to my attention).

References

scheme --help:

--batch-mode, --quiet, --silent

Suppresses the startup report of versions and copyrights, and the valediction.

This command line option seems to have been mistakenly ommitted from the list of command line options in the documentation, but I think this is a legimate command line option because scheme --help shows it, and because --batch-mode is used in other parts of the reference manual (e.g. here).

I think what you want is SCM. You can execute a .scm script like this:

$ scm -f foo.scm arg1 arg2 arg3

See http://people.csail.mit.edu/jaffer/scm_3.html#SEC28 for more details.

The SCM homepage: http://people.csail.mit.edu/jaffer/SCM

checked chez --help, and then I found this(let's say that I'm using chez scheme):

chez --script ./temp.scm

Also, --verbose is very useful:

chez --verbose --script ./temp.scm
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!