Fundamentals
Let's kick things off with some of the most basic operations so you can use Prowl like a calculator.
Expressions
The first thing you should know about is that all files in Prowl are expressions. Most other languages like Python, C, Java, OCaml, and so on have a concept of top-level definitions, or something more complicated, which must house all the expressions you can write. In Prowl, not so - files are simply expressions.
Literals
In stack languages, all "values" are really functions, which operate between stacks. Literals are functions which accept a stack, any stack, and produce a new stack with the value representing the literal on top. Juxtaposing these functions composes them, which is how we can create new programs that do interesting things.
5 /* Places a 5 on the stack */
5 7 /* Places a 5 and then a 7 on the stack */
Prowl has many kinds of literals, here are some of them:
42 /* Integer */
2.3 /* Float */
"Hello!" /* String */
'x' /* Char */
<> /* Unit */
Output
Prowl makes output easy using this one simple rule: the contents of the stack is printed at the end of execution, when the program completes. For the time being, there is no put
(print) function - programs are pure - you must write your programs in a way such that the final stack contains your answer.
5
should print:
5
5 7
should print:
5
7
The values on the stack are printed last-final, so that they match the order of execution in a naive program.
Input
You may be wondering now how user input can be retrieved. Prowl makes this simple as well - command line arguments are placed on the stack at the start of execution. However, all command line arguments are placed as strings.
Program: 7
Invocation: prowl path/program.prw -i 5
Output:
5
7
Note again that 5 is a string, but strings are shown without quotes.
Arithmetic
Let's do some math! Prowl is unusual among stack languages in that it supports infix. It looks the same as in most other programming languages. Prowl also implements the operator precedence that you should be familiar with from math.
5 + 6
==> 11
5 - 1 - 2
==> 2
+
is add-
is subtract*
is multiply/
is divide**
is power
Additionally, parentheses can be used for grouping.
6 * (1 + 1)
==> 12