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.
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.
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:
| 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 operators#
Unary 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 operators#
Binary 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 booleans. |
xor | XOR | XOR or exclusive disjunction of the operands coerced to booleans. |
and | AND | AND or conjunction of the operands coerced to booleans. |
is ais an | Typecheck | Whether the first operand is of the type described by the second operand. |
is not ais not anisn't aisn’t aisn't anisn’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 toequals tois=== | Equality check | Whether the first operand is considered equal to the second operand. |
[is] not equal toisn't equal toisn’t equal to[is] unequal tois notisn'tisn’tnot =!=≠ | 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 withbegins 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. |
containshas | Containment check | Whether the second operand or its contents are contained by the first operand. |
does not containdoesn't containdoesn’t containdoes not havedoesn't havedoesn’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 inis 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 inisn't inisn’t inis not contained byisn't contained byisn’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. |
| ─────────── | ──────── |