1-2: Basic Syntax
BushelScript, being a programming language, has syntax which must be adhered to.
See also: Quick Tutorial.
#
CommentsComments 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.
#
ValuesNumbers#
integer
s#
Positive and negative whole numbers, no fractions. Any numeric literal in the appropriate range and without a decimal point produces an integer
. integer
s store signed 64-bit values, which means -2⁶³ ≤ 𝑥 < 2⁶³ for all integer
s 𝑥.
real
s#
Positive and negative numbers with fractions allowed. A numeric literal with a .
decimal point produces a real
.
real
s use double-precision floating-point format. This provides a huge range of representable values, but can cause imprecision in base-10 calculations: real
s 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
.
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.
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.
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.
unspecified
is also the value of that
at the beginning of a function.
#
CommandsCommands are units of operation. They take and produce data, and may have additional effects.
#
ParametersInputs to a command are called its parameters. The caller provides their values.
#
ResultThe output of a command is called its result. It is available to the caller after it has received control back from a call.
#
Side-effectsCommands 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 terminologyTo be as clear and precise as possible, here is a table summarizing what each confusingly similar command-related term precisely means:
Term | Definition |
---|---|
call | A single evaluation of a command with a certain set of inputs. Often but not strictly produced by invocations. |
invocation | An expression that generates a command call, using a certain set of arguments, and evaluates to its result. |
parameter | A term with which argument values can be associated in an invocation or call. e.g., new in make new window . |
argument | An 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 operatorsUnary operators require one operand.
Unary prefix operators#
Unary prefix operators are positioned before their operand.
Syntax | Name | Result |
---|---|---|
not | Unary NOT | The negation of the operand coerced to a boolean . |
#
Binary operatorsBinary operators require two operands.
Binary infix operators#
Binary infix operators are positioned in-between their operands.
Syntax | Name | Result |
---|---|---|
or | OR | OR or disjunction of the operands coerced to boolean s. |
xor | XOR | XOR or exclusive disjunction of the operands coerced to boolean s. |
and | AND | AND or conjunction of the operands coerced to boolean s. |
is a is an | Typecheck | Whether 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 typecheck | Whether 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 check | Whether 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 check | Whether the first operand is ordered before the second operand. |
[is] less than [or] equal to [is] less than or equals <= ≤ | Less-than-equal check | Whether the first operand is ordered before or the same as the second operand. |
[is] greater than > | Greater-than check | Whether the first operand is ordered after the second operand. |
[is] greater than [or] equal to [is] greater than or equals >= ≥ | Greater-than-equal check | Whether the first operand is ordered after or the same as the second operand. |
starts with begins with | Starts-with check | Whether the sequential contents of first operand begin with the second or its contents. |
ends with | Ends-with check | Whether the sequential contents of first operand end with the second or its contents. |
contains has | Containment check | Whether 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) . |
& | Concatenate | The contents of the first operand and the contents of the second operand joined together. |
+ | Add | The sum of the first and second operands. |
- − | Subtract | The difference between the first and second operands. |
* × | Multiply | The product of the first and second operands. |
/ ÷ | Divide | The quotient of the first and second operands. |
as | Coerce | The first operand coerced to the type described by the second operand. |
─────────── | ──────── |