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
210
Scala製インタプリタをブラウザで動かす3分クッキング
Rikito Taniguchi
September 09, 2017
Tweet
Share
More Decks by Rikito Taniguchi
See All by Rikito Taniguchi
Why Wasm+WASI for Scala
tanishiking
0
83
Scala to WebAssembly: Exploring the How and Why
tanishiking
0
1.5k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.4k
Scala Days Madrid 2023 参加レポート
tanishiking
0
70
Tooling for Scala3
tanishiking
0
380
API-Based Code Search
tanishiking
0
43
Things happening before start coding with Metals ~behind the curtain of daily coding~
tanishiking
0
580
How we replaced a 10-year-old Perl product using Scala
tanishiking
14
33k
Quick introduction to scalafix
tanishiking
1
190
Other Decks in Technology
See All in Technology
30分でわかる『アジャイルデータモデリング』
hanon52_
9
2.7k
【Developers Summit 2025】プロダクトエンジニアから学ぶ、 ユーザーにより高い価値を届ける技術
niwatakeru
2
1.4k
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
6.2k
技術負債の「予兆検知」と「状況異変」のススメ / Technology Dept
i35_267
1
1.1k
株式会社EventHub・エンジニア採用資料
eventhub
0
4.3k
君も受託系GISエンジニアにならないか
sudataka
2
430
トラシューアニマルになろう ~開発者だからこそできる、安定したサービス作りの秘訣~
jacopen
2
2k
Nekko Cloud、 これまでとこれから ~学生サークルが作る、 小さなクラウド
logica0419
2
960
リアルタイム分析データベースで実現する SQLベースのオブザーバビリティ
mikimatsumoto
0
1.3k
データ資産をシームレスに伝達するためのイベント駆動型アーキテクチャ
kakehashi
PRO
2
530
2/18/25: Java meets AI: Build LLM-Powered Apps with LangChain4j
edeandrea
PRO
0
110
Oracle Cloud Infrastructure:2025年2月度サービス・アップデート
oracle4engineer
PRO
1
210
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
44
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
A Tale of Four Properties
chriscoyier
158
23k
How to train your dragon (web standard)
notwaldorf
91
5.8k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Why Our Code Smells
bkeepers
PRO
336
57k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
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