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
340
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
220
Other Decks in Technology
See All in Technology
Microsoft Build 2025 技術/製品動向 for Microsoft Startup Tech Community
torumakabe
2
250
標準技術と独自システムで作る「つらくない」SaaS アカウント管理 / Effortless SaaS Account Management with Standard Technologies & Custom Systems
yuyatakeyama
3
1.2k
Agentic Workflowという選択肢を考える
tkikuchi1002
1
470
製造業からパッケージ製品まで、あらゆる領域をカバー!生成AIを利用したテストシナリオ生成 / 20250627 Suguru Ishii
shift_evolve
PRO
1
120
Windows 11 で AWS Documentation MCP Server 接続実践/practical-aws-documentation-mcp-server-connection-on-windows-11
emiki
0
900
_第3回__AIxIoTビジネス共創ラボ紹介資料_20250617.pdf
iotcomjpadmin
0
150
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
110
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
1
160
ハノーバーメッセ2025座談会.pdf
iotcomjpadmin
0
160
GitHub Copilot の概要
tomokusaba
1
130
Model Mondays S2E02: Model Context Protocol
nitya
0
210
OpenHands🤲にContributeしてみた
kotauchisunsun
1
390
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
69
11k
Designing for Performance
lara
609
69k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.6k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
The Invisible Side of Design
smashingmag
299
51k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Gamification - CAS2011
davidbonilla
81
5.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
For a Future-Friendly Web
brad_frost
179
9.8k
Automating Front-end Workflow
addyosmani
1370
200k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
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