LispSyntax.jl â ACSets.jl bidirectional bridge with OCaml ppx_sexp_conv-style deriving
Bidirectional S-expression â ACSet conversion inspired by OCaml's ppx_sexp_conv
Version: 1.1.0 Trit: 0 (Ergodic - coordinates data serialization) Bundle: serialization Dynamic Sufficiency: â VERIFIED (2025-12-22) - handles ACSets of arbitrary complexity
This skill bridges LispSyntax.jl (Lisp-like syntax in Julia) with ACSets.jl (algebraic databases) using the pattern established by OCaml's ppx_sexp_conv library. It enables:
parse_sexp("(+ 1 2)") â Sexpsexp_of_acset(graph) â Sexpacset_of_sexp(GraphType, sexp) â Graph(* OCaml pattern *)
type color = Red | Blue | Green [@@deriving sexp]
(* generates: sexp_of_color and color_of_sexp *)
# Julia equivalent for ACSets
sexp_of_acset(acs::ACSet) â Sexp
acset_of_sexp(::Type{T}, ::Sexp) â T where T <: ACSet
abstract type Sexp end
struct Atom <: Sexp
value::String
end
struct SList <: Sexp
children::Vector{Sexp}
end
# String â Sexp (like OCaml's Sexp.of_string)
sexp = parse_sexp("(define (square x) (* x x))")
# Sexp â String (like OCaml's Sexp.to_string)
str = to_string(sexp)
# Roundtrip verification
@assert verify_parse_roundtrip("(a (b c) d)")
# To S-expression
sexp_of_int(42) # â Atom("42")
sexp_of_float(3.14) # â Atom("3.14")
sexp_of_string("hello") # â Atom("hello")
sexp_of_list(sexp_of_int, [1,2,3]) # â SList([1, 2, 3])
# From S-expression
int_of_sexp(Atom("42")) # â 42
list_of_sexp(int_of_sexp, SList([...])) # â [1, 2, 3]
# ACSet â Sexp
# Produces: (TypeName (Ob1 ((id1 attrs...) ...)) (hom1 ((src tgt) ...)) ...)
sexp = sexp_of_acset(my_graph)
# Sexp â ACSet
graph = acset_of_sexp(GraphType, sexp)
# Verify roundtrip
@assert verify_roundtrip(original_graph)
# Colorize with deterministic seed
colored = colorize(sexp, seed=0x598F318E2B9E884)
# ColoredSexp with LCH color from SplitMix64
ACSet to S-expression produces structured output:
(Graph
(V ((1) (2) (3))) ; Vertices (object parts)
(E ((1) (2))) ; Edges (object parts)
(src ((1 1) (2 2))) ; Source morphism (id â target)
(tgt ((1 2) (2 3)))) ; Target morphism (id â target)
| Trit | Skill | Role |
|---|---|---|
| -1 | slime-lisp | Validates Lisp syntax |
| 0 | lispsyntax-acset | Coordinates serialization |
| +1 | cider-clojure | Generates Clojure interop |
Conservation: (-1) + (0) + (+1) = 0 â
;; Hy uses same sexp concepts
(defclass ColoredSExpr []
"S-expression with semantic color annotations")
(defn acset-to-colored-sexpr [acset]
"Convert ThreadACSet to Colored S-expression tree")
# Inverse operation: Sexp â ACSet graph
function sexp_to_graph(sexp::ColoredSexp)::ColoredSexpData
data = ColoredSexpData()
_add_sexp!(data, sexp, nothing, 0)
data
end
# Run demo
lispsyntax-demo:
julia --project=. -e 'include("lib/lispsyntax_acset_bridge.jl"); LispSyntaxAcsetBridge.demo()'
# Test roundtrip parsing
lispsyntax-test:
julia --project=. -e '
include("lib/lispsyntax_acset_bridge.jl")
using .LispSyntaxAcsetBridge
@assert verify_parse_roundtrip("(a (b c) d)")
println("â Parse roundtrip OK")
'
lib/lispsyntax_acset_bridge.jllib/colored_sexp_acset.jllib/thread_relational_hyjax.hysrc/sicp/colored-sexp.cljNEW 2025-12-22: Integrated Specter-style bidirectional navigation with Julia-specific optimizations achieving 93-113x speedup over CPS-based implementation.
| Operation | Hand-Written | Original CPS | Optimized | Ratio |
|---|---|---|---|---|
| Select evens (n=1000) | 423.8 ns | 52.58 Ξs | 561.6 ns | 1.3x |
| Transform evens | 354.9 ns | 40.04 Ξs | 354.2 ns | 1.0x |
| comp_navs allocation | - | 7.8 ns | 0.5 ns | 15.7x |
Vector{Navigator} â type stability, 0 allocs@inline annotations â aggressive hot path inliningPath caching follows 3-MATCH gadget principles:
# Correct-by-construction path caching
compiled_path = TupleNav((ALL, pred(iseven))) # Type-stable, 0 allocs
result = nav_select(compiled_path, data, IDENTITY) # Guaranteed correct
lib/specter_optimized.jl - Zero-overhead implementationlib/specter_chairmarks_world.jl - Chairmarks benchmarksSPECTER_OPTIMIZATION_RESULTS.md - Full benchmark reportacsets-algebraic-databases skill - ACSet foundationsgay-mcp skill - Deterministic coloringthree-match skill - Correct-by-construction caching