Guestlist
Console program99 lines of .st128 lines of generated Rust
Hello, what's your name? Welcome to the Treehouse, bert
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "Rust"
}
}
}main.st
ability "function" "what_is_your_name" {
returns = String
locals = [{ name = "your_name", type = String, size = 64 }]
body = [ability.read_line.Line, ability.trim.Ends, ability.lower.Case]
return = your_name
}
ability "read_line" "Line" {
target = your_name
}
ability "trim" "Ends" {
target = your_name
}
ability "lower" "Case" {
target = your_name
}
ability "print" "Question" {
message = "Hello, what's your name?"
}
ability "call" "GetName" {
function = ability.function.what_is_your_name
result = ability.value.name
depends_on = [ability.print.Question]
}
ability "for" "CheckList" {
counter = ability.value.i
from = 0
while = data.value.i.current < length(var.visitor_list)
next = data.value.i.current + 1
body = [ability.if.OnList]
depends_on = [ability.call.GetName]
}
ability "if" "OnList" {
condition = var.visitor_list[data.value.i.current] == data.value.name.current
then = [ability.set.AllowIn]
}
ability "set" "AllowIn" {
target = ability.value.allow_them_in
value = true
}
ability "if" "Door" {
condition = data.value.allow_them_in.current
then = [ability.print.Welcome]
else = [ability.print.Sorry]
depends_on = [ability.for.CheckList]
}
ability "print" "Welcome" {
message = "Welcome to the Treehouse, ${data.value.name.current}"
}
ability "print" "Sorry" {
message = "Sorry, you aren't on the list."
}vars.st
variable "visitor_list" {
type = Array
of = String
size = 3
default = ["bert", "steve", "fred"]
}
ability "value" "name" {
type = String
size = 64
}
data "value" "name" {
of = ability.value.name
}
ability "value" "allow_them_in" {
type = Bool
initial = false
}
data "value" "allow_them_in" {
of = ability.value.allow_them_in
}
ability "value" "i" {
type = Int
initial = 0
}
data "value" "i" {
of = ability.value.i
}Input, plan and generated Rust#
input.txt · typed input (1 lines)
input.txt · typed input (1 lines)
Bertstructop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.function.what_is_your_name
+ ability.read_line.Line
+ ability.trim.Ends
+ ability.lower.Case
+ ability.print.Question
+ ability.call.GetName
+ ability.for.CheckList
+ ability.if.OnList
+ ability.set.AllowIn
+ ability.if.Door
+ ability.print.Welcome
+ ability.print.Sorry
+ ability.value.name
+ ability.value.allow_them_in
+ ability.value.i
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.rs
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 rust-guestlist # a folder holding the .st files above
structop init
structop plan
structop apply < input.txt