🔙 Back to Top

Feb 02 2013

Gauche 設定ファイル [後編]

ファイル名は ~/.scm としてたほうがそれっぽいな. gosh -l で読み込めるかが心配だったんだけど杞憂だった.

それと、pwd, cd, ls なんかがあったほうも便利だ. これは http://practical-scheme.net/gauche/man/gauche-refj_140.html を使ったほうがよかろう.

;; .scm
(use srfi-1)
(use file.util)
(use gauche.process)

(define-syntax e
    (syntax-rules ()
        ((_ name) (begin (run-process `(vim ,name) :wait #t)
                         (load (string-append "./"
                                 (if (symbol? name) (symbol->string name) name)))) )))

(define-syntax cd
    (syntax-rules ()
        ((_)      (current-directory))
        ((_ dir)  (current-directory (if (symbol? dir) (symbol->string dir) dir))) ))
(define (pwd) (cd))

(define-syntax ls
    (syntax-rules ()
        ((_)      (ls "."))
        ((_ dir)  
    (receive (ds fs) (directory-list2 (if (symbol? dir) (symbol->string dir) dir))
    (let1 ls (append (map (cut string-append <> "/") (drop ds 2)) fs)
    (display (string-join ls (if (< (length ls) 10) "\n" "\t")))
    (newline) )))))

(define-syntax cat
    (syntax-rules ()
        ((_ fname) (display (call-with-input-file (if (symbol? fname) (symbol->string fname) fname) port->string)))))

基本的にいちいち"で括りたくないので、文字列ではなくシンボルで ファイル名なんかを指定.

(e 'test.scm)

gauche ファイルの編集. vimプロセスが終了後、インタプリタはロードを試みる.

(cd [dir])

current directory の変更.(cd)は (pwd)に等しい.

(ls)
(cat 'test.scm)