
65
65
4.4 参考文献
す。たとえば、行単位で関数を適用することができます。例
4-7
と例
4-8
は、それぞ
れ
Python
と
R
でこれがどのようなコードになるのかを示す必要最小限のコードです。
これらは、パイプを介して送られてくる整数の自乗を計算します。
例
4-7
~/book/ch04/stream.py eeeee
#!/usr/bin/env python
from sys import stdin, stdout
while True:
line = stdin.readline()
if not line:
break
stdout.write("%d\n" % int(line)**2)
stdout.flush()
例
4-8
~/book/ch04/stream.R
#!/usr/bin/env Rscript
f <- file("stdin")
open(f)
while(length(line <- readLines(f, n = 1)) > 0) {
write(as.integer(line)^2, stdout())
}
close(f)
/}
4.4
• Docopt.
(
2014
)
. Command-Line Interface Description Language. http://
docopt.org.
から取得。
• Peek, J., Powers, S., O'Reilly, T., & Loukides, M.
(
2002
)
. Unix Power
Tools ...