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
D言語に入門した話 / Introduction to D language
Search
chapati
April 19, 2022
Technology
0
360
D言語に入門した話 / Introduction to D language
D言語に入門した話です
Twitterでご指摘いただいたのですが
- スライド15ページに記載のCTFEの実行について,バイトコードへの変換は特に行っていないようです
chapati
April 19, 2022
Tweet
Share
More Decks by chapati
See All by chapati
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
240
Other Decks in Technology
See All in Technology
Reflections of AI: A Trilogy in Four Parts (GOTO; Copenhagen 2025)
ondfisk
0
110
空間を設計する力を考える / 20251004 Naoki Takahashi
shift_evolve
PRO
4
460
SwiftUIのGeometryReaderとScrollViewを基礎から応用まで学び直す:設計と活用事例
fumiyasac0921
0
160
生成AIとM5Stack / M5 Japan Tour 2025 Autumn 東京
you
PRO
0
250
Git in Team
kawaguti
PRO
3
350
定期的な価値提供だけじゃない、スクラムが導くチームの共創化 / 20251004 Naoki Takahashi
shift_evolve
PRO
4
360
E2Eテスト設計_自動化のリアル___Playwrightでの実践とMCPの試み__AIによるテスト観点作成_.pdf
findy_eventslides
2
600
GoでもGUIアプリを作りたい!
kworkdev
PRO
0
130
AWS IoT 超入門 2025
hattori
0
330
Geospatialの世界最前線を探る [2025年版]
dayjournal
1
220
CoRL 2025 Survey
harukiabe
0
160
やる気のない自分との向き合い方/How to Deal with Your Unmotivated Self
sanogemaru
0
480
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
The Illustrated Children's Guide to Kubernetes
chrisshort
49
51k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
It's Worth the Effort
3n
187
28k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
140k
The Cult of Friendly URLs
andyhume
79
6.6k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
Transcript
D言語に入門した話 チャパティ
自己紹介 チャパティ (Twitter:@_shouth_kit) 情報工学課程4回 プログラムを書くのが好き ちゃぱえもんと呼ばれることもある
D言語って 知ってますか?
None
None
D言語の簡単な歴史 - 1999年に開発開始 - 2001年に最初のバージョンがリリース - 2007年にバージョン1.0に到達 紆余曲折を得て現在はD1は廃止され 現行のバージョンはD2
プログラム例: Hello world import std.stdio; int main() { writeln("Hello world!");
}
プログラム例: 基本的な制御構造 import std.stdio; int main() { for (int i
= 1; i <= 100; i++) { if (i % 15 == 0) { writeln("FizzBuzz"); } else if (i % 3 == 0) { writeln("Fizz"); } else if (i % 5 == 0) { writeln("Buzz"); } else { writeln(i); } } }
ね,簡単でしょう?
メタプログラミング にっょぃ struct Vector(size_t D, T = double) if (__traits(isFloating,
T)) { T[D] num; alias num this; T dot(const Vector rhs) { T res = 0; static foreach (i; iota(D)) res += num[i] * rhs.num[i]; return res; } static if (D == 3) { Vector cross(const Vector rhs) { return Vector([ num[0] * rhs.num[1] - num[1] * rhs.num[0], num[1] * rhs.num[2] - num[2] * rhs.num[1], num[2] * rhs.num[0] - num[0] * rhs.num[2] ]); } } } void main() { auto v0 = Vector!3([ 1, 2, 3 ]); auto v1 = Vector!3([ 4, 5, 6 ]); writeln(v0.cross(v1)); writeln(v0.dot(v1)); } メタプログラミング にっょぃ ↓こんな感じで呼べる
UFCS最強 struct Vector(size_t D, T = double) if (__traits(isFloating, T))
{ T[D] num; alias num this; } T dot(size_t D, T = double) (const Vector!(D, T) lhs, const Vector!(D, T) rhs) { T res = 0; static foreach (i; iota(D)) res += lhs.num[i] * rhs.num[i]; return res; } Vector!(D, T) cross(size_t D, T = double) (const Vector!(D, T) lhs, const Vector!(D, T) rhs) if (D == 3) { return Vector!(D, T)([ lhs.num[0] * rhs.num[1] - lhs.num[1] * rhs.num[0], lhs.num[1] * rhs.num[2] - lhs.num[2] * rhs.num[1], lhs.num[2] * rhs.num[0] - lhs.num[0] * rhs.num[2] ]); } Uniform Function Call Syntax void main() { auto v0 = Vector!3([ 1, 2, 3 ]); auto v1 = Vector!3([ 4, 5, 6 ]); writeln(v0.cross(v1)); writeln(v0.dot(v1)); } ↓同じくこんな感じで呼べる
UFCS最強 import std.stdio; string repeat(string s, size_t times) { char[]
res; for (size_t i = 0; i < times; i++) res ~= s; return cast(string) res; } void main() { "Hello world\n".repeat(3).write(); } 要はこんなことができる
CTFE最強 Compile Time Function Execution コンパイル時にインタプリタで実行してその計算結果 をバイナリに埋め込む 割と任意の処理がコンパイル時に実行できる
CTFE最強 Compile Time Function Execution 標準ライブラリには正規表現の文字列をコンパイル 時に解析するヤツとかある 私はこの機能を使ってコンパイル時 brainfuckインタ プリタを書きました
CTFE最強 Compile Time Function Execution この機能を掘り下げるとちょっと面白い 1. D言語をバイトコードにコンパイル 2. バイトコードをインタプリタが実行
3. 実行結果をコンパイラがバイナリに埋め込む ...という風に実現されているようです
微妙だと思う点もある あくまで私の主観ですが ...
それ言語レベルで実現しちゃったのか - unittest - version - debug - foreach_reverse
それ言語レベルで実現しちゃったのか - unittest - version - debug - foreach_reverse int
multiply(int a, int b) { return a * b; } unittest { assert(multiply(2, 3) == 6); assert(multiply(7, 9) == 63); } Cでライブラリ毎にテスト方法がバラバラだった のをどうにかしたかったらしい
それ言語レベルで実現しちゃったのか - unittest - version - debug - foreach_reverse version
(Windows) { // Windows用のコード } else { // それ以外 } Cのマクロをどうにかしたかったらしい
それ言語レベルで実現しちゃったのか - unittest - version - debug - foreach_reverse debug
{ // デバッグ用コード } これもCのマクロをどうにかしたかったらしい
それ言語レベルで実現しちゃったのか - unittest - version - debug - foreach_reverse int[]
arr = [ 1, 2, 3, 4, 5 ]; foreach_reverse (i, e; arr) { // 逆向きに反復 } 「順方向」と「逆方向」を相補的なモノとして捉えたようだ
言語キメラ - Javaのclassに - C++のtemplateを合体させ - Cのマクロを分解して取り込んだ こんな感じの言語 決して悪いわけじゃないけど2022年基準で見ると微妙な気がする
質疑応答とか 一通り Origins of the D Programming Language を読み込んだので D言語の歴史とかも触りだけ話せます
参考 - Origins of the D Programming Language https://dl.acm.org/doi/pdf/10.1145/3386323 -
Dlang Tour https://tour.dlang.org