MacにGaucheの環境を作る

作り方

  1. MacにGaucheを入れる
  2. デバッグしやすいようにtraceを使えるようにする
  3. VimからGaucheを叩けるようにする

1.Gaucheのインストール

homebrewで入る
brew install gauche  
インストール後は、コマンドライン上で以下のように使う
$ gosh ;goshに入る  
gosh> (+ 1 2)  
3
gosh> (exit) ;goshから出る

2.Debug用にトレースを入れる

slibのインストール

slibがhomebrewに無いので自分で頑張る

cd ~  
mkdir tmp  
cd tmp  
  
curl -O 'http://groups.csail.mit.edu/mac/ftpdir/scm/slib-3b4.zip'  
unzip slib-3b4.zip  
  
mv slib /usr/local/  
cd /usr/local/slib  
  
./configure  
make  
sudo make install  
traceの使い方
;テスト用関数定義  
(define (inc x) (+ x 1))
(define (dec x) (- x 1))
(define (plus a b)
 (if (= a 0)
     b
     (inc (plus (dec a) b))))

; traceを設定する
(use slib)
(require 'trace)
(trace plus)

;traceを出力する
(print (plus 4 5))
CALL plus 4 5
  CALL plus 3 5
    CALL plus 2 5
      CALL plus 1 5
        CALL plus 0 5
        RETN plus 5
      RETN plus 6
    RETN plus 7
  RETN plus 8
RETN plus 9
9

参考にした記事
Scheme処理系のインストールとデバッグトレース - somemo's diary
404 Blog Not Found:scheme - traceとslib

3.VimからGaucheを叩けるようにする

vimすら怪しい私がEmacsにまで手を広げられるわけないのでvimからGaucheを叩くためのプラグインを入れる。 NeoBundleを使ってインストールするので、.vimrcに以下を書く

" gaucheを呼ぶまではロードしない
NeoBundleLazy "git://github.com/aharisu/vim_goshrepl.git", {
       \ "autoload": {
       \   "commands": ['GoshREPL', 'GoshREPLWithBuffer'],
       \}}
vmap <CR> <Plug>(gosh_repl_send_block)
let s:hooks = neobundle#get_hooks("vim_goshrepl")
  function! s:hooks.on_source(bundle)
    let g:gosh_buffer_direction = 'v'    "垂直分割でバッファを開く
    let g:gosh_buffer_width = 80        "バッファの横幅は80文字
  endfunction
主なコマンドは以下

GoshREPL -> gosh REPLを起動
GoshREPLWithBuffer -> バッファを読見込んでREPLを起動
特にGoshREPLWithBufferは便利
コードが書かれたファイルをvimで開いてから、GoshREPLWithBufferするとファイルで定義しておいた関数などがREPL上で使える

なお、GoshREPLWithBufferはMacVim(Kaoriya)からは使えなかった。
残念。

参考にした記事
Vim上でGaucheのREPLを動かす - aharisuのごみ箱