info

aescm使ってみた

aescmってのはscheme(他の言語でも使えるみたい)で使える、Rubyで言う所のerb、Perlで言う所のTemplate Toolkit
普通にテキストを書いていって、テキストを繰り返したい時や一部だけ書きかえたい時プログラムを貼りつけられる。

使ってる処理系はgauche 0.8.13なんで単純にaescmのtarおっことしてきて解凍して、./configure make sudo make install
gauche以外の処理系使うとなんかconfigure時に操作が必要みたい

README.jaを見てみる

<?TARGET EXPRESSION ... ?>  -- EXPRESSION を順に評価する
<?TARGET:d EXPRESSION?>     -- EXPRESIION を評価して, display で出力する

改行とかで書きにくすぎて、ググってたらいい記法があった
http://www.uchizono.com/wiki/wiliki.cgi?%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E5%9F%8B%E3%82%81%E8%BE%BC%E3%81%BFScheme

<?scm
(use srfi-1)
(define (beers x)
  (cond ((= x 0) "no more bottles of beer")
        ((= x 1) "1 bottle of beer")
        ((> x 1) (string-append (x->string x) " bottles of beer"))))

(for-each
 (lambda (x)
?><?scm:d (beers x) ?> on the wall, <?scm:d (beers x) ?>.
<?scm
(if (= x 0)
    (begin ?>Go to the store and buy some more, 99 bottles of beer on the wall.<?scm (newline) (newline))
    (begin ?>Take one down and pass it around, <?scm:d (beers (- x 1))?> on the wall.<?scm (newline) (newline))))
(reverse (iota 100 0)))
?>

出力

$ aescm hell.scm
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

----------------------------------------------

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

no more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.

よし動いた