1-3: Data Flow
As any computer program, BushelScript scripts need to shunt data around to get things done. The two primary ways to do this are anonymous data flow and variables.
See also: Language Reference.
#
Anonymous data flow"Anonymous" data flow is passing values around without giving them names. This is aided by the that
keyword, which refers to the result of the last sequenced expression, usually whatever was discarded at the end of the previous line.
We can perform a numeric calculation across multiple lines, without assigning any variables:
We can also check a condition without losing what we're working with (we'll cover conditional expressions more in Section 5):
This style is encouraged whenever reasonable, but don't feel restricted to it.
Take note that everything you write in BushelScript is an expression that yields a result, so that
almost always has a meaningful value. (The only exception is the first expression of a program or function, where that
is unspecified
.)
#
VariablesIf you are used to AppleScript, take note: In BushelScript, there are no green-lettered "user identifiers". Instead, all names, including variables, are terms defined in a dictionary.
Variables can be defined using a let
expression. This defines a variable named logic
:
This defines a variable named num
and assigns it a value of 42
:
Like most other dynamic languages, variables themselves are not assigned a specific data type. i.e., BushelScript variables are more like variables in Python than in Java.
Variables can shadow (hide) other terms:
And like all terms, variables can be composed of multiple words:
Shadowing and naming rules will be covered in detail in terms.