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
Scala製インタプリタをブラウザで動かす3分クッキング
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Rikito Taniguchi
September 09, 2017
Technology
240
1
Share
Scala製インタプリタをブラウザで動かす3分クッキング
Rikito Taniguchi
September 09, 2017
More Decks by Rikito Taniguchi
See All by Rikito Taniguchi
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
160
Capture Checking / Separation Checking 入門
tanishiking
0
540
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
710
Scala meets WebAssembly
tanishiking
0
950
Why Wasm+WASI for Scala
tanishiking
0
140
Scala to WebAssembly: Exploring the How and Why
tanishiking
1
1.9k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.9k
Scala Days Madrid 2023 参加レポート
tanishiking
0
100
Tooling for Scala3
tanishiking
0
440
Other Decks in Technology
See All in Technology
AIが自律的に働く時代へ Amazon Quick で実現するAIエージェント紹介
koheiyoshikawa
0
200
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8k
ボトムアップ限界を越える - 20チームを束る "Drive Map" / Beyond Bottom-Up: A 'Drive Map' for 20 Teams
kaonavi
0
170
ServiceによるKubernetes通信制御ーClusterIPを例に
miku01
1
160
Claude Code / Codex / Kiro に AWS 権限を 渡すとき、何を設計すべきか
k_adachi_01
3
560
サンプリングは「作る」のか「使う」のか? 分散トレースのコストと運用を両立する実践的戦略 / Why you need the tail sampling and why you don't want it
ymotongpoo
3
150
エンタープライズの厳格な制約を開発者に意識させない:クラウドネイティブ開発基盤設計/cloudnative-kaigi-golden-path
mhrtech
0
380
Agent Skillsで実現する記憶領域の運用とその後
yamadashy
2
1.6k
Digital Independence: Why, When and How
wannesrams
0
310
セキュリティ対策、何からはじめる? CloudNative環境の脅威モデリングと リスク評価実践入門 #cloudnativekaigi
varu3
2
580
毎日の作業を Claude Code 経由にしたら、 ノウハウがコードになった
kossykinto
1
1.2k
そのSLO 99.9%、本当に必要ですか? 〜優先度付きSLOによる責任共有の設計思想〜 / Is that 99.9% SLO really necessary? Design philosophy of shared responsibility through prioritized SLOs
vtryo
0
490
Featured
See All Featured
Music & Morning Musume
bryan
47
7.2k
RailsConf 2023
tenderlove
30
1.4k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
510
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Between Models and Reality
mayunak
3
280
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Limits of Empathy - UXLibs8
cassininazir
1
320
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
350
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
690
Transcript
Scala 製インタプリタをブラウザで動かす 3 分クッ キング id:tanishiking24 Scala 関西 Summit2017 1
こんにちは • • twitter @tanishiking • id:tanishiking24 • Web アプリケーションエンジニア@はてな
• 主に Scala、たまに TypeScript/Perl 2
今日作るもの • https://github.com/tanishiking/MLScala 3
手順 • インタプリタを作る • Scala.js でビルドする • UI を書く •
完成! 4
インタプリタを作る このあたりを参考に頑張る • https://github.com/ksuenaga/IoPLMaterials • http://esumii.github.io/min-caml/ パーサコンビネータに fastparse 使った 5
インタプリタを作る こちらにあらかじめ作ったものが 6
Scala.js でビルドする 公式ドキュメントを参考に build.sbt をいじる • crossProject で shared,js,jvm 用にプロジェクト分ける
• コアロジックは shared 以下につっこむ、雑に全部ごっちゃに すると sbt test が動かなくなったり • https://github.com/scala-js/scala-js/issues/739 7
Scala.js でビルドする • export するモジュールやメソッドを annotation で指定 • プログラムの文字列を入力として print
メソッドに渡した値の 文字列を返す簡素な API import scalajs.js.annotation._ @JSExportTopLevel(”ML”) object Interpreter { @JSExport def interpret(input: String): String = { // ... 8
UI を作る • ビルド成果物の JS を雑に読み込んで、さっき export したメ ソッドを実行したらなんか動く •
標準出力は console に出てくる ... <script src=”./js/target/scala-2.12/mlscala-fastopt.js”></scrip ... <script> const result = ML.interpret('let x = 1 in print x;;'); </script> 評価結果を適当な div につっこんで表示する感じで 9
完成!! http://tanishiking.github.io/MLScala/ 10
まとめ • 普通に動いてすごい • 面白 AltJS くらいの印象だったけど Scala 製モジュールのデモ に良さそう
• ブラウザで動かしたいけど JS で書きたくないモジュールある よね 11