有没有办法降低 MIT Scheme 的冗长程度?

Is there a way to turn down the verbosity of MIT Scheme?

我最近决定按照 SICP 中的示例开始使用 MIT Scheme。我从 Ubuntu 存储库安装了方案。

sudo apt-get install mit-scheme

给定一个如下所示的输入文件:

486
(+ 137 349)
(- 1000 334)
(* 5 99)
(/ 10 5)
(* 25 4 12)

我运行方案如下

scheme < Numbers.scm

它产生以下输出。

MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2011 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Sunday February 7, 2016 at 10:35:34 AM
  Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> 486
;Value: 486

1 ]=> (+ 137 349)
;Value: 486

1 ]=> (- 1000 334)
;Value: 666

1 ]=> (* 5 99)
;Value: 495

1 ]=> (/ 10 5)
;Value: 2

1 ]=> (* 25 4 12)
;Value: 1200

1 ]=> 
End of input stream reached.
Moriturus te saluto.

这个输出感觉太多了,所以我目前正在削减它。

scheme < Numbers.scm  | awk '/Value/ {print }
486
486
666
495
2
1200

有没有一种本机方法可以减少方案的冗长程度,这样我就可以在不借助外部进程的情况下获得类似于上述输出的内容?

我检查了 scheme --help 的输出,但没有找到任何明显的选项。


请注意,将文件名作为参数传递在 MIT-Scheme 中似乎不起作用。

scheme Numbers.scm  
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2011 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Sunday February 7, 2016 at 10:35:34 AM
  Release 9.1.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116
;Warning: Invalid keyword: "Numbers.scm"
;Warning: Unhandled command line options: ("Numbers.scm")

1 ]=> 

作为解决方法,

scheme < Numbers.scm | gawk '/^;Value: / { sub(/^;Value: /, ""); print }'

但也许您会 运行 将其作为脚本文件而不是标准输入流?不确定 MIT Scheme 调用,比如

scheme Numbers.scm

虽然这样你必须明确地打印出结果,用 (display) 或其他东西,否则他们会被忽视。

给你:

scheme --quiet < Numbers.scm 

现在这将完全抑制 REPL,除非发生错误,这样未明确显示的内容将不会显示。例如。评估 (+ 2 3) returns 5,但不会打印,因为您没有告诉它打印。您需要使用 display 之类的过程来打印信息,或者返回使用 REPL,其唯一目的是显示您的结果。

我原本希望你能做到:

scheme --quiet --load Numbers.scm

但是在文件后并没有退出,加上--eval (exit)让REPL问你要不要退出。

编辑

(define (displayln v)
  (display v)
  (newline)
  v)

(displayln (+ 4 5))
; ==> 9, in addition you get the side effect that "9\n" is written to current output port

您也许还可以制作一个宏来执行此操作:

(define-syntax begin-display
  (syntax-rules ()
    ((_ form ...) (begin (displayln form) ...))))

(begin-display
  486
  (+ 137 349) 
  (- 1000 334)
  (* 5 99)
  (/ 10 5)
  (* 25 4 12))
; ==> 1200. In addition you get the side effect that "486\n486\n666\n49\n2\n1200\n" is written to current output port