関数型言語の勉強にSICPを読もう - (41) 3章 - 小休止 はじめての実用(?)スクリプト
id:higepon:20060518:1147942020を改造して、Gaucheではじめての実用(?)スクリプトを書いてみました。
↓こんな感じで使います。
gosh replace.scm sample.txt "^(hogehoge.+)$" "#\\1"
#!/usr/bin/env gosh
(use file.util)
(define (main args)
(define (replace-text file from-regexp to)
(display from-regexp)
(display to)
(map
(lambda (line)
(regexp-replace from-regexp line to))
(file->string-list file)))
(if (< 4 (length args))
(error "no args")
(let1 lines (replace-text (cadr args) (caddr args) (cadddr args))
(call-with-output-file
(cadr args)
(lambda (port)
(for-each
(lambda (line)
(display line port)
(newline port))
lines))))))
cygwinでも動くのでひっそりと僕のマシンで活躍中です。
計算機プログラムの構造と解釈
posted with amazlet on 06.04.15
Gerald Jay Sussman Julie Sussman Harold Abelson 和田 英一
ピアソンエデュケーション (2000/02)
売り上げランキング: 56,404
ピアソンエデュケーション (2000/02)
売り上げランキング: 56,404
