New modules
ics
The ics module arrives in Basthon's Python kernel: it writes and reads calendars in the iCalendar format, the .ics files that every calendar understands (the phone's, the school's digital workspace, Thunderbird, Google Calendar…). A way to generate the schedule of a project or of a course, then import it into your calendar in a single click.
OCaml libraries with #require
Basthon's OCaml kernel can now load libraries, with the #require directive of the OCaml toplevel, as you would with a library installed by opam:
#require "zarith";;
Z.(~$2 ** 200);;Libraries are only downloaded at the first #require, and are already compiled to JavaScript: they load almost instantly. Here are those available:
| Library | To… |
|---|---|
visu | visualize memory, recursive calls, trees and graphs (Basthon.Visu) |
graphviz | draw graphs described in DOT (Basthon.Graphviz) |
ocamlgraph | graphs and their algorithms (Graph module) |
zarith | big integers and rationals (Z and Q modules) |
containers, containers-data | priority queues, deques, dynamic arrays… |
yojson, csv | read and write JSON and CSV data |
The libraries specific to Basthon are put in the Basthon module: after #require "visu", write for instance module Visu = Basthon.Visu. Basthon.help () lists them all. By the way, the Basthon module gains display_svg and display_html to show an SVG image or HTML.
Each one has its example notebook in the gallery, presented in the following posts.

Priority queues, deques… in OCaml with containers
OCaml's standard library has no priority queue, no double-ended queue and no dynamic array. In Basthon, the containers library fills this gap:
#require "containers-data";;
module Heap = CCHeap.Make (struct type t = int let leq = ( <= ) end);;
Heap.to_list_sorted (Heap.of_list [ 5; 3; 8; 1 ]);;
let d = CCDeque.of_list [ 2; 3 ];;
CCDeque.push_front d 1;;It notably provides heaps (CCHeap), deques (CCDeque), persistent queues (CCFQueue), dynamic arrays (CCVector), bit vectors (CCBV), as well as many extensions of the standard library (CCList, CCString…). The example notebook uses them for heap sort, Dijkstra's algorithm, a breadth-first search or the sieve of Eratosthenes.

Reading CSV and JSON data in OCaml
To work in OCaml on real data (spreadsheet exports, open data…), Basthon offers two libraries: csv and yojson.
#require "csv";;
#require "yojson";;
let rows = Csv.Rows.load ~has_header:true "students.csv";;
List.map (fun r -> Csv.Row.find r "name") rows;;
let json = Yojson.Safe.from_string {|{"name": "Ada", "marks": [15, 18]}|};;
Yojson.Safe.Util.(json |> member "marks" |> to_list);;A file opened in Basthon (or attached to the notebook) is read directly, and a file produced is downloaded with Basthon.download. The example notebook computes means from a CSV file, writes a ranking, builds and analyses JSON, then converts the CSV into JSON.

Drawing graphs in OCaml: Graphviz and ocamlgraph
Two libraries arrive in Basthon's OCaml kernel to work on graphs.
graphviz draws a graph described in the DOT language of Graphviz, directly in the notebook:
#require "graphviz";;
module Gv = Basthon.Graphviz;;
Gv.display "digraph { a -> b; b -> c; c -> a }";;
Gv.display ~engine:"circo" "graph { 1 -- 2 -- 3 -- 4 -- 1 }";;So writing a function that produces the DOT text of a structure is enough to draw a graph given by adjacency lists, a binary search tree or an automaton.
ocamlgraph is OCaml's reference graph library: many graph structures and the classic algorithms (traversals, Dijkstra, connected components, topological sort, spanning trees, flows…). It produces DOT too, which Gv.display draws:
#require "ocamlgraph";;
module G = Graph.Pack.Digraph;;
let g = G.Classic.full 4;;
G.dot_output g "g.dot";;
Gv.display_file "g.dot";;The example notebook shows ocamlgraph's two styles (the ready-to-use Pack module, and functors), with for instance the shortest path in red.
