Scan float64
Console program59 lines of .st259 lines of generated Cbuilds as C and Rust
2.500000 0.250000 3 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
# scan into a Float64 reads a double (C "%lf"), beside a Float and an Int in one pattern; the same in both targets.
ability "value" "price" {
type = Float64
}
data "value" "price" {
of = ability.value.price
}
ability "value" "rate" {
type = Float
}
data "value" "rate" {
of = ability.value.rate
}
ability "value" "n" {
type = Int
}
data "value" "n" {
of = ability.value.n
}
ability "scan" "Read" {
source = "price=2.5 rate=0.25 n=3"
pattern = "price=${ability.value.price} rate=${ability.value.rate} n=${ability.value.n}"
}
ability "scan" "Precise" {
source = "0.1"
pattern = "${ability.value.price}"
depends_on = [ability.print.Show]
}
ability "print" "Show" {
message = "${data.value.price.current} ${data.value.rate.current} ${data.value.n.current}"
depends_on = [ability.scan.Read]
}
ability "print" "Tenth" {
message = "${data.value.price.current * 10.0 == 1.0}"
depends_on = [ability.scan.Precise]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.price
+ ability.value.rate
+ ability.value.n
+ ability.scan.Read
+ ability.print.Show
+ ability.scan.Precise
+ ability.print.Tenth
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 scan-float64 # a folder holding the .st files above
structop init
structop plan
structop apply