Your First Program
Create a file called hello.fs:
import Logger from 'std:logger'
greet = (name: String): String => 'hello ' + name
main = (): Undefined => { Logger.info(greet('FScript'))}
main()That program already shows a few core rules:
- imports are explicit
- functions use arrow syntax
- the final expression in a block becomes the result
- logging comes from
std:logger, not a globalconsole
Check it first
cargo run -p fscript-cli -- check hello.fsIf the file parses and typechecks, the CLI exits successfully.
Run it
cargo run -p fscript-cli -- run hello.fsYou should see the greeting printed through the current runtime-backed logger.
A slightly richer version
import Array from 'std:array'import Logger from 'std:logger'
names = ['Ada', 'Grace', 'Linus']
messages = names |> Array.map((name) => 'hello ' + name)
main = (): Undefined => { Array.forEach((message) => Logger.info(message), messages)}
main()That example introduces pipes and explicit array helpers.
If you know JavaScript
A similar JavaScript example might use:
console.lognames.map(...)function main() { return ... }
In FScript the same ideas become:
Logger.infoArray.map- arrow functions and final-expression blocks
Common early mistakes
- forgetting to import the
std:module you want to use - trying to call array prototype methods such as
.map - writing
return - trying to reassign a binding with
letorconst
Next step
Continue with Project Layout or jump into the Language Guide.