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.
#
CommentsYou 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 commentsLine comments start with two hypens --
and continue to the end of the current line. They never extend over multiple lines.
#
Block commentsBlock 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 )--
.
#
ValuesValues are abstract objects, like numbers. Every value belongs to a type class, discussed later in 1-4: Object Types.
#
NumbersType a number to produce a number value. Whole numbers are of type integer
, while numbers with fractional components are of type 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.
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.
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.
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
.
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.
#
CommandsCommands 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:
#
Direct object argumentsWe didn't give alert
anything to display. We can tell it to show a string
like this:
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:
Here, the real
approximation of π is the direct argument. Note that we don't have to provide a direct argument.
#
Named argumentsWe 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:
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:
Finally, we can specify multiple named arguments, as many as the command supports:
#
OperatorsOperators are special commands that are called differently and have no side-effects. Common math operators like +
and *
(multiply) are built in.
For a full list, consult the Language Reference.