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
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
200
Scala meets WebAssembly
tanishiking
0
690
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
87
Tooling for Scala3
tanishiking
0
410
API-Based Code Search
tanishiking
0
65
Things happening before start coding with Metals ~behind the curtain of daily coding~
tanishiking
0
620
Other Decks in Technology
See All in Technology
DMMの検索システムをSolrからElasticCloudに移行した話
hmaa_ryo
0
310
InsightX 会社説明資料/ Company deck
insightx
0
130
AIとの協業で実現!レガシーコードをKotlinらしく生まれ変わらせる実践ガイド
zozotech
PRO
2
210
re:Inventに行くまでにやっておきたいこと
nagisa53
0
840
AWS DMS で SQL Server を移行してみた/aws-dms-sql-server-migration
emiki
0
270
AI連携の新常識! 話題のMCPをはじめて学ぶ!
makoakiba
0
170
入院医療費算定業務をAIで支援する:包括医療費支払い制度とDPCコーディング (公開版)
hagino3000
0
130
個人でデジタル庁の デザインシステムをVue.jsで 作っている話
nishiharatsubasa
3
5.3k
[Journal club] Thinking in Space: How Multimodal Large Language Models See, Remember, and Recall Spaces
keio_smilab
PRO
0
100
データとAIで明らかになる、私たちの課題 ~Snowflake MCP,Salesforce MCPに触れて~ / Data and AI Insights
kaonavi
0
210
AI駆動で進める依存ライブラリ更新 ─ Vue プロジェクトの品質向上と開発スピード改善の実践録
sayn0
1
370
Raycast AI APIを使ってちょっと便利なAI拡張機能を作ってみた
kawamataryo
0
230
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Testing 201, or: Great Expectations
jmmastey
46
7.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building Adaptive Systems
keathley
44
2.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Keith and Marios Guide to Fast Websites
keithpitt
412
23k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
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