StructOp Handbook
Contents Examples Commands
Handbook / What is StructOp?

Declarative application development

In StructOp an application is a set of declarations. Each declaration names something that exists or something that happens, and StructOp checks the types and references, works out the run order and generates the code.

On this page

Declarations#

Every declaration is a block with a kind and a name. Types are declarations too: the guest list from the guided tour declares an enum and a struct.

types.st
ability "enum" "Mood" {
    values = [Happy, Sleepy]
}

ability "struct" "Guest" {
    fields = [
        { name = "name", type = String },
        { name = "age", type = Int },
        { name = "mood", type = Mood },
    ]
}

The kinds enum and struct come from the portable core provider. Once declared, Mood and Guest can be used wherever a type is expected.

Values and data#

Data that changes lives in a value ability. Abilities that change it name the value; everything else reads it through a data block. The separation makes every write and every read visible.

vars.st (excerpt)
ability "value" "guests" {
    type    = List
    of      = Guest
    size    = 8
    initial = [
        { name = "Ada", age = 36, mood = Mood.Happy },
        { name = "Linus", age = 12, mood = Mood.Sleepy },
    ]
}

data "value" "guests" {
    of = ability.value.guests
}

Behaviour and order#

Behaviour is still written as steps: add a guest, loop over the list, call a function, switch on a value. What is declarative is that each step is a named, typed declaration whose relationships StructOp can check, order, plan and draw.

main.st (excerpt)
ability "add" "Newcomer" {
    list  = ability.value.guests
    value = { name = "Grace", age = 45, mood = Mood.Happy }
}

ability "for" "Each" {
    counter    = ability.value.i
    from       = 0
    while      = data.value.i.current < length(data.value.guests.current)
    next       = data.value.i.current + 1
    body       = [ability.call.Greet]
    depends_on = [ability.add.Newcomer]
}

Top-level abilities run in the order they are written. depends_on makes one wait for another, and abilities in a list such as body run inside their owner, in dependency order. structop validate reports a dependency cycle instead of guessing an order.

What StructOp checks#

These checks run before any code is generated. They find errors in the declarations; they do not prove that the program does what was intended. That is what tests are for.

Learn the language#