elisp入門めも


elisp
• 概要
◦ すべてが式(expression)
関数型言語
▪ 関数と関数呼び出しプログラミング
▪ 関数とは
▪ 副作用がない
▪ 引数を書き換えることを「破壊的」という
▪ 入力があって出力がある
◦ 例
▪ (+ 1 3) => 4
▪ (+ 3 4 5) => 12
▪ (setq foo "Foo") => "Foo" 
foo => "Foo"
▪ (if (= a b) (message "a equals to b") (message "a doesn't equal to b")))
▪ (defun my-hello-emacs () (message "hello emacs"))
▪ (let *1 => "foo"
▪ (cdr '("foo" . "bar")) => "bar"
• 関数
◦ (defun my-plus1 (n) (+ n 1)) ; (my-plus1 10)
◦ (defun my-plus (m n) (+ m n)) ;(my-plus 2 5)
*2 1 3)
◦ (fset 'my-plus2 '(lambda (n) (+ n 2)))
• シンボル(symbol)
◦ foo ; (setq foo "Foo")
◦ 任意のオブジェクトをさせる
• オブジェクト
◦ 型
vector
▪ cons
▪ string
▪ float
▪ 3.14
▪ 9.01
▪ integer
▪ 42
▪ 100
▪ symbol

*1:cnt 0) (lst '(1 8 7 11 3 2))) (mapcar '(lambda (n) (if (= (% n 2) 0) (setq cnt (1+ cnt)))) • クォート ◦ 評価しない ◦ (set (quote foo) "foo") ;(set 'foo "foo") • コンスセル(リスト) ◦ 二つのスロット(ポインタ)を持つオブジェクト ◦ 生成 ▪ ("foo" . "bar") ▪ (cons "foo" "bar") ◦ 参照 ▪ carとcdrのみで参照可能 ▪ (car '("foo" . "bar"

*2:lambda (m n) (+ m n