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
350
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
230
Other Decks in Technology
See All in Technology
AIのグローバルトレンド 2025 / ai global trend 2025
kyonmm
PRO
1
120
✨敗北解法コレクション✨〜Expertだった頃に足りなかった知識と技術〜
nanachi
1
550
風が吹けばWHOISが使えなくなる~なぜWHOIS・RDAPはサーバー証明書のメール認証に使えなくなったのか~
orangemorishita
15
5.5k
【OptimizationNight】数理最適化のラストワンマイルとしてのUIUX
brainpadpr
1
310
Tableau API連携の罠!?脱スプシを夢見たはずが、逆に依存を深めた話
cuebic9bic
3
210
【CEDEC2025】大規模言語モデルを活用したゲーム内会話パートのスクリプト作成支援への取り組み
cygames
PRO
2
770
AIに目を奪われすぎて、周りの困っている人間が見えなくなっていませんか?
cap120
1
430
オブザーバビリティプラットフォーム開発におけるオブザーバビリティとの向き合い / Hatena Engineer Seminar #34 オブザーバビリティの実現と運用編
arthur1
0
350
AI時代の経営、Bet AI Vision #BetAIDay
layerx
PRO
1
1.8k
OPENLOGI Company Profile for engineer
hr01
1
37k
20250807_Kiroと私の反省会
riz3f7
0
170
Google Agentspaceを実際に導入した効果と今後の展望
mixi_engineers
PRO
3
340
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Java REST API Framework Comparison - PWX 2021
mraible
32
8.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Navigating Team Friction
lara
188
15k
Faster Mobile Websites
deanohume
308
31k
A designer walks into a library…
pauljervisheath
207
24k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Pragmatic Product Professional
lauravandoore
36
6.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
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