Fundamentals
Here, we describe the first little pieces of Quarrel. Can you feel the montage music coming?!
#
CommentsComments begin with a #
Comments can also be sectional or short mid-line circumfix style
#
AssignmentIn Quarrel, you assign using either :=
or .=
. The first one will make a copy at that new location (disconnecting it from the origin). The latter will just give you a symbolic link to the origin.
To create a constant immutable container, utilize the $
prefix operator.
#
Equality OperatorsCreate a file at src/pages/my-markdown-page.md
:
Unlike some languages that use !=
, Quarrel opts for another popular choice, the diamond operator.
#
Text DataRemember, single quotes are not for strings
#
Truth ValuesAlso called "booleans", Quarrel has the usual cast of true
and false
, however, we've also opted for a new intuitive convention yes
and no
.
#
Math OperatorsIn addition to the usual math operators, there are some other operators that represent what would normally be provided as method calls in other languages.
And there are some even weirder ones:
#
Comparison OperatorsTo allow for using <
and >
for another syntax (dictionaries), we've added an extra operator for the usual suspects. This has the inadvertent effect of aligning the character count for all comparison operators.
#
Logical OperatorsIn some languages, programmers cheat the control flow game with "short-circuit" logical operators. In Quarrel, you are provided conditional operators that already act like these "short-circuit" versions which we will discuss shortly. To help eliminate extraneous syntax, the logical operators in Quarrel do not "short-circuit" and are in fact much more traditional propositional logic operators.
#
Conditional OperatorsAs mentioned, Quarrel does not provide traditional logical operators in any way. Instead, logic is done with something like the ternary operators of some c-like languages. Of course, Quarrel takes it a step further by giving you a few additional forms that make it even easier to write control flows.
#
RoutinesThe curly braces are optional around the parameter pattern and the parentheses around the sequence are optional too. If there is ambiguity, use a ,
to separate expressions and a ;
to terminate the sequence.
Invoke a routine with the list postcircumfix operator.
Parentheses are also optional in invocation with ;
being used to terminate ambiguous sequence expressions as well.
A routine without any arguments is called a sequence. Sequences can be invoked by using the !
postfix operator.
The !
operator used on an empty sequence provides a null result, useful for creating empty containers and arguments
Parameter patterns can be variadic with the ...
operator.
No containing name means the remaining parameters are discarded.
Optional parameters are specified by using a ?@
operator inside of a pattern.
If y
is ()!
(empty), then it will set y
to "Unknown"
.
Routines are really just a binary operation from a pattern to a sequence. The pattern provides the layout of the context, the sequence provides a series of expressions given that context. Patterns and sequences are examples of aggregate data which is explained in the next section.