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
400
API-Based Code Search
tanishiking
0
53
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
KubeCon + CloudNativeCon Japan 2025 Recap by CA
ponkio_o
PRO
0
260
AWS Organizations 新機能!マルチパーティ承認の紹介
yhana
1
230
AI専用のリンターを作る #yumemi_patch
bengo4com
5
2.3k
Model Mondays S2E03: SLMs & Reasoning
nitya
0
240
SpringBoot x TestContainerで実現するポータブル自動結合テスト
demaecan
0
130
Geminiとv0による高速プロトタイピング
shinya337
0
200
さくらのIaaS基盤のモニタリングとOpenTelemetry/OSC Hokkaido 2025
fujiwara3
2
280
ドメイン特化なCLIPモデルとデータセットの紹介
tattaka
2
540
作曲家がボカロを使うようにPdMはAIを使え
itotaxi
0
400
AWS テクニカルサポートとエンドカスタマーの中間地点から見えるより良いサポートの活用方法
kazzpapa3
3
620
CursorによるPMO業務の代替 / Automating PMO Tasks with Cursor
motoyoshi_kakaku
2
830
無意味な開発生産性の議論から抜け出すための予兆検知とお金とAI
i35_267
2
4.7k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
730
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
VelocityConf: Rendering Performance Case Studies
addyosmani
331
24k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
GraphQLとの向き合い方2022年版
quramy
49
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Testing 201, or: Great Expectations
jmmastey
42
7.6k
The Language of Interfaces
destraynor
158
25k
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