diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-15 21:36:03 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-15 21:36:03 -0800 |
commit | 640f9a3f5be5528dd4f8ed658cfe4d06d833e4c9 (patch) | |
tree | ada8aa70f2f162324033fd2bf47890449525d244 | |
parent | f5f261968de27ecdd2eacedc6255da115e7b43cb (diff) |
make other thing readme
-rw-r--r-- | Doxyfile | 4 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md (renamed from MAINPAGE.md) | 0 | ||||
-rw-r--r-- | README.org | 76 | ||||
-rw-r--r-- | examples/stdlib.stem | 9 |
5 files changed, 13 insertions, 78 deletions
@@ -949,7 +949,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = include/ src/ MAINPAGE.md +INPUT = include/ src/ README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -1165,7 +1165,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = MAINPAGE.md +USE_MDFILE_AS_MAINPAGE = README.md # The Fortran standard specifies that for fixed formatted Fortran code all # characters from position 72 are to be considered as comment. A common @@ -24,6 +24,8 @@ clean: install: cp $(TARGET) /usr/local/bin/ + mkdir -p /usr/local/lib/share/stem/ + cp -r stemlib/ /usr/local/share/stem/stdlib/ doc: doxygen diff --git a/README.org b/README.org deleted file mode 100644 index e223f66..0000000 --- a/README.org +++ /dev/null @@ -1,76 +0,0 @@ -#+title: Stem - -* Credits -Big thanks to Andrei Sova for contributing ~fib.stem~ in the ~examples/~ directory. -* Introduction -Stem aims to be a small implementation of something like the forth programming language, -meaning it operates on a virtual stack. There are words, quotes, and literal types in this -language; this allows for metaprogramming. - -** Quickstart -In this language, words are anything that are not literals (strings, ints, floats), and are -not the special characters [ and ]. Literals include the types above and they work just -like in other languages, and quotes are just lists of these words and literals. - -Any literal in the language by itself gets pushed onto the stack. For example, the value: -#+begin_example -"hello world" -#+end_example -gets pushed onto the stack once it is created. - -Note that words can also act like literals, but they are different in that you can bind them to funtions: -#+begin_example -helloworld [ "hello world" . ] func -#+end_example -Where . is a builtin function that pops the first value off the stack and prints it. In this example, the helloworld -word is pushed onto the stack, then the quote ~[ "hello world" . ]~, which is just an array of these two values. Then, -the ~func~ builtin is called, which takes these two values off of the stack. As a result, whenever ~helloworld~ is used -in the future, it is expanded into whatever is in the quote. - -a useful way to know what's on the stack: -#+begin_example -? -#+end_example -is a builtin function that prints everything on the stack, where the very last thing printed is the top of the stack. - -*** Quoting and Escaping -If you want to push a word to the stack after it has been bound, you must escape it: -#+begin_example -\helloworld -#+end_example - -quotes are somewhat related to escaping. They allow the language to talk about itself, along with the ~eval~ keyword. -To get an idea of what you can do with it, consider the following example: -#+begin_example -[ hello [ "hello" . ] func ] eval -#+end_example -this statement is essentially the same statement as the above, but you can represent the entire code in a quote -before evaluation. This allows for many possibilities. For example, you may try writing a program that automatically -names functions and automatically changes what those functions do. - -*** Loops -Looping in this language is done via recursion. Because the language is stack-based, recursion is not more memory efficient -than looping if using tail recursion. For example, the REPL for this language is implemented like so: -#+begin_example -loop [ "> " . read strquote eval loop ] func loop -#+end_example -Where read takes in a string and prints it before reading a value, strquote turns a string into a quote, and loop is the function that calls -itself. - -*** Curry, Compose, Qstack, Quote -These functions are important for manipulating quotes. For example: -#+begin_example -[ a b ] 6 5 quote curry compose -#+end_example -first turns 5 into ~[ 5 ]~, then curry adds 6 to the end of the quote. Compose takes two quotes and adjoins them together. Qstack -simply turns everything on the stack into a quote, then puts it on the stack. For example: -#+begin_example -1 2 3 4 5 6 7 qstack -#+end_example -Returns the quote ~[ 1 2 3 4 5 6 7 ]~. -* CLib -This language has a foreign language interface (FLI). The FLI functions via including ~parser.h~ and creating the functions -~add_funcs~ and ~add_objs~. Each custom object needs to have its own free, print, and copy functions. For some implementation examples, -see the ~builtins.c~ file. Later on there will be more documentation. -* Install -~make~ and ~sudo make install~. diff --git a/examples/stdlib.stem b/examples/stdlib.stem index a063c9b..df81cd8 100644 --- a/examples/stdlib.stem +++ b/examples/stdlib.stem @@ -1,6 +1,9 @@ evalstr [ strquote eval ] func include [ fread evalstr ] func +# Author: Preston Pan +neg [ 0 swap - ] func + # Author of loop function: Andrei S loop [ swap dup 0 > [ @@ -15,6 +18,12 @@ dupd [ [ dup ] keep ] func over [ dupd swap ] func dup2 [ over over ] func dip2 [ swap [ dip ] dip ] func +while [ dup2 [ [ ] if ] dip2 over [ while ] [ dsc dsc ] if ] func loop-times [ dup2 [ swap [ ] if ] dip2 dup [ 1 - loop-times ] [ dsc dsc ] if ] func + +d>base [ [ pow * "" swap ] keep2 + +[ [ over ] [ [ dup2 / floor * swap over - ] keep [ [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "↊" "↋" ] vat swap + ] with dip2 ] while dsc2 dup len(str-len) ] dip +- dup2 tail [ head "." ] dip + + ] func |