Tutorial, lesson 3 of 9
Procs
A proc is ela’s function: proc, its name, its parameters in brackets, the lines it runs, then
end proc. return hands values back. greet is the simple form, with no types and no names,
and a proc never needs more.
A proc is called with brackets, greet("Ada"). A bare word is always a command, so a proc never
stands in for a program of the same name.
A proc sees its parameters and the constants, never the script’s variables: what it needs comes in as an argument, and a reader sees it at the call.
A parameter may name its type, as text: string does. A call that passes a number then stops at
its line, before the proc runs, and the error names the parameter. Try echo "${shout(42)}".
A proc may also declare its results after ->, each with a name and a type, as split_host
does. A return that hands back text for port stops at that return, naming port. A call
that takes one value where two come back is told both names: try only = split_host("db:5432").
Each type buys three things. Installed ela’s ela --lint checks the calls and each use of a result
before a line runs, so if split_host(...) is reported first. An error names the parameter or the
result, so the fix is at hand. And an agent that reads the first line of split_host knows what
to pass and what comes back, without reading the body.