$30 off During Our Annual Pro Sale. View Details »
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
Capture Checking / Separation Checking 入門
tanishiking
0
270
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
300
Scala meets WebAssembly
tanishiking
0
790
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.7k
Scala Days Madrid 2023 参加レポート
tanishiking
0
90
Tooling for Scala3
tanishiking
0
420
API-Based Code Search
tanishiking
0
76
Other Decks in Technology
See All in Technology
Challenging Hardware Contests with Zephyr and Lessons Learned
iotengineer22
0
180
[デモです] NotebookLM で作ったスライドの例
kongmingstrap
0
140
AWS CLIの新しい認証情報設定方法aws loginコマンドの実態
wkm2
6
710
AI 駆動開発勉強会 フロントエンド支部 #1 w/あずもば
1ftseabass
PRO
0
340
Lessons from Migrating to OpenSearch: Shard Design, Log Ingestion, and UI Decisions
sansantech
PRO
1
120
Snowflakeでデータ基盤を もう一度作り直すなら / rebuilding-data-platform-with-snowflake
pei0804
4
1.4k
寫了幾年 Code,然後呢?軟體工程師必須重新認識的 DevOps
cheng_wei_chen
1
1.3k
AWS Trainium3 をちょっと身近に感じたい
bigmuramura
1
140
今年のデータ・ML系アップデートと気になるアプデのご紹介
nayuts
1
290
RAG/Agent開発のアップデートまとめ
taka0709
0
160
生成AI時代におけるグローバル戦略思考
taka_aki
0
130
「Managed Instances」と「durable functions」で広がるAWS Lambdaのユースケース
lamaglama39
0
300
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Six Lessons from altMBA
skipperchong
29
4.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Context Engineering - Making Every Token Count
addyosmani
9
500
Building Adaptive Systems
keathley
44
2.9k
Facilitating Awesome Meetings
lara
57
6.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
How to train your dragon (web standard)
notwaldorf
97
6.4k
For a Future-Friendly Web
brad_frost
180
10k
Raft: Consensus for Rubyists
vanstee
141
7.2k
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