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
180
Scala製インタプリタをブラウザで動かす3分クッキング
Rikito Taniguchi
September 09, 2017
Tweet
Share
More Decks by Rikito Taniguchi
See All by Rikito Taniguchi
Scala to WebAssembly #scala_waiwai
tanishiking
0
760
Scala Days Madrid 2023 参加レポート
tanishiking
0
33
Tooling for Scala3
tanishiking
0
320
API-Based Code Search
tanishiking
0
34
Things happening before start coding with Metals ~behind the curtain of daily coding~
tanishiking
0
510
How we replaced a 10-year-old Perl product using Scala
tanishiking
14
32k
Quick introduction to scalafix
tanishiking
1
140
Format things with scalafmt
tanishiking
1
1.7k
トランザクション技術入門
tanishiking
0
120
Other Decks in Technology
See All in Technology
ChatworkのSRE部って実は 半分くらいPlatform Engineering部かもしれない
saramune
0
160
レガシーをぶっ壊せ。AEONで始めるDevRelの話 / Qiita Night 2024-2-22
aeonpeople
3
1.3k
Kernel MemoryでAzure OpenAI Serviceとお手軽データソース連携
mitsuzono
1
250
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
520
EMとして2023年度に頑張ったこと / What we did well in FY2023 as a EM
pauli
1
170
Além do else! Categorizando Pokemóns com Pattern Matching no JavaScript
wmsbill
0
620
Java EE/Jakarta EEの現状と将来―クラウドネイティブ時代にJava EEは対応できるのか?―
takakiyo
1
160
検証を通して見えてきたTiDBの性能特性
lycorptech_jp
PRO
6
3.8k
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
1
520
どうするコスト最適化のトレードオフ
tetsuyaooooo
1
520
今年のRubyKaigiはProfiler Year🤘
osyoyu
0
120
反実仮想機械学習とは何か
usaito
PRO
11
4.7k
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
124
8.5k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
GitHub's CSS Performance
jonrohan
1025
450k
Practical Orchestrator
shlominoach
182
9.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
6
1.5k
KATA
mclloyd
15
12k
A Philosophy of Restraint
colly
197
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
322
20k
Optimizing for Happiness
mojombo
370
69k
In The Pink: A Labor of Love
frogandcode
138
21k
Bash Introduction
62gerente
604
210k
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