[ANN] Terse.jl

Hi all,

Announcing Terse.jl (release pending in General)!

I found myself wanting a succinct syntax for building complex type hierarchies for two reasons: 1) working on complex hierarchies myself, and 2) understanding quickly how Claude code is approaching a problem (It also saves you a few precious tokens in your 1M context window).

You can probably immediately guess what the following creates:

using Terse

@types Shape > (
    TwoDimensional > (
        Circle(radius::Float64 = 1.0),
        Rectangle(width::Float64 = 1.0, height::Float64 = 1.0),
        Triangle(base::Float64, height::Float64)
    ),
    @mutable ThreeDimensional > (
        Sphere(@const(radius::Float64); hollow::Bool = false),
        Cube(@const(side::Float64); hollow::Bool = false),
        Prism > (
            TriangularPrism(base::Float64, height::Float64),
            Cylinder(radius::Float64 = 1.0; height::Float64 = 1.0)
        )
    )
)

Check it out and let me know what you think!

5 Likes

cool!

I wonder why you chose @mutable and @const when those are already reserved keywords, and you’re parsing them inside a macro already ? (@types)

The β€œmacros” (don’t actually exist, but used within the @types macro) are my solution for creating a valid Julia expression:

julia> :(MyType(const field::FieldType))
ERROR: ParseError:
# Error @ REPL[35]:1:10
:(MyType(const field::FieldType))
#        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ── expected assignment after `const`
Stacktrace:
 [1] top-level scope
   @ REPL:1
2 Likes