Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ansi_common_lispが読めるようになりたい2 #TechLunch
Search
Livesense Inc.
PRO
April 23, 2014
Technology
80
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ansi_common_lispが読めるようになりたい2 #TechLunch
2011/10/26(水) @ Livesense TechLunch
発表者:春日 太志
Livesense Inc.
PRO
April 23, 2014
Transcript
17 slides
@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
More Decks by Livesense Inc.
See All by Livesense Inc.
新規商品の開発におけるAIの活用 〜挑戦は人間にしかできない〜
livesense
PRO
0
35
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
210
Rubyはただの⾔語に⾮ず
livesense
PRO
0
620
28新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
0
190
27新卒_総合職採用_会社説明資料
livesense
PRO
0
8k
27新卒_Webエンジニア職採用_会社説明資料
livesense
PRO
0
13k
株式会社リブセンス・転職会議 採用候補者様向け資料
livesense
PRO
0
630
株式会社リブセンス 会社説明資料(報道関係者様向け)
livesense
PRO
1
1.8k
データ基盤の負債解消のためのリプレイス
livesense
PRO
0
750
Other Decks in Technology
See All in Technology
[DBRE Summit 26] DBRE はデータベース運用をどう変えたのか
_awache
0
140
フルTypeScript × AI駆動開発で開発量が数倍に (JSConf JP 2026 スポンサーLT:NCDC株式会社)
keitaibaraki
0
150
AIエージェントのアーキテクチャ設計
nsatoh
0
560
Taking back control of your AI development
inesmontani
PRO
0
320
こんなに変わった! AWSネットワークの常識
shotashiratori
16
12k
[NW-JAWS DAY]「うちのAWS、インターネット出られないんで」― AWS外の自社サービスをPrivateLinkでシュッと公開する方法
ykimi
3
930
Platform Engineering をベースとした Agentic Software Factory の実践
110y
3
1k
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
260
攻撃と守りは何が変わり、何が変わらないのか~最近の不正アクセスから考える、リスク評価と標準の使いどころ
oidfj
2
330
業務の傍らで進める改善ループエンジニアリング
bengo4com
1
240
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
490
gradle-best-practices 使ってみた
mikanichinose
0
240
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1.1k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
2
560
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
690
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k