diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-10 11:08:48 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-10 11:08:48 -0800 |
commit | 08d3ca49897c85c71e7a66ce8902bbf04081c441 (patch) | |
tree | 5e3160dbae96d940eccb4a66b0219c16cb877b61 /MAINPAGE.md | |
parent | 3802eec07ec36a55815468a442add5debbbe7fb6 (diff) |
fix dip
Diffstat (limited to 'MAINPAGE.md')
-rw-r--r-- | MAINPAGE.md | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/MAINPAGE.md b/MAINPAGE.md index de5bdce..0ba8c25 100644 --- a/MAINPAGE.md +++ b/MAINPAGE.md @@ -1,3 +1,44 @@ -# Introduction +# Introduction {#mainpage} Stem aims to be a minimal interpreted stack based programming language -that allows for metaprogramming and a foreign language interface. +that allows for metaprogramming and a foreign language interface. It features +a C API that is elegant and simple. Additionally, garbage collection is +not needed in this language as the responsibility of writing memory safe +operations is put in the hands of the maintainers of the builtin functions +and FLI library maintainers. Therefore, the end user does not need to worry +about memory allocation while the implementation remains extremely simple. + +# Installation +`make` and `sudo make install`. To generate the html documentation, one must first +install `doxygen` as an optional dependency. If you are on a BSD or MacOS, you +must use `gmake`. + +# Quickstart +Because this is a stack based language, all operations are done in reverse polish. For example, to add two numbers together: +``` +3 4 + +``` +would return the result `7`. `3` and `4` get pushed onto the stack when they are written out as literals in the language, and `+` is a builtin +that adds the top two elements of the stack. In this language, there are two kinds of objects: literals +(strings, ints, floats, words, and literals of type `VERROR` are built in), and quotes that contain these literals (arrays of valid statements that can be evaluated). +Words might be new to you if you're coming from another language. If you're coming from lisp, a words are analogous to symbols. If you're coming from another +language, a word is a literal that has the special property that they can be bound to functions. For example, the `+` symbol is a word, which is bound +to the action of adding two numbers when called. + +Let's look at a real example of a REPL implementation in this language: +``` +repl [ "> " . read strquote eval repl ] func +repl +``` +`repl` is a word, which means it is a literal, and everything that is a literal gets pushed onto the stack. +Everything between the `[` and `]` is an element in a quote. Then, we see the `func` word. If a word is already bound to a function, +the function gets called instead of getting pushed to the stack, so the `func` function gets called, which takes the top two +elements off the stack, and creates a function called `repl` where now every time `repl` is called in the future, the quote is evaluated +instead. + +Let's take a closer look at the quote: +``` +"> " . read strquote eval repl +``` +`.` takes the first thing off the stack and prints it. In this case, it would print a prompt `> ` every REPL loop. `read` reads a value from stdin, +then `strquote` turns that string into a quote. `eval` pops the first thing off the stack and evaluates the quote in the same way calling a function +does, and then finally `repl` gets called again at the end so we can loop forever. |