grabapl
A library for graph-based programming languages with static analysis.
Playground: https://skius.github.io/grabapl/
Docs: https://docs.rs/grabapl/latest/grabapl/
Main Features
- The program state is a single global, directed graph.
- The type system is a shape-based type system (i.e., existence and absence of nodes and edges) composed
with an arbitrary client-defined type system for node and edge values.
- Nodes and edges can hold arbitrary values of arbitrary types.
- See
grabapl_template_semanticsfor an example client.
- No explicit loops, only recursion.
- Statically visible nodes and edges are guaranteed to exist at runtime. No nulls.
- Frontend-agnostic with a focus on intermediate abstract states:
- The fundamental building blocks of programs are "instructions" that can stem from any source.
- For example, a frontend may decide to be visual-first by visualizing intermediate states and turning interactive actions into instructions.
- A text-based frontend is provided with
grabapl_syntax, supporting a Rust-like syntax with pluggable client-defined parsing rules.
Example
Using the grabapl_syntax frontend as example with the example node and edge type system from
grabapl_template_semantics, here is an implementation of in-place bubble sort on a linked list
(feel free to copy-paste this code into the playground and play around with it!):
// Jumpstarts the helper function
// General approach:
// 1. Depending on `direction`, go down the linked list, pulling the maximum/minimum
// element with us.
// 2. Once we reach the end/beginning of the *remaining* list, we know that
// that element is now in its final position (it was either the maximum or
// the minimum remaining element)
// 3. Hence we mark that node as 'fixed', and switch direction.
// 4. Once there are no more non-'fixed' nodes, we are done.
//
// In other words, the call stack will look roughly like this, with
// 'fixed' mark actions indicated by an 'x':
//
// Linked list: a -> b -> c -> d
// 1.
// 2.
// 3.
// 4.
// 5. x
// 6. x
// 7. x
// x 8. x
// x 9. x
// x 10. x x
// x x x x
//
// 10. can't go down the list anymore, hence the entire list has been sorted.