Skip to content

Instantly share code, notes, and snippets.

@moratori
Created June 5, 2013 15:02
Show Gist options
  • Save moratori/5714545 to your computer and use it in GitHub Desktop.
Save moratori/5714545 to your computer and use it in GitHub Desktop.
simple read macro
;; Lisp のリーダは括弧の始まりを読むと閉じ括弧までを読む
;; ( から ) まで
;; 今それと同じ機能を [] にも 持たせる
;; まず閉じる目印になる括弧を設定
;; こいつは ) と同じ機能
(set-macro-character #\] (get-macro-character #\)))
;; 開き括弧に会ったら、閉じ括弧まで読む
(set-macro-character #\[
(lambda (stream char)
(declare (ignore char))
(read-delimited-list #\] stream t)))
[defun fact [n]
[cond
[[zerop n] 1]
[t [* n [fact [1- n]]]]]]
[print [fact 5]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment