はじめての Scheme

移り気な僕は Scheme なぞを触ってみた。学生時代にもなぜかやっていなかったので今さらではあるが、違った言語を学ぶことで新たな視点を身につけることができると思う。

処理系には、GaucheGauche - A Scheme Implementation) を使うこととする。お手軽な感じがしたので。 MIT/GNU Schemeはエディタが慣れるのに大変そうだし、DrSchemeはUIは親切だけど重そうだったので。

エディタには 日ごろ使っている Meadow を使う。
SICP再開に向けて emacs + gauche の環境を整えた : フッ君の日常
を参考に、.emacs

(setq scheme-program-name "gosh")
(require 'cmuscheme)

(defun scheme-other-window ()
  "Run scheme on other window"
  (interactive)
  (switch-to-buffer-other-window
   (get-buffer-create "*scheme*"))
  (run-scheme scheme-program-name))

(define-key global-map
  "\C-cS" 'scheme-other-window)

を追加。

Scheme を学ぶ王道は SICP(計算機プログラムの構造と解釈)であるが、いきなりは自信がなかったので初心者向けのサイトを探す。
もうひとつの Scheme 入門(http://www.shido.info/lisp/idx_scm.html
というページを見つける。これ分かり易そう。

しばし触っているうちに、3章のコンスセルまでたどり着いた。練習問題

("Sum of" (1 2 3 4) "is" 10)

(cons "Sum of" (cons (cons 1 (cons 2 (cons 3 (cons 4 '())))) (cons "is" (cons 10 '()))))

ができた時はちょっと達成感。

こういうのは脳刺激するので楽しいね。