■
(carに対して : 残りのリストに対して)
mapcar : maplist
mapc : mapl
mapcan : mapcon
(setq a '(1 2 3 4 5 6 7 8)) (mapcan #'(lambda (x) (if (evenp x) (list x))) a) -> (2 4 6 8) (defun mapcan2 (fn lst) (apply #'nconc (mapcar fn lst)))
集合
(setq a '(1 2 3 4 5 6 7 8)) (member 7 a) ->(7 8) (member-if #'evenp a) ->(2 3 4 5 6 7 8) (member-if-not #'evenp a) ->(1 2 3 4 5 6 7 8) (setq b '(1 2 4 5)) (adjoin 3 b);; なければ追加 (3 1 2 4 5) (adjoin 3 b) (3 1 2 4 5) (setq v1 '(1 2 3 4) v2 '(3 4 5 6)) ;; デフォルトではeq(:test) (union v1 v2) ->(1 2 3 4 5 6) (intersection v1 v2) ->(4 3) (set-difference v1 v2);; v1 - v2 ->(2 1) (set-exclusive-or v1 v2) ->(2 1 6 5) (defun set-xor2 (x y) (set-difference (union x y) (intersection x y) )) (set-xor2 v1 v2) ->(6 5 2 1) (subsetp '(2 3 4) '(1 2 3 4 5));; xがyの部分集合 ->t ;; キーワード:keyを使って関数を適用することができる (member 2 '((one . 1) (two . 2) (three . 3)) :key #'cdr) ((two . 2) (three . 3)) (member 64 '(0 1 2 3 4 5 6 7 8 9 10) :key #'(lambda (x) (expt 2 x))) (6 7 8 9 10)
破壊版
nunion
nintersection
nset-difference
nset-exclusive-or
文字列
(substring "common lisp" 4);; str start [end] ->"on lisp" (substring "common lisp" 1 5) ->"ommo" (subseq "common lisp" 4) ->"on lisp" (string= "hello" "HELLO") ->nil (string-equal "hello" "HELLO") ->t (equal "hello" "HELLO") ->nil (equalp "hello" "HELLO") ->t (string< "hello" "hellp");; 何文字目が運命の分かれ目になったか返ってくる(真なら) ->4 (string<= "hello" "hello") ->5 ;; 割る ではなく,ノットイコール (string/= "potato" "potato") ->nil (string/= "potato" "potato!") ->6 以下は大文字・小文字を区別しない string-lessp : < string-not-lessp : >= string-greaterp : > string-not-greaterp : <= string-not-equal : /= (concatenate 'string "L" "I" "S" "P");; 連結 ->"LISP" (string-trim "*" "**.*Lisp*.**") ->".*Lisp*." (string-trim '(#\* #\.) "**.*Lisp*.**");; リストで複数の文字を ->"Lisp" (string-right-trim "-" "-Lisp-") ->"-Lisp" (string-right-trim "-" "-Lisp-") ->"Lisp-" (string-upcase "visual studio") ->"VISUAL STUDIO" (string-downcase "VISUAL STUDIO") ->"visual studio" (string-capitalize "c c# c++ java python ruby lisp COBOL") ->"C C# C++ Java Python Ruby Lisp Cobol" ;;nstring-upcase, nstring-downcase, nstring-capitalize (reverse "asihubon") ->"nobuhisa" (search "l" "hello") ->2 (search "l" "hello" :from-end t) ->3 (elt "hello" 4) ->#\o (make-sequence 'string 10 :initial-element #\A) ->"AAAAAAAAAA"
その他シーケンス関数
http://www.lispworks.com/documentation/HyperSpec/Body/c_sequen.htm
いろいろ
(type-of "hello") ->simple-string (typep 1 'integer) ->t (identity 1) ->1 (parse-integer "1024") ->1024 ->4 (parse-integer "1024" :start 1);; :endもある ->24 ->4 (parse-integer "10000000000" :radix 2) ->1024 ->11 (parse-integer "100km/h" :junk-allowed t);; 変なのがあっても解析! ->100 ->3 (write-to-string 127) ->"127" (write-to-string 127 :base 2) ->"1111111" 出力色々 prin1 princ print pprint
現在更新中