Skip to main content

1-2: Basic Syntax

BushelScript, being a programming language, has syntax which must be adhered to.

See also: Quick Tutorial.

Comments#

Comments are pieces of text embedded in a program that are intended only to aid human readers. They have no formal semantic effect on the program; adding or removing comments does not change what a program does.

Line comments#

Line comments begin with -- and continue to the end of their line.

Block comments#

Block comments begin with --( and continue through to new lines, until either )-- or the end of the program is reached.

Values#

Numbers#

integers#

Positive and negative whole numbers, no fractions. Any numeric literal in the appropriate range and without a decimal point produces an integer. integers store signed 64-bit values, which means -2⁶³ ≤ 𝑥 < 2⁶³ for all integers 𝑥.

reals#

Positive and negative numbers with fractions allowed. A numeric literal with a . decimal point produces a real.

reals use double-precision floating-point format. This provides a huge range of representable values, but can cause imprecision in base-10 calculations: reals are stored as 𝑠 × 2ⁿ, where 𝑠 and 𝑛 are integers, but not all decimal numbers can be represented exactly in this format.

string#

A string is a sequence of Unicode characters. If it's text, it goes in a string.

"abc"
"this is a string value"
"😀😃😄" -- length 3 (grapheme clusters, not UTF-16 units)

boolean, truth and falsity#

A boolean represents the answer to a yes-or-no question. It can be reacted to by control flow constructs or factored into logical operations.

true
false
true and false --> false
false or true --> true

missing, the intentional absence of a value#

missing indicates the intentional absence of a value. It is the sole value of type [ae4:msng], which is called missing value in AppleScript. It is encoded as this type object when sent in an AppleEvent.

missing
missing as boolean --> false

unspecified, the incidental absence of a value#

unspecified indicates the incidental absence of a value. It is the initial value of unset variables, including those corresponding to function parameters.

let my var
my var --> unspecified
to build greeting
to (name)
do
-- 'name' = unspecified if the 'to' parameter is omitted
"Hello" & (if name then (", " & name) else "") & "!"
end
build greeting --> "Hello!"
build greeting to "Billy" --> "Hello, Billy!"

unspecified is also the value of that at the beginning of a function.

Commands#

Commands are units of operation. They take and produce data, and may have additional effects.

Parameters#

Inputs to a command are called its parameters. The caller provides their values.

Result#

The output of a command is called its result. It is available to the caller after it has received control back from a call.

Side-effects#

Commands often have side-effects; that is, they modify outside state in addition to producing a result. Side-effects are necessary for a program to really do anything, but they can also make code harder to debug. Commands without side-effects are analogous to mathematical functions.

Command invocations#

A command is invoked by naming it. This produces a command invocation expression, which passes arguments to the command's parameters and evaluates to its result.

Precise terminology#

To be as clear and precise as possible, here is a table summarizing what each confusingly similar command-related term precisely means:

TermDefinition
callA single evaluation of a command with a certain set of inputs. Often but not strictly produced by invocations.
invocationAn expression that generates a command call, using a certain set of arguments, and evaluates to its result.
parameterA term with which argument values can be associated in an invocation or call. e.g., new in make new window.
argumentAn input value from the point of view of an invocation. Is ephemeral and constant on a per-invocation basis.

Operators#

Operators are built-in commands with special invocation syntax.

Each operator has an assigned precedence ranking. This will be elaborated on as soon as some issues get ironed out.

Unary operators#

Unary operators require one operand.

Unary prefix operators#

Unary prefix operators are positioned before their operand.

SyntaxNameResult
notUnary NOTThe negation of the operand coerced to a boolean.

Binary operators#

Binary operators require two operands.

Binary infix operators#

Binary infix operators are positioned in-between their operands.

SyntaxNameResult
orOROR or disjunction of the operands coerced to booleans.
xorXORXOR or exclusive disjunction of the operands coerced to booleans.
andANDAND or conjunction of the operands coerced to booleans.
is a
is an
TypecheckWhether the first operand is of the type described by the second operand.
is not a
is not an
isn't a
isn’t a
isn't an
isn’t an
Negated typecheckWhether the first operand is not of the type described by the second operand. x is not a y = not (x is a y).
equals
[is] equal to
equals to
is
=
==
Equality checkWhether the first operand is considered equal to the second operand.
[is] not equal to
isn't equal to
isn’t equal to
[is] unequal to
is not
isn't
isn’t
not =
!=
Inequality check
Negated equality check
Whether the first operand is not considered equal to the second operand. x is not equal to y = not (x is equal to y).
[is] less than
<
Less-than checkWhether the first operand is ordered before the second operand.
[is] less than [or] equal to
[is] less than or equals
<=
Less-than-equal checkWhether the first operand is ordered before or the same as the second operand.
[is] greater than
>
Greater-than checkWhether the first operand is ordered after the second operand.
[is] greater than [or] equal to
[is] greater than or equals
>=
Greater-than-equal checkWhether the first operand is ordered after or the same as the second operand.
starts with
begins with
Starts-with checkWhether the sequential contents of first operand begin with the second or its contents.
ends withEnds-with checkWhether the sequential contents of first operand end with the second or its contents.
contains
has
Containment checkWhether the second operand or its contents are contained by the first operand.
does not contain
doesn't contain
doesn’t contain
does not have
doesn't have
doesn’t have
Non-containment check
Negated containment check
Whether the second operand or its contents are not contained by the first operand. x does not contain y = not (x contains y).
is in
is contained by
Contained-by check
Converse containment check
Whether the first operand or its contents are contained by the second operand. x is in y = y contains x.
is not in
isn't in
isn’t in
is not contained by
isn't contained by
isn’t contained by
Not-contained-by check
Converse non-containment check
Whether the first operand or its contents are not contained by the second operand. x is not in y = not (x is in y).
&ConcatenateThe contents of the first operand and the contents of the second operand joined together.
+AddThe sum of the first and second operands.
-
SubtractThe difference between the first and second operands.
*
×
MultiplyThe product of the first and second operands.
/
÷
DivideThe quotient of the first and second operands.
asCoerceThe first operand coerced to the type described by the second operand.
───────────────────
Last updated on by Ian Gregory