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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Capture Checking / Separation Checking 入門
tanishiking
0
440
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
460
Scala meets WebAssembly
tanishiking
0
870
Why Wasm+WASI for Scala
tanishiking
0
130
Scala to WebAssembly: Exploring the How and Why
tanishiking
1
1.8k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.8k
Scala Days Madrid 2023 参加レポート
tanishiking
0
94
Tooling for Scala3
tanishiking
0
420
API-Based Code Search
tanishiking
0
89
Other Decks in Technology
See All in Technology
Codex 5.3 と Opus 4.6 にコーポレートサイトを作らせてみた / Codex 5.3 vs Opus 4.6
ama_ch
0
220
GitHub Issue Templates + Coding Agentで簡単みんなでIaC/Easy IaC for Everyone with GitHub Issue Templates + Coding Agent
aeonpeople
1
260
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
SRE Enabling戦記 - 急成長する組織にSREを浸透させる戦いの歴史
markie1009
0
170
OCI Database Management サービス詳細
oracle4engineer
PRO
1
7.4k
Oracle AI Database移行・アップグレード勉強会 - RAT活用編
oracle4engineer
PRO
0
110
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
93k
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
3
230
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
12
5.6k
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
130
日本の85%が使う公共SaaSは、どう育ったのか
taketakekaho
1
250
ランサムウェア対策としてのpnpm導入のススメ
ishikawa_satoru
0
230
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
14k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
The browser strikes back
jonoalderson
0
420
How to train your dragon (web standard)
notwaldorf
97
6.5k
The Limits of Empathy - UXLibs8
cassininazir
1
220
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
440
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
50k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
The World Runs on Bad Software
bkeepers
PRO
72
12k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
53
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
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