OCaml
Your own OCaml modules, as with a compiler
In Basthon, you can open your own .ml files (Open menu or module= URL parameter) to use them as modules. Loading them is now close to separate compilation:
- a module is only loaded when first used:
stack.mlcan useQueueeven if it is opened beforequeue.ml; - an interface
queue.mliconstrains the module, and hides what it does not declare; - the errors of a module are shown in the cell that uses it, with the excerpt of the file at fault;
- a student's module takes precedence over the modules opened by Basthon: a
file.ml(the queue of the French course, "file" in French) is no longer hidden by js_of_ocaml'sFilemodule; - a module opened again after a change is reloaded, and circular dependencies are reported.

Visualizing memory and recursive calls in OCaml
In Python, tools such as lolviz, rcviz or Python Tutor help students picture memory and recursive calls. Basthon's OCaml kernel now has its own tool: the visu library, which draws in the notebook:
- the trace and the call tree of a recursive function, where redundant computations appear in orange;
- the memory representation of a value: blocks, pointers, sharing (the classic trap of
Array.maketo create a matrix!) and cyclic values; - trees, graphs and arrays, for instance to follow a sort step by step.
#require "visu";;
module Visu = Basthon.Visu;;
let fib fib n = if n < 2 then n else fib (n - 1) + fib (n - 2);;
Visu.arbre_appels ~nom:"fib" string_of_int string_of_int fib 5;;
Visu.memoire ~nom:"m" (Array.make 3 (Array.make 2 0));;To observe its calls, the function is written in open recursion: its first parameter is the function to use for its recursive calls. The #trace directive of the OCaml toplevel does not work in Basthon, where OCaml is compiled to JavaScript: Visu.trace replaces it.

Big integers and rationals in OCaml with zarith
In Basthon, OCaml is compiled to JavaScript and its integers are 32 bits: max_int is 2,147,483,647 and the factorial of 13 already overflows. The zarith library brings integers of arbitrary size (Z module) and exact rationals (Q module):
#require "zarith";;
let rec fact n = if n = 0 then Z.one else Z.mul (Z.of_int n) (fact (n - 1));;
fact 100;;
Z.probab_prime Z.(~$2 ** 127 - ~$1) 25;;
Q.(of_ints 1 10 + of_ints 2 10);;GCD and Bézout's identity, modular inverse and exponentiation, primality tests: everything is there for arithmetic, up to a miniature RSA written in a few lines in the example notebook. Values are shown directly in the toplevel, and computations stay fast thanks to JavaScript's big integers (BigInt).

Interactive and animated OCaml canvases
In Basthon's OCaml kernel, a Graphics_js canvas once shown stays alive after the cell has run. It reacts to the mouse and the keyboard with loop, mouse_pos or read_key, and can be animated with Lwt.
It works in the console as in the notebook, including with isolated kernels.
