Skip to main content

1-2: Basic Syntax

Syntax is the structure of language. Programming languages have stricter syntactic rules than natural languages, and BushelScript is no exception.

See also: Language Reference.

Comments#

You can write comments to help people understand your code. Use them to explain the behavior, purpose or design of complicated code, to help others adapt your code to their needs, or even to share ASCII art (please don't).

Your programs will work just fine without any comments. Then again, a car would work just fine without an instruction manual. What and why you comment is really up to you.

There are two kinds of comments:

Line comments#

Line comments start with two hypens -- and continue to the end of the current line. They never extend over multiple lines.

-- I'm a line comment
-- You can write whatever you like here.
-- The computer doesn't care!
-- Though other humans probably will 😉
this is not a line comment and will probably cause an error
-- An empty line comment:
--

Block comments#

Block comments start with two hyphens and an opening parenthesis --(, and they continue across any number of lines until a closing parenthesis and two more hyphens are reached )--.

--( Single-line block comments are possible )--
--( Multi-line
block comments
are too )--
--(
Whatever style
floats your boat.
)--

Values#

Values are abstract objects, like numbers. Every value belongs to a type class, discussed later in 1-4: Object Types.

Numbers#

Type a number to produce a number value. Whole numbers are of type integer, while numbers with fractional components are of type real.

123 -- integer
1.23 -- real

string, a sequence of characters#

Type anything between quotation marks to produce a string, which is a fancy name for a glob of text, like a character, word, sentence, or doctoral dissertation.

-- Note that each of these lines produces a string that is
-- immediately discarded; none of this actually does
-- much of anything.
-- That is to say, don't write real programs like this.
"a"
"string"
"is composed of one or more letters, or digits 1234567890, or"
"anything, really."
"To include a quotation mark character in a string, type"
"a backslash like this \" to \"escape\" it."
"Strings can also be empty, like this next one:"
""

boolean, truth and falsity#

Type true to produce a value representing truth and false for a value representing falsity.

These boolean values are more typically produced when ask a yes-or-no question. For example, "1 is a number" is, under usual definitions, indisputably true; while "the character count of the most recent tweet on Twitter is 49" may or may not be true, depending on the state of the world when we ask the question.

true -- boolean
false -- boolean
1 = 2 -- boolean (more on this below)

missing, the intentional absence of a value#

You can type missing to get a value that represents the lack of an otherwise meaningful value. For instance, if I asked "what is your great niece's nephew's birthday?", and you replied that that person doesn't exist, we could represent this formally as missing—a placeholder for the lack of a birthday value.

missing

unspecified, the incidental absence of a value#

Finally, you can type unspecified to get a value that represents the "incidental" lack of a value. unspecified is often generated by other language constructs. In particular, it is the default value for variables. If you're familiar with JavaScript, unspecified is essentially undefined.

unspecified
let my variable
my variable --> unspecified

Aside (advanced): As an example of why distinguishing between "intentional" and "incidental" lack-of-value is useful, consider a function that makes a REST API request with parameters. Users should be able to specify a "null" JSON value for some parameters, but omit the others entirely from the request. The function can distinguish these situations by encoding JSON "null" if the value is missing, and omitting a parameter entirely if the value is unspecified. With this design, an invocation of the command that doesn't name every parameter will have those parameters omitted from the API call.

Commands#

Commands are actions like add, remove, search, and send. They can take data as input and produce data as output, and they may have additional effects.

We can invoke (run) a command by typing its name. For example, alert is the built-in command that we used in Step 1: User Interaction:

alert

Direct object arguments#

We didn't give alert anything to display. We can tell it to show a string like this:

alert "some message"

The input values we give to a command are called the arguments, and this special argument, the direct argument, comes right after the name of the command. Another example is:

cos 3.14159265

Here, the real approximation of π is the direct argument. Note that we don't have to provide a direct argument.

Named arguments#

We can provide additional input as named arguments. To do this, we type the name of a parameter that the command defines, and follow that with the value. For example:

send "Hey!" to "ian@example.com"

This invocation provides two arguments: The direct argument "Hey!", and the named argument "ian@example.com" associated with the parameter to. If the command doesn't require it, we can also provide only named arguments:

download from "https://example.com/"

Finally, we can specify multiple named arguments, as many as the command supports:

login "ian@example.com" to "example.com" password "password123"

Operators#

Operators are special commands that are called differently and have no side-effects. Common math operators like + and * (multiply) are built in.

1 + 2
not (true and false)

For a full list, consult the Language Reference.

Last updated on by Ian Gregory