Posts
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).

Express restarts for Python
Restarting Basthon's Python kernel is now almost instant: about half a second, against three seconds before. You can start again from a clean state as often as needed, without waiting, in the console as in the notebook.
To achieve it, Basthon takes a snapshot of Python's memory just after it is loaded, before running a single line of code. At each restart, it starts again from this snapshot instead of reloading everything. Nothing of your code or your variables is in it: the kernel really restarts afresh.
The browser also keeps this snapshot from one visit to the next. From the second visit on, the kernel is ready in less than a second, instead of two and a half.
These speed-ups concern the isolated kernels, used by default. The legacy mode starts as before.
An R kernel in Basthon
After C, a new language arrives in Basthon: R! The reference language of statistics now works directly in the browser, with no installation nor server, thanks to the webR project.
Everything you expect from R is there:
- results are shown as in the R console;
- charts (
plot,hist,barplot…) appear directly next to the console or below the cell; - missing packages (
dplyr,ggplot2…) are downloaded automatically at the firstlibrary(); - the help is still available with
?meanorhelp("mean"); readline()asks the user for an input.
It is available in the console and in the notebook, and the gallery already offers a few examples.

pytest tests with ipytest
The ipytest module is available in Basthon. It lets you write pytest tests directly in the console or in a cell of the notebook:
import ipytest
ipytest.autoconfig()
def mean(marks):
return sum(marks) / len(marks)
def test_mean():
assert mean([10, 12, 14]) == 12
def test_empty_list():
assert mean([]) == 0
ipytest.run()asserts are detailed as with pytest: you see straight away which test fails and why. The %%ipytest magic command does not exist in Basthon: call ipytest.run().
The notebook speaks ten languages
The interface of Basthon's notebook is now translated into ten languages: French, English, German, Spanish, Italian, Dutch, Portuguese, Russian, Chinese and Japanese.
The language is chosen in the View menu, Language submenu, and the choice is remembered for the next visits. It can also be forced in a link with the lang parameter, for instance ?lang=en.
