diff --git a/README.md b/README.md index b83ff61..96677af 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,10 @@ it in a REPL (Read-Eval-Print-Loop) fashion, by inserting a "Compile" step in th of the loop -- so it's a Read-Compile-Run-Print-Loop -- while still feeling very interactive. **GoNB** leverages that compilation speed to implement a full-featured (at least it's getting there) -[Jupyter notebook](https://jupyter.org/) kernel. +[Jupyter notebook](https://jupyter.org/) kernel. As a side benefit it works with packages that use CGO -- although it +won't parse C code in the cells, so it can't be used as a C kernel. -It already includes many goodies: contextual help and auto-complete (with +It already includes many goodies: cache between cell of results, contextual help and auto-complete (with [`gopls`](https://github.com/golang/tools/tree/master/gopls)), compilation error context (by mousing over), bash command execution, images, html, etc. See the [tutorial](examples/tutorial.ipynb). @@ -101,9 +102,6 @@ Contributions are welcome! * Windows version: * Installation. * Named-pipe implementation in `kernel/pipeexec.go`. -* Tracking of lines on generated Go files back to cell, so reported errors are easy to - follow. In the meantime the errors can be moused over and will display the lines - surrounding them. * Controllable (per package or file) logging in GoNB code. * Run `goimports` before calling `gopls` to inspect a variable, or auto-complete. This would be handy, but complicates tracking the position of the cursor on the changed diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8aa4507..e0254e0 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,6 @@ # GoNB Changelog -## Next version +## v0.6.0 * Issue #16: Added package `cache`: implements a convenient cache of values for things that are expensive or slow to regenerate at each execution. diff --git a/examples/tutorial.ipynb b/examples/tutorial.ipynb index 5c7d72e..d4c7a7f 100644 --- a/examples/tutorial.ipynb +++ b/examples/tutorial.ipynb @@ -36,6 +36,7 @@ } ], "source": [ + "!*go mod edit --replace github.com/janpfeifer/gonb=/home/janpf/Projects/gonb\n", "func main() {\n", " fmt.Printf(\"Hello World!\")\n", "}" @@ -186,6 +187,61 @@ "fmt.Printf(\"current startValue=%f\\n\", startValue)" ] }, + { + "cell_type": "markdown", + "id": "f4fc0797-df7f-4652-8a22-e8b489580e1d", + "metadata": {}, + "source": [ + "If one wants to save results calculated from one cell to another, GoNB includes the `github.com/janpfeifer/gonb/cache` package that makes it trivial to save and load previously generated results.\n", + "\n", + "**Example**: Below `VeryExpensive` is only called once for `CachedValue`, so you will notice that if you run the cell multiple times, it will display always the same number, while `NonCachedValue` will always call `VeryExpensive` again, and display another number. So the string \"...calculating...\" is printed twice only the first time." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "d59e0cbd-0d2a-42e5-8f94-29936130f437", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\t...calculating...\n", + "NonCachedValue=575\n", + " CachedValue=36\n" + ] + } + ], + "source": [ + "import (\n", + " \"math/rand\"\n", + " \"github.com/janpfeifer/gonb/cache\"\n", + ")\n", + "\n", + "func VeryExpensive() int {\n", + " fmt.Println(\"\\t...calculating...\")\n", + " return rand.Intn(1000)\n", + "}\n", + "\n", + "var (\n", + " CachedValue = cache.Cache(\"expensive\", VeryExpensive)\n", + " NonCachedValue = VeryExpensive()\n", + ")\n", + " \n", + "%%\n", + "fmt.Printf(\"NonCachedValue=%d\\n\", NonCachedValue)\n", + "fmt.Printf(\" CachedValue=%d\\n\", CachedValue)" + ] + }, + { + "cell_type": "markdown", + "id": "5a5470b4-43ea-47ae-a111-63ab77376bd0", + "metadata": {}, + "source": [ + "The `cache` package has many more features, check out " + ] + }, { "cell_type": "markdown", "id": "83c85334-6323-4b75-b9a2-184c0d83ed1c", @@ -1325,7 +1381,7 @@ "name": "go", "nbconvert_exporter": "", "pygments_lexer": "", - "version": "go1.20.1" + "version": "go1.20.3" } }, "nbformat": 4,