This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* define('HOGECON', false); */ | |
if(HOGECON) { | |
print_r('hoge'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(format "%s" "foo") ; => "foo" | |
;; 整数は%sまたは%dで指定する | |
(format "%d" 1) ; => "1" | |
;; 右寄せ 左寄せ 0詰め | |
(format "[%2d] [%-2d] [%02d]" 3 3 3) ; => "[ 3] [3 ] [03]" | |
;; %cは文字を文字列に変換する | |
(format "文字から文字列へ: %c" ?a) ; => "文字から文字列へ: a" | |
;; %%は%そのものを表す | |
(format "%d円の商品の消費税は%d%%で%d円です" 500 5 (* 500 0.05)) ; => "500円の商品の消費税は5%で25円です" | |
(format "%s%s" "Emacs" "Lisp") ; => "EmacsLisp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(+ 3 4) ; => 7 | |
(* 5 6) ; => 30 | |
;; M-; で ;がレイアウトされ、もう一度M-; で; =>となる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(setq x 1) | |
x ; => 1 | |
(let ((x 2) | |
null) ; グローバル変数xを一時的に変更する | |
x ; => 2 | |
null ; => nil | |
;; letは入れ子に出来る | |
(let ((x 3)) x) ; => 3 | |
) | |
;; letを抜けたらグローバルの値になる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; リストを作る | |
(cons 1 (cons 2 (cons 3 nil))) ; => (1 2 3) | |
(list 1 2 3) ; => (1 2 3) | |
'(1 2 3) ; => (1 2 3) | |
;; リストに要素を追加するときは前から追加される | |
(setq l (cons 3 nil)) ; => (3) | |
(setq l (cons 2 l)) ; => (2 3) | |
(setq l (cons 1 l)) ; => (1 2 3) | |
;; リストのcarは先頭、cdrは残りすべて | |
(car '(1 2 3)) ; => 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;ifとprognをcondに置き変えるとインデントがきれいになる | |
(let (a b) | |
(if (= 1 1) | |
(progn | |
(setq a 2) | |
(setq b 3)) | |
(setq a 10) | |
(setq b 20)) | |
(list a b)) ; => (2 3) | |
(let (a b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; ネストしたif式をcondに置き換える | |
(if (zerop (% 10 4)) | |
"10は4の倍数" | |
(if (zerop (% 10 2)) | |
"10は偶数" | |
"10は奇数")) ; => "10は偶数" | |
(cond ((zerop (% 10 4)) | |
"10は4の倍数") | |
((zerop (% 10 2)) | |
"10は偶数") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; and 返り値は最後に評価したフォームで、いずれかが偽ならばnil | |
(and t t) ; => t | |
(and nil t) ; => nil | |
(and 1 2) ; => 2 | |
(if 1 2) ; => 2 | |
(and 1 2 3) ; => 3 | |
;; or 返り値は最後に評価したフォームで、すべて偽ならばnil | |
(or nil nil) ; => nil | |
(or nil t) ; => t | |
(or nil 1 2) ; => 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; whileをdolistに置き換える | |
(let ((lst '(1 2 3)) result) | |
(while (car lst) | |
(setq result (cons (car lst) result)) | |
(setq lst (cdr lst))) | |
(cons 'finished result)) ; => (finished 3 2 1) | |
(let (result) | |
(dolist (x '(1 2 3)) | |
(setq result (cons x result))) ; => nil | |
(cons 'finished result)) ; => (finished 3 2 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; aは必須引数で、bとcは省略可能関数(&optionalをつける) | |
(defun optional-arg (a &optional b c) | |
(setq c (or c 20)) ; デフォルト引数もどき | |
(list a b c)) | |
(optional-arg 1) ; => (1 nil 20) | |
(optional-arg 1 2) ; => (1 2 20) | |
(optional-arg 1 2 3) ; => (1 2 3) | |
(optional-arg 1 2 3 4) ; => エラー | |