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
230
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
150
Capture Checking / Separation Checking 入門
tanishiking
0
520
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
700
Scala meets WebAssembly
tanishiking
0
930
Why Wasm+WASI for Scala
tanishiking
0
130
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
430
Other Decks in Technology
See All in Technology
AI時代における技術的負債への取り組み
codenote
1
1.3k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
290
Bill One 開発エンジニア 紹介資料
sansan33
PRO
6
18k
みんなの「データ活用」を支えるストレージ担当から持ち込むAWS活用/コミュニティー設計TIPS 10選~「作れる」より、「続けられる」設計へ~
yoshiki0705
0
240
AI時代のガードレールとしてのAPIガバナンス
nagix
0
220
AWS DevOps Agentはチームメイトになれるのか?/ Can AWS DevOps Agent become a teammate
kinunori
6
690
60分で学ぶ最新Webフロントエンド
mizdra
PRO
34
18k
マルチプロダクトの信頼性を効率良く保っていくために
kworkdev
PRO
0
150
AzureのIaC管理からログ調査まで、随所に役立つSkillsとCustom-Instructions / Boosting IaC and Log Analysis with Skills
aeonpeople
0
210
データを"持てない"環境でのアノテーション基盤設計
sansantech
PRO
1
110
明日からドヤれる!超マニアックなAWSセキュリティTips10連発 / 10 Ultra-Niche AWS Security Tips
yuj1osm
0
560
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The browser strikes back
jonoalderson
0
970
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
350
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
230
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Spectacular Lies of Maps
axbom
PRO
1
700
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
240
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
260
Ethics towards AI in product and experience design
skipperchong
2
260
Believing is Seeing
oripsolob
1
110
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