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
650
Why Wasm+WASI for Scala
tanishiking
0
120
Scala to WebAssembly: Exploring the How and Why
tanishiking
1
1.7k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.7k
Scala Days Madrid 2023 参加レポート
tanishiking
0
86
Tooling for Scala3
tanishiking
0
410
API-Based Code Search
tanishiking
0
64
Things happening before start coding with Metals ~behind the curtain of daily coding~
tanishiking
0
610
How we replaced a 10-year-old Perl product using Scala
tanishiking
14
34k
Other Decks in Technology
See All in Technology
サイバーエージェント流クラウドコスト削減施策「みんなで金塊堀太郎」
kurochan
3
1.5k
LLM時代にデータエンジニアの役割はどう変わるか?
ikkimiyazaki
6
1.4k
AWS Top Engineer、浮いてませんか? / As an AWS Top Engineer, Are You Out of Place?
yuj1osm
2
210
『バイトル』CTOが語る! AIネイティブ世代と切り拓くモノづくり組織
dip_tech
PRO
1
120
アイテムレビュー機能導入からの学びと改善
zozotech
PRO
0
150
Node.js 2025: What's new and what's next
ruyadorno
0
260
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
310
業務効率化をさらに加速させる、ノーコードツールとStep Functionsのハイブリッド化
smt7174
2
140
いまからでも遅くない!SSL/TLS証明書超入門(It's not too late to start! SSL/TLS Certificates: The Absolute Beginner's Guide)
norimuraz
0
230
オープンソースでどこまでできる?フォーマル検証チャレンジ
msyksphinz
0
140
BI ツールはもういらない?Amazon RedShift & MCP Server で試みる新しいデータ分析アプローチ
cdataj
0
160
プレーリーカードを活用しよう❗❗デジタル名刺交換からはじまるイベント会場交流のススメ
tsukaman
0
150
Featured
See All Featured
It's Worth the Effort
3n
187
28k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Automating Front-end Workflow
addyosmani
1371
200k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
980
Build your cross-platform service in a week with App Engine
jlugia
232
18k
How to Ace a Technical Interview
jacobian
280
24k
Practical Orchestrator
shlominoach
190
11k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Producing Creativity
orderedlist
PRO
347
40k
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