Appearance
Variables & Lazy Thunks
Declaring Variables (let)
Declare a variable with let <name> be <expr>. Its type is inferred automatically:
text
let count be 0
let label be say ready end
let active be yesYou can also annotate the type explicitly with as <type>:
text
let count as num be 0
let names as list of text be empty list of textMutating Variables (set)
Update an existing variable with set <name> to <expr>:
text
set count to count plus 1
set label to say done endAssigning a value of a different type is caught at compile time.
Lexical Scoping & Shadowing
FakeScript v3.0 supports true block-level lexical scoping:
- Top-level
letstatements declare global variables accessible from any function, initialized in exact top-to-bottom source order. letinsidefn,if,else,loop, orfor eachdeclares a local variable scoped to that block and can safely shadow outer variables.- Unused local variables do not cause Go compilation errors.
text
import print
let x be 10
fn demo do
let x be 99
if x is 99 do
let x be 7
ln of print contains x
end
ln of print contains x
end
exec demo
ln of print contains xOutput:
text
7
99
10Lazy Action Bindings (Thunks)
Assigning any void call (such as ln of print contains ... or a void function call) to a variable does not run it immediately. Instead, fksc wraps it in a lazy thunk (func()):
text
import print
let announce be ln of print contains say action fired end
fn main do
ln of print contains say before end
announce
announce
end
exec mainOutput:
text
before
action fired
action firedThunks work in both global and local scopes, and can be reassigned with set to another void action.