Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ansi_common_lispが読めるようになりたい2 #TechLunch
Search
Livesense Inc.
PRO
April 23, 2014
Technology
0
60
ansi_common_lispが読めるようになりたい2 #TechLunch
2011/10/26(水) @ Livesense TechLunch
発表者:春日 太志
Livesense Inc.
PRO
April 23, 2014
Tweet
Share
More Decks by Livesense Inc.
See All by Livesense Inc.
27新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
0
2.4k
株式会社リブセンス・転職会議 採用候補者様向け資料
livesense
PRO
0
51
株式会社リブセンス 会社説明資料(報道関係者様向け)
livesense
PRO
0
1.5k
データ基盤の負債解消のためのリプレイス
livesense
PRO
0
440
26新卒_総合職採用_会社説明資料
livesense
PRO
0
11k
株式会社リブセンス会社紹介資料 / Invent the next common.
livesense
PRO
1
37k
26新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
1
13k
中途セールス職_会社説明資料
livesense
PRO
0
260
EM候補者向け転職会議説明資料
livesense
PRO
0
130
Other Decks in Technology
See All in Technology
Codeful Serverless / 一人運用でもやり抜く力
_kensh
7
360
5年目から始める Vue3 サイト改善 #frontendo
tacck
PRO
3
210
品質視点から考える組織デザイン/Organizational Design from Quality
mii3king
0
160
AIのグローバルトレンド2025 #scrummikawa / global ai trend
kyonmm
PRO
1
260
AWSを利用する上で知っておきたい名前解決のはなし(10分版)
nagisa53
9
2.9k
EncryptedSharedPreferences が deprecated になっちゃった!どうしよう! / Oh no! EncryptedSharedPreferences has been deprecated! What should I do?
yanzm
0
130
複数サービスを支えるマルチテナント型Batch MLプラットフォーム
lycorptech_jp
PRO
0
280
データアナリストからアナリティクスエンジニアになった話
hiyokko_data
2
440
Obsidian応用活用術
onikun94
1
450
バイブスに「型」を!Kent Beckに学ぶ、AI時代のテスト駆動開発
amixedcolor
2
500
オブザーバビリティが広げる AIOps の世界 / The World of AIOps Expanded by Observability
aoto
PRO
0
330
Webアプリケーションにオブザーバビリティを実装するRust入門ガイド
nwiizo
5
700
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.5k
Building Applications with DynamoDB
mza
96
6.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Designing for Performance
lara
610
69k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
910
The Power of CSS Pseudo Elements
geoffreycrofte
77
6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
111
20k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Art, The Web, and Tiny UX
lynnandtonic
302
21k
Balancing Empowerment & Direction
lara
3
610
Transcript
@bar_̲row 2011年年10⽉月19⽇日 Livesense Inc. 1
⽬目次 Livesense Inc. 2 1. 関数 2. ⼊入出⼒力力 3. 変数
4. 代⼊入 5. 反復復 6. リスト
1-‐‑‒1. 関数(関数の定義) Livesense Inc. 3 > (defun my-third (x)) (car
(cdr (cdr x))) MY-THIRD > (my-third ’(a b c d)) C Ø 関数の定義は defun オペレータを使う Ø defun の引数は通常「関数名」「引数リスト」「関数本体」 Ø リストの指定要素を取得するアクセス関数オペレータ nth, first – tenth, cxr
1-‐‑‒2. 関数(関数オブジェクト) Livesense Inc. 4 > (function +) #<compiled-function +>
> #’+ #<compiled-function +> Ø function オペレータで関数オブジェクトを得る Ø quote と同様に #ʼ’ のエイリアスがある
1-‐‑‒3. 関数(call, apply, map) Livesense Inc. 5 > (apply #’+
1 2 ’(3 4 5)) 15 > (funcall #’* 1 2 3 5) 30 > (mapcar #’(lambda (x) (* x 2)) ’(1 2 3)) (2 4 6) Ø apply はパラメータの最後がリストである必要がある Ø funcall はパラメータがリストでなくてよい Ø リストの各要素に関数を適⽤用するオペレータは何個かある
1-‐‑‒4. 関数(無名関数) Livesense Inc. 6 > (lambda (x y) (+
x y) (LAMBDA-CLOSURE () () () (X y) (+ X Y)) > ((lambda (x y) (+ x y)) 1 2) 3 > (funcall #’(lambda (x y) (+ x y)) 1 2) 3 Ø lambda はオペレータではなくシンボル、古い Lisp の名残 Ø 即時実⾏行行できるし、#ʼ’ で関数オブジェクトを得られる
2. ⼊入出⼒力力 Livesense Inc. 7 > (format t“~A plus ~A
equals ~A.~%”2 3 (+ 2 3)) 2 plus 3 equals 5. NIL > (read) > a A Ø format は「出⼒力力場所」「書式」「挿⼊入値」を受け取る Ø read は構⽂文解析して得られた Lisp オブジェクトを返す
3. 変数 Livesense Inc. 8 > (let ((x 1) (y
2)) (+ x y) 3 > (defparameter *age* 27) *AGE* > (defconstant limit 35) LIMIT Ø 変数定義は局所変数は let、⼤大域変数は defparameter を使う Ø ⼤大域変数名の前後のアスタリスクは慣習 Ø 局所変数で初期化した変数は let の本体内でのみ使⽤用可能 Ø ⼤大域定数で使われたシンボルを変数名として使うとエラー
4. 代⼊入 Livesense Inc. 9 > (setf *age* 28) 28
> (let ((n 10)) (setf n 2) n) 2 > (setf a 1 b 2) 2 > (setf (car ’(1 2 3)) 4) (4 2 3) Ø 変数への代⼊入には setf Ø ⼀一般化参照 Ø setf の第⼀一引数が局所変数 でない場合は⼤大域変数と みなされる
5-‐‑‒1. 反復復 Livesense Inc. 10 > (do ((i 0 (+
i 1))) ((> i 5) ’done) (format t“~A~%”i)) 0 1 2 3 4 5 DONE Ø (変数 初期値 更更新式) Ø (終了了判定式 終了了後実⾏行行式) Ø (本体式)
5-‐‑‒2. 反復復(dolist) Livesense Inc. 11 > (let ((len 0)) (dolist
(elem ’(a b c d e)) (setf len (+ len 1))) len) 5 Ø リストの反復復処理理を⾏行行うのであれば dolist が便便利利
6-‐‑‒1. リスト(proper list) Livesense Inc. 12 Ø コンス(コンスセル)は概念念的には⼀一対のポインタ Ø 第⼀一ポインタは
car 部を、第⼆二ポインタは cdr 部を指す Ø コンスだけからなるリストは真リストと呼ばれる nil a (A) (list ’a)
6-‐‑‒2. リスト(proper list) Livesense Inc. 13 nil a b c
(A B C) (list ’a ’b ’c)
6-‐‑‒3. リスト(proper list) Livesense Inc. 14 nil a b d
(A (B C) D) c (list ’a ’(b c) ’d) nil
6-‐‑‒4. リスト(dotted list) Livesense Inc. 15 Ø 真リストでないコンスはドットリストと呼ばれる Ø ’(a
b c) は ’(a . (b . (c . nil))) と書いても同じ nil a (A) (cons ’a nil) a (A . B) (cons ’a ’b) b
6-‐‑‒5. リスト(assoc list) Livesense Inc. 16 Ø ドットリストで連想リストが⽣生成できる Ø assoc
オペレータで指定キーのドットリストを取得 Ø しかしパフォーマンスは低い > (setf hoge ’((+ .“add”) (- .“substract”)) ((+ .“add”) (- .“substract”)) > (cdr (assoc ’+ hoge)) “add” > (assoc ’* hoge) NIL
Livesense Inc. 17