从命令行运行Scheme one-liner

从命令行运行Scheme one-liner

如何既不使用保存在文件中的脚本也不启动交互式 shell 从命令行运行Scheme 表达式?

Python 中的等价物是:python -c "print 1+1".scheme (+ 1 1)只需启动交互式 shell 并在其中显示结果。

答案1

我安装guile并能够让它以四种方式执行代码:

1

$ guile <<< "(+ 1 1)"
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
$ 

2

$ echo "(+ 1 1)" | guile
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
scheme@(guile-user)>
$ 

3

$ echo "(+ 1 1)" > guile.script
$ guile < guile.script
GNU Guile 2.0.9
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
$1 = 2
$ 

4

谢谢GAD3R对于这个:

$ guile -c "(display (+ 1 1)) (newline)"
2
$

在所有情况下,我都会返回到原来的 shell 提示符(由裸线表示$)。

相关内容