From ed124a759765c392b4d1d441bfad34cccc8067d7 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sun, 15 Nov 2026 23:50:40 +0100 Subject: [PATCH] playground v0.18.0: Julia cells run in the page; the blurbs and the Julia example follow playground/go.mod pins go-notebook/playground v0.18.0 (go-notebook v0.20.0, go-embedded-julia v0.17.0, go-embedded-fortran v0.24.1 follow). hugo.toml's playground and notebook blurbs say Julia runs in the page, in a third core loaded on first use. playground/notebooks/4-julia.md is the playground's own example. The workflow already serves everything cmd/build writes (the Julia core and its image included); its comment says so. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/hugo.yml | 5 ++++- hugo.toml | 6 +++--- playground/go.mod | 10 ++++++---- playground/go.sum | 20 +++++++++++-------- playground/notebooks/4-julia.md | 34 ++++++++++++++++++++++----------- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index 03a025f..084da7d 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -71,7 +71,10 @@ jobs: --baseURL "${{ steps.pages.outputs.base_url }}/" # The playground: the page, its example notebooks and the WebAssembly - # cores (Go, and Go with Ruby), built here from the + # cores (Go; Go with Ruby, R and Fortran; and that with Julia, with its + # compressed Base image, which the page fetches only when a Julia cell is + # run: cmd/build writes them all into the output directory, so everything + # in ../public/playground is served), built here from the # go-notebook/playground version that playground/go.mod pins (never a # committed binary). The build runs every notebook first and fails if a # cell fails. diff --git a/hugo.toml b/hugo.toml index 15fe631..4663724 100644 --- a/hugo.toml +++ b/hugo.toml @@ -49,7 +49,7 @@ disableKinds = ['taxonomy', 'term', 'rss', 'sitemap', '404'] title = "Go and Ruby cells, and what they printed" [[params.hero.cards]] title = "Try it in your browser" - text = "The playground runs notebooks, Go, Ruby and R cells, in WebAssembly in the tab: edit a cell, press Ctrl+Enter, see the result." + text = "The playground runs notebooks, Go, Ruby, R, Fortran and Julia cells, in WebAssembly in the tab: edit a cell, press Ctrl+Enter, see the result." href = "/playground/" more = "Open the playground" @@ -59,12 +59,12 @@ disableKinds = ['taxonomy', 'term', 'rss', 'sitemap', '404'] name = "notebook" kind = "kernel · command" href = "https://github.com/go-notebook/notebook" - blurb = "The kernel, the notebook command (run, html, watch, serve, irb) and the HTML export: format parses the Markdown, analysis builds the dependency graph from the syntax, gen writes the Go program, kernel compiles and drives it through runtime and keeps results and values, export writes the page. Ruby cells (```ruby) run on rbgo, a Ruby written in Go, with the go-scikit bindings (Stats, Special, Optimize, Integrate, DataFrame, Plot, NDArray), and share their variables with the Go cells. --timeout and --memory stop a runaway cell in either language. notebook irb is the same Ruby as an interactive session, as irb: => inspect after each input, _, multi-line input decided by rbgo's parser, Tab completion and history in a pure-Go line editor (go-ruby-reline), each input in a worker that --timeout, --memory or Ctrl-C can stop without losing the prompt, and --save to keep the session as a notebook. More → Julia cells (```julia) are parsed with go-embedded-julia's parser and checked (syntax errors at their line with julia's message, names in the dependency graph under Julia's scope rules), and, since go-notebook v0.18.0, run by its interpreter (v0.17.0, since go-notebook v0.19.0) in one kernel shared by the Julia cells: a global or a function a cell defines is there in the next one, a top-level loop updates a global as in IJulia (55 for a sum of 1 to 10), and a failure, a MethodError included, is julia's own text. The kernel boots from a prebuilt Base image, fetched on the first Julia cell and loaded only if its SHA-256 is the pinned one (cold start about a second). A cell may run 30 s and 50 million statements, within a memory budget of 512 MiB counted as 16 bytes per array element (a floor, not the heap: strings are not counted, and one array may have at most 2^24 elements). Julia variables cross with Go cells in both directions (Int64, Float64, Bool, String, and vectors and matrices of Float64 or Int64; Go int and []int as Int64): a Julia value of another type stays in Julia and the Go reader is deferred, naming the type, and a Go value Julia cannot take fails the Julia cell. Inputs are measured before any copy (2^24 elements per array, a cell's inputs together within its memory limit, so a cell can hold up to twice its limit). This breaks v0.18.0, where Julia variables were not shared. Known limitations: a Float64 A * x needs BLAS (go-embedded-julia#67), a non-ASCII uppercase needs utf8proc (#65), and Get refuses an n×0 matrix (#76). The playground checks Julia cells and does not run them (Julia cells run in go-notebook, not yet in the browser). More → R cells (```r) are parsed with go-embedded-r's parser, identical to R 4.6.2 on R's own sources, and checked in the same way: syntax errors at their line in R's words, names in the graph, and a cell that cannot be analysed from its text (<<-, eval, library) depending on every cell above it. They run on go-embedded-r's evaluator in one shared environment (v0.10.0), and since v0.12.0 each cell is bounded: 512 MiB of vectors, 50 million steps, 30 s. The browser playground runs them too (playground v0.15.0), in its second core, with R variables kept apart from the other languages: 512 MiB, 20 million steps, 10 s per cell, and a crash restarts the core with a message on the cell. More → Fortran cells (```fortran) are checked and run with go-embedded-fortran (since go-notebook v0.17.0, go-embedded-fortran v0.17.0: its sema session for the names and errors, its eval.Session for the running; free form, implicit typing off) and highlighted with go-rouge's fortran lexer. The Fortran cells share one session: a cell sees the variables (with the values the earlier cells left), procedures, modules and derived types of the Fortran cells before it. Fortran variables stay in Fortran, as R's do: they are not shared with Go, Ruby, Julia, R or C cells in either direction yet. A cell may make at most 2^32 loop iterations and calls and run 30 s, and a failure is reported at its line and column. The browser playground runs them too (playground v0.16.0), in its second core, with Fortran variables kept apart from the other languages: 200 million steps and 10 s per cell, and an endless do ends with a message and leaves the page usable. More →" + blurb = "The kernel, the notebook command (run, html, watch, serve, irb) and the HTML export: format parses the Markdown, analysis builds the dependency graph from the syntax, gen writes the Go program, kernel compiles and drives it through runtime and keeps results and values, export writes the page. Ruby cells (```ruby) run on rbgo, a Ruby written in Go, with the go-scikit bindings (Stats, Special, Optimize, Integrate, DataFrame, Plot, NDArray), and share their variables with the Go cells. --timeout and --memory stop a runaway cell in either language. notebook irb is the same Ruby as an interactive session, as irb: => inspect after each input, _, multi-line input decided by rbgo's parser, Tab completion and history in a pure-Go line editor (go-ruby-reline), each input in a worker that --timeout, --memory or Ctrl-C can stop without losing the prompt, and --save to keep the session as a notebook. More → Julia cells (```julia) are parsed with go-embedded-julia's parser and checked (syntax errors at their line with julia's message, names in the dependency graph under Julia's scope rules), and, since go-notebook v0.18.0, run by its interpreter (v0.17.0, since go-notebook v0.19.0) in one kernel shared by the Julia cells: a global or a function a cell defines is there in the next one, a top-level loop updates a global as in IJulia (55 for a sum of 1 to 10), and a failure, a MethodError included, is julia's own text. The kernel boots from a prebuilt Base image, fetched on the first Julia cell and loaded only if its SHA-256 is the pinned one (cold start about a second). A cell may run 30 s and 50 million statements, within a memory budget of 512 MiB counted as 16 bytes per array element (a floor, not the heap: strings are not counted, and one array may have at most 2^24 elements). Julia variables cross with Go cells in both directions (Int64, Float64, Bool, String, and vectors and matrices of Float64 or Int64; Go int and []int as Int64): a Julia value of another type stays in Julia and the Go reader is deferred, naming the type, and a Go value Julia cannot take fails the Julia cell. Inputs are measured before any copy (2^24 elements per array, a cell's inputs together within its memory limit, so a cell can hold up to twice its limit). This breaks v0.18.0, where Julia variables were not shared. Known limitations: a Float64 A * x needs BLAS (go-embedded-julia#67), a non-ASCII uppercase needs utf8proc (#65), and Get refuses an n×0 matrix (#76). The browser playground runs them too (playground v0.18.0), in a third core that the page loads only when a Julia cell is first run (about 28 MB and about 20 s), with Julia variables kept apart from Go's: 512 MiB, 20 million statements and 20 s per cell, and a new worker after each Julia run. More → R cells (```r) are parsed with go-embedded-r's parser, identical to R 4.6.2 on R's own sources, and checked in the same way: syntax errors at their line in R's words, names in the graph, and a cell that cannot be analysed from its text (<<-, eval, library) depending on every cell above it. They run on go-embedded-r's evaluator in one shared environment (v0.10.0), and since v0.12.0 each cell is bounded: 512 MiB of vectors, 50 million steps, 30 s. The browser playground runs them too (playground v0.15.0), in its second core, with R variables kept apart from the other languages: 512 MiB, 20 million steps, 10 s per cell, and a crash restarts the core with a message on the cell. More → Fortran cells (```fortran) are checked and run with go-embedded-fortran (since go-notebook v0.17.0, go-embedded-fortran v0.17.0: its sema session for the names and errors, its eval.Session for the running; free form, implicit typing off) and highlighted with go-rouge's fortran lexer. The Fortran cells share one session: a cell sees the variables (with the values the earlier cells left), procedures, modules and derived types of the Fortran cells before it. Fortran variables stay in Fortran, as R's do: they are not shared with Go, Ruby, Julia, R or C cells in either direction yet. A cell may make at most 2^32 loop iterations and calls and run 30 s, and a failure is reported at its line and column. The browser playground runs them too (playground v0.16.0), in its second core, with Fortran variables kept apart from the other languages: 200 million steps and 10 s per cell, and an endless do ends with a message and leaves the page usable. More →" [[params.repos]] name = "playground" kind = "wasm · page" href = "https://github.com/go-notebook/playground" - blurb = "A notebook in the browser, with no server. The page shows the prose as text and each code cell as a syntax-highlighting editor in Go Mono at 13 px, with a minimap on its right (a click moves the caret) and line annotations, a gutter marker and an inline panel on Ctrl+Shift+M, saved in the Markdown as a gonb:notes comment (a plain text box if the editor fails to load); Ctrl+Enter runs the whole notebook again in the tab. A Go interpreter (yaegi) compiled to WebAssembly runs the cells, while the libraries they import — go-statistics, go-numerics, go-ndarray, go-plot — run compiled: only the notebook's own code is interpreted. Each run posts the whole notebook to a Web Worker and gets every cell's results back, one call in and one string out, so a long run neither freezes the page nor costs a call per widget. Ruby cells run there too, in rbgo with the go-scikit bindings: the page fetches the Ruby core only when the notebook has a Ruby cell. R cells run there too, on go-embedded-r, in the second core (about 4.5 MB larger), bounded to 512 MiB, 20 million steps and 10 s. Julia cells are parsed and checked there, with their badge saying not runnable yet. Nothing reaches the network or a file system, and every figure goes through an allowlist SVG sanitizer. Deployed as /playground/ here, with notebooks about the notebook itself, and on go-statistics and go-numerics." + blurb = "A notebook in the browser, with no server. The page shows the prose as text and each code cell as a syntax-highlighting editor in Go Mono at 13 px, with a minimap on its right (a click moves the caret) and line annotations, a gutter marker and an inline panel on Ctrl+Shift+M, saved in the Markdown as a gonb:notes comment (a plain text box if the editor fails to load); Ctrl+Enter runs the whole notebook again in the tab. A Go interpreter (yaegi) compiled to WebAssembly runs the cells, while the libraries they import — go-statistics, go-numerics, go-ndarray, go-plot — run compiled: only the notebook's own code is interpreted. Each run posts the whole notebook to a Web Worker and gets every cell's results back, one call in and one string out, so a long run neither freezes the page nor costs a call per widget. Ruby cells run there too, in rbgo with the go-scikit bindings: the page fetches the Ruby core only when the notebook has a Ruby cell. R cells run there too, on go-embedded-r, in the second core (about 4.5 MB larger), bounded to 512 MiB, 20 million steps and 10 s. Julia cells run there too, on go-embedded-julia, in a third core and its Base image that the page fetches only when a Julia cell is run (about 28 MB and about 20 s the first time, shown on the cell), bounded to 512 MiB, 20 million statements and 20 s, with their variables kept apart from Go's. Nothing reaches the network or a file system, and every figure goes through an allowlist SVG sanitizer. Deployed as /playground/ here, with notebooks about the notebook itself, and on go-statistics and go-numerics." [[params.repos]] name = "docs" kind = "site" diff --git a/playground/go.mod b/playground/go.mod index f69d8d4..f23ade5 100644 --- a/playground/go.mod +++ b/playground/go.mod @@ -2,7 +2,7 @@ module github.com/go-notebook/go-notebook.github.io/playground go 1.27.4 -require github.com/go-notebook/playground v0.16.0 +require github.com/go-notebook/playground v0.18.0 require ( filippo.io/age v1.3.2 // indirect @@ -69,6 +69,7 @@ require ( github.com/fxamacker/cbor/v2 v2.9.4 // indirect github.com/go-asn1-ber/asn1-ber v1.5.8 // indirect github.com/go-augeas/augeas v0.0.0-20260830115849-a0db83a6594a // indirect + github.com/go-bignum/bigfloat v0.2.0 // indirect github.com/go-commonmark/commonmark v0.1.0 // indirect github.com/go-composites/array v0.0.0-20261015235938-f7161fa2d065 // indirect github.com/go-composites/bag v0.0.0-20261017234052-8c0542744097 // indirect @@ -80,8 +81,8 @@ require ( github.com/go-dataframe/dataframe v0.1.0 // indirect github.com/go-datetime/dates v0.2.0 // indirect github.com/go-embedded-c/c v0.2.1 // indirect - github.com/go-embedded-fortran/fortran v0.17.0 // indirect - github.com/go-embedded-julia/julia v0.15.0 // indirect + github.com/go-embedded-fortran/fortran v0.24.1 // indirect + github.com/go-embedded-julia/julia v0.17.0 // indirect github.com/go-embedded-r/r v0.17.1 // indirect github.com/go-embedded-r/tre v0.1.3 // indirect github.com/go-embedded-ruby/ruby v0.8.5 // indirect @@ -107,7 +108,7 @@ require ( github.com/go-mustache/mustache v0.1.0 // indirect github.com/go-ndarray/ndarray v0.40.3 // indirect github.com/go-nokogiri/nokogiri v0.1.0 // indirect - github.com/go-notebook/notebook v0.18.0 // indirect + github.com/go-notebook/notebook v0.20.0 // indirect github.com/go-numerics/integrate v0.2.0 // indirect github.com/go-numerics/optimize v0.3.1 // indirect github.com/go-numerics/special v0.2.0 // indirect @@ -118,6 +119,7 @@ require ( github.com/go-plot/plot v0.1.1 // indirect github.com/go-puppet/puppet v0.0.0-20260918012035-fc6b0424cdbd // indirect github.com/go-regexp/engine v0.4.2 // indirect + github.com/go-regexp/pcre2 v0.1.0 // indirect github.com/go-richdoc/richdoc v0.7.0 // indirect github.com/go-rouge/rouge v0.9.0 // indirect github.com/go-ruby-aasm/aasm v0.0.0-20261025185733-ae3deccc721d // indirect diff --git a/playground/go.sum b/playground/go.sum index 026f7d2..a6a59b9 100644 --- a/playground/go.sum +++ b/playground/go.sum @@ -182,6 +182,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.8 h1:H9AZkK22UOmfX8J84ubyaZxKJZ3FMHVwn8swoM github.com/go-asn1-ber/asn1-ber v1.5.8/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= github.com/go-augeas/augeas v0.0.0-20260830115849-a0db83a6594a h1:WnRzPthHV1yr9s1jPmUmdApc1M3iIA1ZfH/fwKmCzFg= github.com/go-augeas/augeas v0.0.0-20260830115849-a0db83a6594a/go.mod h1:syDsgdbvlbD/zjgs6nJktc2araTaN5DEL3a/OvPCrkM= +github.com/go-bignum/bigfloat v0.2.0 h1:9sDb0Trg9ikAoSvLtjAXBLERNX2wYkbHi/w3FSqj6BQ= +github.com/go-bignum/bigfloat v0.2.0/go.mod h1:YVHspp0DKscpWZ6NK+rSCXxCfVDldNNoAN2JYQ8FInk= github.com/go-commonmark/commonmark v0.1.0 h1:UUjE5rIPuYYxDBi2Nj2/fNoTGDyAirp3p/t8B4TzMjE= github.com/go-commonmark/commonmark v0.1.0/go.mod h1:llCsI7zIAI9nbpH+zhewbQfL6WtyYxmkB4HWZ0YseD8= github.com/go-composites/array v0.0.0-20261015235938-f7161fa2d065 h1:WDXYARIlvdq8yAthNq8esKhDlJPBxbAgYs/7psRyI/E= @@ -204,10 +206,10 @@ github.com/go-datetime/dates v0.2.0 h1:5zXrMqTgw3ljlQfghRsdJRtXYqnR6jYqTgMvA3kG8 github.com/go-datetime/dates v0.2.0/go.mod h1:FmzSHylloy714Cc8MEkRjREYP7TcslqjmzsFMQXglAg= github.com/go-embedded-c/c v0.2.1 h1:LCNcLHJ1T3Ry0adJwO+jK9RnoFwrMd6yR/0bb0muHIc= github.com/go-embedded-c/c v0.2.1/go.mod h1:MhuXRqUtTZTUnm/3fVjho1HiL6QCFylChzOQ+Tu9eiQ= -github.com/go-embedded-fortran/fortran v0.17.0 h1:jaFE9Nqzqms9NOZDg1+7zQ9qZUGssvEcoOCxuPhIPWY= -github.com/go-embedded-fortran/fortran v0.17.0/go.mod h1:UUtUFdyuO7fWnDoBjbjGZNGXg7bH2fW2DLp1D4QOAkg= -github.com/go-embedded-julia/julia v0.15.0 h1:FcGqZTIYPqBFdA2BDr6HdItbUe4QAf3/HNRW+bZWnJ4= -github.com/go-embedded-julia/julia v0.15.0/go.mod h1:WkSyHRvyKTls2QhqjwORXAcDOJCeoO6zIx2wedBPLpk= +github.com/go-embedded-fortran/fortran v0.24.1 h1:hp0Rx5xhoLhNXVsVRmI/B3QdKz+Stxseklb9B5TX3Ro= +github.com/go-embedded-fortran/fortran v0.24.1/go.mod h1:UUtUFdyuO7fWnDoBjbjGZNGXg7bH2fW2DLp1D4QOAkg= +github.com/go-embedded-julia/julia v0.17.0 h1:lCsAJ6bsvfqC1OGM3d5LUGbZlpdvDq+MoXFv/Bo+VVo= +github.com/go-embedded-julia/julia v0.17.0/go.mod h1:WkSyHRvyKTls2QhqjwORXAcDOJCeoO6zIx2wedBPLpk= github.com/go-embedded-r/r v0.17.1 h1:raX7Ac9Bvni/pw+A+7lWFO1UkJqm66d4f26uh57DH2w= github.com/go-embedded-r/r v0.17.1/go.mod h1:+SbBiE9KSTuc1kWNF6009Ixrs2tM2uQCuKxByngTWL4= github.com/go-embedded-r/tre v0.1.3 h1:MuHk9dLUO51F6kr7j8mnu01bUMVBmOpVlrmO16qObjo= @@ -265,10 +267,10 @@ github.com/go-ndarray/ndarray v0.40.3 h1:jsQnEKagtYZs484MzLNGbpcttkVvS1m8UrodoWJ github.com/go-ndarray/ndarray v0.40.3/go.mod h1:O4U0Y5pV0Pakd0iqx5ECW8VP346oxJlvm73FTeQ1rI8= github.com/go-nokogiri/nokogiri v0.1.0 h1:3Q3BewGHK16Bt34ggJeyf9xeIMJyA3dmfbIxARPgR9U= github.com/go-nokogiri/nokogiri v0.1.0/go.mod h1:zjghooYIK8Xfg+fL4/OUhROslx51xGsM3JKtB2TI0tg= -github.com/go-notebook/notebook v0.18.0 h1:D+dUbO7UGntilJgKy0RSe4c8lSM/29L5ATJsGh3vlaQ= -github.com/go-notebook/notebook v0.18.0/go.mod h1:uGGg7forGdvyhc3ohmknC/1mNf3FD7JkEmwj3yAx4s0= -github.com/go-notebook/playground v0.16.0 h1:XewbwFXAxR/HPvdT6o/gK8Xp+SLVabqz2gI8sf+9fis= -github.com/go-notebook/playground v0.16.0/go.mod h1:n9jKYN6FtJjfP8llbctGgJaHtTykQf4uB+kge7IYyCA= +github.com/go-notebook/notebook v0.20.0 h1:puHnpLw1qupEVT+9PYgm0WnKlQCJf0yoiw5vNCzDMBk= +github.com/go-notebook/notebook v0.20.0/go.mod h1:UuafSbeeR/l6bA/dg817XK0/ns6azBubh9uJmiys9bY= +github.com/go-notebook/playground v0.18.0 h1:P/u6ypZhfOZM3Q5wjSDLL/MVn6VUhVvcxSoHKQy9qFo= +github.com/go-notebook/playground v0.18.0/go.mod h1:jaO8J8X4ieIzFmBGgSwJ0syswQlKdt7ALX88nWUfigo= github.com/go-numerics/integrate v0.2.0 h1:IkJhDimTc7nQETCixEvbbHhtOF36GbANBKJI3mJB3Kw= github.com/go-numerics/integrate v0.2.0/go.mod h1:ABjpcWy8ZSOg8j6S+7YRsvMJ2LpVkH4E64/CGet2gCw= github.com/go-numerics/optimize v0.3.1 h1:eYkT9BpORKSwXnDtEJxXfZ19qJT0cI2RH6xEL3VLZSU= @@ -289,6 +291,8 @@ github.com/go-puppet/puppet v0.0.0-20260918012035-fc6b0424cdbd h1:0tExRGSb1rQsGZ github.com/go-puppet/puppet v0.0.0-20260918012035-fc6b0424cdbd/go.mod h1:wdKZWNCMcBQA7Dgp7xu2QFDPF7tQ2fTlOG4cjGEMgxU= github.com/go-regexp/engine v0.4.2 h1:oI69hZyQyZH2n5w0UI7UEO7CaTa7hy3VSgKo76EJB4g= github.com/go-regexp/engine v0.4.2/go.mod h1:fWnPvSuE4HIVpBQIHMiaPMEE7InDc00KeoPr/QNFGwA= +github.com/go-regexp/pcre2 v0.1.0 h1:5nHNMcypAjg0DeTnCyHyF7EocavWnI5bvLRpt9nDXpw= +github.com/go-regexp/pcre2 v0.1.0/go.mod h1:NoGfatNS+oPnPJQpPsHmVyW6fJxlziutuLku3KjNf9Y= github.com/go-richdoc/richdoc v0.7.0 h1:vhHypa0y26ulrOz6Aw1RIzeLjSMsFJyU1SzK5jd90lg= github.com/go-richdoc/richdoc v0.7.0/go.mod h1:RhxAcqwoUg1pnTYCiRdKILzOZwOmraO0dMJI4N6yY70= github.com/go-rouge/rouge v0.9.0 h1:qIFbx0aQYYE2YeSAeTjhWa5zumXHJuNi0i6pJgO2IEk= diff --git a/playground/notebooks/4-julia.md b/playground/notebooks/4-julia.md index 6f2cb37..5fb1e66 100644 --- a/playground/notebooks/4-julia.md +++ b/playground/notebooks/4-julia.md @@ -1,31 +1,43 @@ -# Julia cells, checked in the page and run in go-notebook +# Julia cells run in the page, in a core of their own -A cell written in a `julia` fence is **parsed and checked** with [go-embedded-julia](https://go-embedded-julia.github.io/)'s parser. In go-notebook itself (`notebook run`, `notebook serve`) it also **runs**, on go-embedded-julia's interpreter in one kernel. In this page it does **not** run yet: the interpreter's Base image is fetched at run time, which a page cannot do. There is no external `julia` behind it. The badge on the cell says so: *Julia · not runnable yet*. +A cell written in a `julia` fence **runs** here, on [go-embedded-julia](https://go-embedded-julia.github.io/)'s interpreter, in WebAssembly in this tab. There is no external `julia` and no server behind it. It is the same interpreter that `notebook run` and `notebook serve` use. -In the page a Julia cell is checked, not run. What works here is the checking: syntax errors come back at the right line, and the cell never reaches the Go evaluator. +Julia is the heaviest runtime the page has, so it is loaded **only when you run a Julia cell**: Run loads a third core and Julia's Base image (about 28 MB over the wire, about 20 seconds the first time, then your browser keeps them), and says so on the cell while it does. Opening this notebook, and running the Go cells above the first Julia cell, download nothing for Julia. The Go, Ruby, R and Fortran cores never carry it. ```go n := 10 ``` -The Julia cell below is well formed, so it is not an error. It does not run in the page: its output says why, and no number comes back. +The Julia cell below runs in Julia's REPL scope: the loop at the top of the cell assigns to the global `s`, as it does in the REPL and in a Jupyter kernel, and the value of the last expression is shown, as the REPL shows it. + +```julia +s = 0 +for i in 1:10 + s += i +end +s +``` + +What a cell prints is its output; what it defines stays in the one Julia kernel of the notebook, so the next Julia cell reads it. ```julia xs = [i^2 for i in 1:3] +println("squares: ", xs) total = sum(xs) ``` -In go-notebook itself, Julia variables cross to and from Go cells (Int64, Float64, Bool, String, and vectors and matrices of Float64 or Int64). Here the Julia cell is only checked, so a cell that reads no Julia name neither reads `total` nor waits for it. It runs as usual, whatever the Julia cells above it do: +```julia +println("the sum of the squares is ", total) +``` + +**Julia's variables stay in Julia in the page.** In go-notebook itself (`notebook run`, `notebook serve`) a Julia variable crosses to a Go cell and back. In the page the Julia kernel and the Go interpreter are two interpreters in one worker that do not exchange values, so a Go cell that reads `total`, or a Julia cell that reads `n`, fails with the other language's own message (`undefined: total`, `UndefVarError`) and a note that says why. The Go cell below runs as usual, and does not read the Julia cells' variables: ```go n * 2 ``` -A mistake in a Julia cell is caught at the right line, before anything runs, and the cells that do not read it still run. This notebook would stop being published if one of its cells had one, so here is one, quoted. With a cell that reads - -> y = 2 -> x = (1, +A mistake in a Julia cell is caught at its line and column before anything runs, and an exception shows Julia's own text. Add a Julia cell with `x = (1,` and run the notebook to see ``line 1:8: syntax error: Expected `)` or `,` ``, or one with `sqrt(-1)` to see `ERROR: DomainError with -1.0:`. The cells after a failed cell are not run, as in every language. -the page shows ``line 2:8: syntax error: Expected `)` or `,` ``, at line 2, column 8, where the closing parenthesis was expected. Try it: add a Julia cell with `x = (1,` and run the notebook. +A cell is bounded like an R cell: 512 MiB of arrays, 20 million statements, 20 seconds and a cap on its output. A cell that sleeps or spins ends with `stopped: the Julia cell ran longer than 20s, the limit`, and the kernel, with its variables, is kept. Each run starts a kernel of its own, so a `struct` defined by a cell is not a redefinition the second time you run the notebook. -Running them in the browser is a separate question, pending with go-embedded-julia. Follow the progress at [go-embedded-julia.github.io](https://go-embedded-julia.github.io/). +If Julia cannot start (the network, or a tab out of memory), its cells say so and the cells of the other languages run as usual.