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
IEx maniacs
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
ohr486
December 26, 2021
Programming
680
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
IEx maniacs
https://beam-lang.connpass.com/event/232202/
ohr486
December 26, 2021
More Decks by ohr486
See All by ohr486
負荷試験Night#1 負荷試験2023年トレンド
ohr486
17
4.9k
Elixir/PhoenixによるWeb開発の現場から
ohr486
1
660
Hacking Phoenix Performance
ohr486
1
410
Plug & WAF
ohr486
2
560
elixirをプロダクションに導入する
ohr486
1
740
Hack and Read Elixir
ohr486
2
820
Running App on AppRunner
ohr486
0
870
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
910
ex-app-on-k8s
ohr486
0
270
Other Decks in Programming
See All in Programming
今さら聞けない .NET CLI
htkym
0
150
AIエージェントで 変わるAndroid開発環境
takahirom
2
740
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3.3k
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
170
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
270
FDEが実現するAI駆動経営の現在地
gonta
2
240
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
190
テーブルをDELETEした
yuzneri
0
120
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
620
React本体のコードリーディング
high_g_engineer
0
110
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
260
Featured
See All Featured
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
440
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
580
AI: The stuff that nobody shows you
jnunemaker
PRO
9
850
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Agile that works and the tools we love
rasmusluckow
331
22k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
250
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
Transcript
IEx maniacs 2021-12-26 tokyo.ex #14
agenda • About Me • ゴール • モチベーション • iexの設定方法
• iexのショートカット(ヘルパー) • debugging with iex • まとめ
About Me • おーはら / Twitter: @ohrdev / Github: ohr486
• 株式会社ドリコム SRE部 部長 ◦ Work: ▪ エンジニアマネージャ • 技術戦略の策定/推進 • エンジニア採用/採用戦略策定 ▪ サーバー/インフラエンジニア • 開発現場でゲームのバックエンド (Rails/Phoenix/Go/HCL)のコード書いてます ▪ 新規事業/ディレクター • 負荷試験支援/DevOps推進支援/設計コンサル • Community ◦ tokyo.ex / Japan Elixir Association / Erlang&Elixir Fest • Hobby ◦ 仏像制作 ◦ 自転車
ゴール • ターゲット ◦ iexをもっと便利に使いたい人 ◦ iexを使ってdebugを効率的に行いたい人 • 今日のゴール ◦
iexの設定方法を理解する ◦ iexの便利な使い方を理解する
モチベーション • iexを活用することで生活レベル(=debug効率)が上がった • iexのコードを読んだ/hackした時の気付きが多かった ◦ https://blog.ohr486.net/2021/12/18/iex-inside/
iexの設定方法 • 設定ファイルは以下 ◦ (ホームディレクトリ) / .iex.exs ◦ (プロジェクトディレクトリ )
/ .iex.exs • ファイル探索の優先度 ◦ (1) ホームディレクトリに .iex.exsが無いかチェック ◦ (2) ホームディレクトリになければプロジェクトディレクトリが .iex.exsが無いかチェック • .iex.exsでは、任意のelixirのコードを実行可能 • import_fileで任意のファイルを読み込んで、記述されているelixirコードを実行可能 • iexのヘルパーも実行可能 ◦ プロジェクトディレクトリの .iex.exsからホームディレクトリの .iex.exsを読み込む等ができる • IEx.configure で動的に設定を変更可能 ◦ IEx.configure( 設定項目: 設定値 )
iexの設定方法 • プロンプト表示 : ◦ 色関連の設定: https://hexdocs.pm/elixir/IO.ANSI.html#functions ◦ default_prompt :
文字列を指定 IO.ANSI利用の為 文字列でもOK
iexの設定方法 • 複数行入力時のプロンプト表示 ◦ continuation_prompt : 文字列を設定 ▪ デフォルト: %prefix
部分のみが ドット(.) に差し代わる
iexの設定方法 • 複数行入力時のプロンプト表示 ◦ continuation_prompt : 文字列を設定
iexの設定方法 • 画面表示幅 ◦ width : 横幅の上限
iexの設定方法 • 返り値の表示 ◦ inspect : https://hexdocs.pm/elixir/Inspect.Opts.html ▪ limit :
タプル,Map,Bitstring,List等のコレクションの表示要素数の上限
iexの設定方法 • 返り値の表示 ◦ inspect : https://hexdocs.pm/elixir/Inspect.Opts.html ▪ pretty :
適当な幅でで改行を入れるかどうか
iexの設定方法 • 履歴保持数(後述する vヘルパー での評価値の履歴数) ◦ history_size : 保持履歴数
iexの設定方法 • 色設定 : https://hexdocs.pm/elixir/IO.ANSI.html#functions ◦ colors : ▪ eval_interrupt
: eval時のinterupt / デフォルト: yellow ▪ eval_result : evalの結果表示 / デフォルト: yellow ▪ eval_error : eval時のエラー表示 / デフォルト: red ▪ eval_info : eval時のinfo表示 / デフォルト: normal ▪ stack_info : stack情報表示 / デフォルト: red ▪ blame_diff : blameのdiff表示 / デフォルト: red ▪ ls_directory : ls時のディレクトリ表示 / デフォルト: blue ▪ ls_device : ls時のデバイス表示 / デフォルト: green ▪ syntax_colors • atom: atom型データの表示 / デフォルト: cyan • string : string型データの表示 / デフォルト: green • list : list型データの表示 / デフォルト: default_color • boolean: ブール型データの表示 / デフォルト: magenta • nil : nil型データの表示 / デフォルト: magenta • tuple : tuple型データの表示 / デフォルト: default_color • binary : バイナリデータの表示 / デフォルト: default_color • map : map型データの表示 / デフォルト: default_color
iexの設定方法 • 現在の設定状態の表示 ◦ IEx.configuration
iexの設定方法 • DEMO-1 ◦ ホームディレクトリの.iex.exsを読み込み ◦ 起動時にメッセージをクリア ◦ 起動メッセージを表示
iexのショートカット(ヘルパー) • helpers参照 ◦ https://github.com/elixir-lang/elixir/blob/main/lib/iex/lib/iex/helpers.ex • よく使うもの(1) ◦ 表示 ▪
clear() : ターミナルをクリア ▪ i(対象のvalue) : 対象の値の情報を表示 ▪ h(モジュール/関数/マクロ) : 対象のモジュール/関数/マクロの情報を表示 ▪ exports(モジュール) : 対象モジュールが公開している関数 /マクロを表示 ▪ ls() : 現在のディレクトリのファイルを表示 ▪ pwd() : 現在のディレクトリパスを表示 ◦ コンパイル ▪ recompile() : プロジェクトのコードを recompileしてロード ▪ c(ファイル) : 対象のファイルをコンパイル ▪ r(モジュール) : 対象のモジュールのソースコードをコンパイル
iexのショートカット(ヘルパー) • よく使うもの(2) ◦ REPL ▪ #iex:break : 行を跨いだ入力時に、入力をとりやめる
iexのショートカット(ヘルパー) • よく使うもの(3) ◦ プロセス ▪ pid(文字列) : 文字列のIDでプロセスIDを作成 ▪
pid(int, int, int) : 引数の数字でプロセス IDを作成 ※ port, refも同様
iexのショートカット(ヘルパー) • よく使うもの(3) ◦ 履歴 ▪ v() : 最後に評価された値を返却 ▪
v(n) : n番目の履歴(カウンタがn)の値を返却 ▪ v(-m) : m個前の履歴の値を返却
iexのショートカット(ヘルパー) • よく使うもの(4) ◦ 履歴(パイプ演算子) ▪ vを使って最後に評価した値を呼び出すことができた ▪ 行の冒頭でパイプ演算子を使うと、 vの値(最後に評価された値
)を入力として取れる
iexのショートカット(ヘルパー) • DEMO-2 ◦ 1 + 1 の評価を、iex上で再現 ◦ 文字列
-> トークン -> パース -> eval の一連の流れをelixirモジュールを使っ て実行
Code (charlist) Tokens Forms (quoted) tokenize parse Result eval Code
(string) String.to_charlist “ 1 + 1 “ ‘ 1 + 1 ‘ [ {:int, {1, 1, 1}, ‘1’}, {:dual_op, {1, 3, nil}, :+}, {:int, {1, 5, 1}, ‘1’} ] {:+, [line: 1], [1, 1]} 2 :elixir.string_to_tokens (clist, line, col, file, binds) :elixir.tokens_to_quoted (tokens, binds, env) :elixir.eval_forms (forms, binds, env)
debugging with iex • iexによる主なデバッグ方法 ◦ 古き良き時代のprintdebug(コードにIO.print, IO.inspect を差し込んで値を表示) ◦
ソースコードにIEx.pryを差し込んで、プログラムの途中で内部情報を確認 ◦ 特定の関数がcallされたタイミングでブレイクポイントを挿入、 IEx.pryで内部情報を確認 ◦ REPL上でヘルパーを駆使して処理を再現
debugging with iex • IEx.pry ◦ コードに「 require IEx; IEx.pry
」を記述すると、その行に到達した箇所で pryのREPLに入る ◦ respawn(): pryのREPLから出る ◦ whereami(): IEx.pry周辺のコードを表示 ◦ whereami(N): IEx.pry周辺のコードの前後 N行を表示
debugging with iex • break! ( Module, Function, Arity, break回数
) ◦ Module.Function/Arity の関数実行時に、break回数 だけbreakしてpryに入る
debugging with iex • DEMO-3 ◦ IEx.pryをコードに差し込んでpryを起動 ◦ 前後のコードを表示 ◦
pry挿入箇所のスコープでREPL ◦ respawnでpryから抜ける ◦ break!で特定の関数を実行したタイミングでpryを起動
まとめ • iexの設定ファイル(.iex.exs)について紹介しました • iexの設定項目を紹介しました • pry,breakを使ったiex上でのdebug方法を紹介しました • 参考情報 ◦
https://github.com/blackode/elixir-tips ◦ https://github.com/blackode/elixir-tips/blob/master/part2.md ◦ https://github.com/elixir-lang/elixir/blob/main/lib/iex/lib/iex/helpers.ex ◦ https://medium.com/blackode/custom-iex-prompt-elixir-c95b7f5bf8c3