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
Echo_itself_by__.pdf
Search
ライガー
March 30, 2024
Programming
68
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Echo_itself_by__.pdf
ライガー
March 30, 2024
More Decks by ライガー
See All by ライガー
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
600
Programming Viewing with Reserved Keywords
raiga0310
0
140
愛知県なんもないよね~www
raiga0310
0
62
クソコード鑑賞会
raiga0310
0
180
make HTTP server with Axum, Rust
raiga0310
0
160
Other Decks in Programming
See All in Programming
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
2
1.8k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
パーソナライズPodcastを作った話
repunit11
0
140
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
16k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
R8 の設定見直しでアプリサイズ削減
andpad
0
210
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
110
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
340
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
250
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
1
5.3M
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
740
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
470
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
320
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
How to build a perfect <img>
jonoalderson
1
6.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Site-Speed That Sticks
csswizardry
13
1.6k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Transcript
Echo itself by 🦀 Genkai LT #5 Generated by DALL-E3
Prompt: "自己言及するカニ"
Introduce raiga0310/AHOXA/ライガー Backend Rust/TypeScript/PHP https://profile.a6x.dev ***twitter***: @ahoxa1rx
Quineって知ってる?
Quine クワイン 自身のソースコードと同じ文字列を出力するコード 任意のプログラミング言語 [注]で実装できる 注:任意の計算可能な文字列を出力できるプログラミング言語にはクワインが存在する、別に チューリング完全である必要はない
Quineの例(C)
ナイーブな実装
長い
もう少し簡単な例
None
ナイーブなQuineのポイント このコードは「このコードは「 ...」を出力する」を出力する ↑のような再帰的な出力を考える …が無限に増えないように考える さっきの例だとプリプロセッサとマクロ展開を利用した実装 「出力部の前後」をどう出力するかとかが結構重要
きれいな(?)Quine
Haskell
Scheme & Common Lisp
HQ9+
ほんへ(Rust)
実装パターン • ナイーブな実装 ◦ フォーマットの出力形式を利用する • ズル(?) ◦ Built-inマクロを使います •
macro_rules!でオレオレマクロ ◦ 魔術 • Bling-Bang-Bang-Born • 他にもあるかもしれないけど自分で作って :heart:
ナイーブ実装
徐々に実装していく まず普通に出力してみる
このコードを入れてみる
このままだと再帰地獄なので、前後半に分ける
Rustのフォーマット記法 デバッグ記法を活用する format!系列(文字列に展開する系)の記法 https://doc.rust-lang.org/std/fmt/index.html#syntax
None
None
Rustのフォーマット記法 基本的には「{}」を使って順序で展開する 「{:?}」や「{:#?}」を使うとDebugトレイトの実装にしたがって展開される 「:」の前後で展開する際のオプションをつけれる 前に「数値」または「識別子」を入れるとそれを参照する
例
さっきの書きかけの実装をもう一度見てみる
この実装で足りない部分 愚直実装なのでこのままだと無限引数が生える • 『引数の数を減らす』『Quineの要件を満たす』両方やる →さっきのパラメータ参照するフォーマット記法を使う (+エスケープ記法もつかうのでデバッグ形式を使う )
実装(formatかかったのはゆるして)
ズル(?)な実装
include_str!()がズル ファイルの内容自体を取得できる Quineのためにあると行っても過言ではない (は?)
macro_rules!を使う
macro_rules! 文法拡張記法 = 黒魔術 ルールにマッチするパターンを別の値・式に変換する
縁の下の力持ちなのだが...... Actix-webのルーティング記法、Serenityのコマンド、#[tokio::main]などなど 標準出力のprint!()系の可変長引数を受容できる仕組みもマクロによるもの 実装によっては危惧されるべき動作を起こしやすい 気をつけて実装しようね(臆病すぎるのもあれだけど )
あとはナイーブな実装とほぼ同じ 注意するポイント format!系マクロでの{}のエスケープは2重にすること「{{」「}}」とか(1敗) 出力したあとに使えるようにするにはエスケープを残したいので {:?}をつかおうね(2敗)
まずコード自体を素直に入れてみる
オレ自身がフォーマッタになることだ
おまけ:Bling-Bang-Bang-Born
pelmers/quine参照
なにこれ 後半のコードの文字をすべて ASCIIで配列表現したものをcharにキャストして出力する力技
AAもあるよ なに食べたらひらめくの? https://rosettacode.org/wiki/Quine#Rust
Thx for listening ;)
おまけ https://x.com/mathlava/status/1762633882443411920?s=20