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
Rikito Taniguchi
September 09, 2017
Technology
1
220
Scala製インタプリタをブラウザで動かす3分クッキング
Rikito Taniguchi
September 09, 2017
Tweet
Share
More Decks by Rikito Taniguchi
See All by Rikito Taniguchi
Scala meets WebAssembly
tanishiking
0
540
Why Wasm+WASI for Scala
tanishiking
0
110
Scala to WebAssembly: Exploring the How and Why
tanishiking
0
1.7k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.6k
Scala Days Madrid 2023 参加レポート
tanishiking
0
83
Tooling for Scala3
tanishiking
0
410
API-Based Code Search
tanishiking
0
55
Things happening before start coding with Metals ~behind the curtain of daily coding~
tanishiking
0
600
How we replaced a 10-year-old Perl product using Scala
tanishiking
14
33k
Other Decks in Technology
See All in Technology
第64回コンピュータビジョン勉強会「The PanAf-FGBG Dataset: Understanding the Impact of Backgrounds in Wildlife Behaviour Recognition」
x_ttyszk
0
130
マルチプロダクト環境におけるSREの役割 / SRE NEXT 2025 lunch session
sugamasao
1
220
LLM時代の検索
shibuiwilliam
2
620
AWS CDK 開発を成功に導くトラブルシューティングガイド
wandora58
3
140
Copilot coding agentにベットしたいCTOが開発組織で取り組んだこと / GitHub Copilot coding agent in Team
tnir
0
120
スタートアップに選択肢を 〜生成AIを活用したセカンダリー事業への挑戦〜
nstock
0
270
大量配信システムにおけるSLOの実践:「見えない」信頼性をSLOで可視化
plaidtech
PRO
0
260
20250707-AI活用の個人差を埋めるチームづくり
shnjtk
6
4.1k
Operating Operator
shhnjk
1
640
【LT会登壇資料】TROCCO新コネクタ「スマレジ」を活用した直営店データの分析
kazari0425
1
140
SREの次のキャリアの道しるべ 〜SREがマネジメントレイヤーに挑戦して、 気づいたこととTips〜
coconala_engineer
1
590
成長し続けるアプリのためのテストと設計の関係、そして意思決定の記録。
sansantech
PRO
0
140
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
173
14k
How to Think Like a Performance Engineer
csswizardry
25
1.7k
The Invisible Side of Design
smashingmag
301
51k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Done Done
chrislema
184
16k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Code Reviewing Like a Champion
maltzj
524
40k
Faster Mobile Websites
deanohume
307
31k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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