Characters in Quirl
This page explains all printable characters with a special meaning in Quirl. Note that their special meaning applies only outside text and outside comments.
-
! - The exclamation mark prefixes values of types that use floating-point arithmetic and are hence not guaranteed to be perfectly precise. Here are two examples:
!5.6655388976/10^16and!0.5t. -
" - The quotation mark occurs both at the start and at the end of text, e.g.
"Hello world!". -
# - The number sign, also called hash, marks the start of a comment. The comment runs until the end of the line.
-
$ - The dollar sign marks a placeholder which corresponds to a parameter in the definition of a function or structure. It always comes before a single small letter as in
$a. -
% - Commonly known as percent sign, this sign is actually Quirl's modulo sign. It occurs between two integers. For example,
1%7represents the residue class of integers whose remainder is 1 when divided by 7. -
& - The ampersand represents a value that is greater than any number in a set such as the integers. There is also
-&which is smaller than any number of the set.&and-&are the two possible values of Quirl's Beyond type. -
' - The apostrophe marks the start of the repetend in an infinitely repeating decimal number. For example,
0.8'3represents the number 0.833333333… and so forth, which is exactly5/6. ()- Parentheses enclose the arguments passed to a callable type. For example,
add(3 1)would apply the functionaddto the two arguments3and1to compute their sum, four. -
* - The asterisk serves as a multiplication sign in certain numbers, e.g.
!5*10^3. It also marks the second binary operation on types:Ring*Scalablerepresents an intersection type. -
+ - The plus sign serves as an optional positive unary sign as in
+5and marks addition in the usual sense as inx+1or3+7\2. It also marks the first binary operation on types:Set+Tupleis a union type.U+marks the start of a Unicode code point. -
, - The comma is equivalent to whitespace in Quirl. You can use it instead of or additionally to actual whitespace characters to delimit operands from each other.
-
- - The hyphen-minus marks negative numbers like
-8and subtraction as in2-i. -
. - The full stop or dot is used as decimal point in numbers such as
3.141592. It may also be used as namespace separator outside numbers in the future. ..- Two consecutive dots mark a range from what precedes the dots to what comes after them. Currently, the only supported range is that of Unicode code points as in
U+0041..U+005A. ...- Three consecutive dots make a type or wildcard parameter of a function variadic. For example:
...Intand...?. A variadic parameter accepts any number of arguments when the function is called. -
/ - The solidus or slash is used as a fraction sign as in the rational number
3/4or in!1.380649/10^23. -
: - The colon marks the start of a condition in the definition of a function or structure. When a function is called with certain arguments, only the mapping whose parameters match the arguments and whose condition is true is applied.
-
; - The semicolon separates two statements, so comes between them. Many other programming languages use the semicolon as statement terminator instead, requiring a semicolon after each statement. That is not the case in Quirl.
-
<> - reserved
-
= - The equals sign marks a definition in Quirl. What's left of the equals sign determines the kind of definition.
-
? - The question mark acts as a wildcard. It represents any type in parameter lists. In argument lists, it represents an unbound argument, which enables partial application of functions, e.g.
next = add(? 1). -
@ - The commercial at stands for function composition as in
not@eq($a $b). Function composition is evaluated from right to left. So the example is equivalent tonot(eq($a $b)). -
F - A single capital letter
Frepresents the truth value false. -
T - A single capital letter
Trepresents the truth value true. -
U - A single capital letter
Ufollowed by+and an uppercase hexadecimal number is a Unicode code point. It encodes a character. For example,U+1F436is the codepoint for a dog face🐶. -
[] - Square brackets start and end a tuple, for example
[1 4]. Tuples can be nested as in[[3 5] [2 1]]. -
\ - The reverse solidus, also known as backslash, serves as radical symbol. It is always followed by an unsigned integer, the radicand. That is,
\2is the positive square root of two. -
^ - The circumflex accent is used as power sign so that
x^3is x to the power of three. The base before the power sign must be eitherxor the number ten as in!4*10^12. -
_ - The low line does not have a special effect. But it is notable for being allowed in names like
snake_case. -
` - reserved
-
i - The small letter
iin numbers represents the imaginary unit. That is a square root of negative one, the other square root of negative one being-i. -
t - The small letter
tstands for the angular unit turn. One turn is equivalent to τ radians or 360 degrees. There must be a rational or floating-point real number before the unit as in1/2tor!0.5t. -
x - The small letter
xis the indeterminate in polynomials such asx^2-2x-1. Each x can have a rational or integer coefficient and a non-negative integer power. -
{} - Curly brackets mark the start and end of a set of items, for example
{1 2 "be kind"}. An empty set is represented by curly brackets with nothing except optionally space in between:{}. -
| - The vertical line seperates alternatives on the right side of a grammar production rule, for example the alternatives
"0"and"1"inBIT ~ "0" | "1". -
~ - The tilde separates left and right side in a grammar's production rule. It substitutes for the arrow usually found in literature in its place.
-
° - The degree sign stands for the angular unit degree.
1°is the same as1/360t, so90°is the same as a quarter turn,1/4t. Quirl recognizes degrees as input, but never uses degrees in its output.
Whitespace characters
The unicode characters U+0009 character tabulation, U+000A line feed, U+000D carriage return, U+0020 space and U+00A0 no-break space are recognized as space characters. Space characters separate operands. For instance, 1 2 is a list of two integers one and two. On the other hand, 12 without space in between is the single integer twelve.
The character U+000A line feed is notable for terminating a comment.
Normalization
Quirl's lexer also recognizes some more characters as equivalent to those above and replaces them accordingly. This is to make copying and pasting expressions from other sources for quick computations with Quirl more convenient. Please use the above special characters in your own code though.
⁰¹²³⁴⁵⁶⁷⁸⁹- A superscript integer is converted to a circumflex accent followed by a regular integer. For example,
x⁴²would be replaced byx^42. -
× - U+00D7 multiplication sign is converted to asterisk.
-
… - U+2026 horizontal ellipsis is converted to three consecutive dots.
-
⁄ - U+2044 fraction slash is converted to solidus.
-
− - U+2212 minus sign is converted to hyphen-minus.
-
∕ - U+2215 division slash is converted to solidus.
-
√ - U+221A square root is converted to reverse solidus.
-
⋅ - U+22C5 dot operator is converted to asterisk.
-
⎷ - U+23B7 radical symbol bottom is converted to reverse solidus.