Text in arguments
Console program85 lines of .st190 lines of generated Cbuilds as C and Rust
6 k4 <a4|8|true>
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
}
}main.st
# Text with ${} passed as a value (a call's argument, an argument of a function in an expression, a struct field of an
# object) is formatted as ${} formats it, in both targets; the C build dropped everything after the first ${}.
ability "value" "i" {
type = Int
initial = 4
}
data "value" "i" {
of = ability.value.i
}
ability "struct" "Item" {
fields = [{ name = "name", type = String }, { name = "n", type = Int }]
}
ability "value" "it" {
type = Item
}
data "value" "it" {
of = ability.value.it
}
ability "value" "n" {
type = Int
}
data "value" "n" {
of = ability.value.n
}
ability "function" "twice" {
params = [{ name = "t", type = String }]
returns = Int
body = [ability.return.R]
}
ability "return" "R" {
value = length(t) * 2
}
ability "set" "S" {
target = ability.value.n
value = twice("ab${data.value.i.current}")
}
ability "set" "It" {
target = ability.value.it
value = { name = "k${data.value.i.current}", n = 1 }
depends_on = [ability.set.S]
}
ability "print" "P" {
message = "${data.value.n.current} ${data.value.it.current.name}"
depends_on = [ability.set.It]
}
ability "function" "show" {
params = [{ name = "t", type = String }]
body = [ability.print.T]
}
ability "print" "T" {
message = "<${t}>"
}
ability "call" "Show" {
function = ability.function.show
args = ["a${data.value.i.current}|${data.value.i.current * 2}|${data.value.i.current > 3}"]
depends_on = [ability.print.P]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.i
+ ability.struct.Item
+ ability.value.it
+ ability.value.n
+ ability.function.twice
+ ability.return.R
+ ability.set.S
+ ability.set.It
+ ability.print.P
+ ability.function.show
+ ability.print.T
+ ability.call.Show
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runGenerated main.rs (the same .st built as Rust)
To inspect this generated file, select Rust in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd text-in-arguments # a folder holding the .st files above
structop init
structop plan
structop apply