Scopes and contexts
All Ferret code exists within a private scope.
Execution of a Ferret program begins at the file level. There's
no main
routine-- we just jump right into the first line.
say("Hello, World!")
By default, variables are accessible only within the scope where
they're defined. So, $who
below would not be accessible in another
file since it belongs to the private top level file scope.
$who = "World" say("Hello, $who!")
However, all files belong to a public context.
The context is specified by a package
declaration. When omitted, package main
is presumed.
To expose $who
to another file, we'll add both files to
package Greeting
and share
the variable.
vars.frt
package Greeting share $who = "World"
main.frt
package Greeting share $who say("Hello, $who!")