about summary refs log tree commit diff stats
path: root/lua/chupacabra/refcard.md
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2024-06-09 15:41:19 -0400
committerelioat <hi@eli.li>2024-06-09 15:41:19 -0400
commit79fcbb5f40e91fc74d4d7b1491b8e246ec6a42b5 (patch)
tree08499113a679e782f997dbaaf78a78a68bed6ca6 /lua/chupacabra/refcard.md
parenta461b64cd0996f707914abc7927bb46da8026e46 (diff)
downloadtour-79fcbb5f40e91fc74d4d7b1491b8e246ec6a42b5.tar.gz
*
Diffstat (limited to 'lua/chupacabra/refcard.md')
-rw-r--r--lua/chupacabra/refcard.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/lua/chupacabra/refcard.md b/lua/chupacabra/refcard.md
new file mode 100644
index 0000000..ff805ff
--- /dev/null
+++ b/lua/chupacabra/refcard.md
@@ -0,0 +1,25 @@
+# Chupacabra Quick Reference Card
+
+Chupacabra is a stack-based programming language/calculator implemented in lua. It works a lot like any other forth, save for 2 big differences: 
+
+1. you cannot define new words
+2. you can put entire arrays on to the stack
+
+## Basic Usage
+- **Numbers**: You can push numbers onto the stack. For example, `1` pushes the number 1 onto the stack.
+- **Arrays**: You can push arrays onto the stack. For example, `[1 2 3 4]` pushes the array {1, 2, 3, 4} onto the stack.
+- **`.`**: The `.` operator pops the top element from the stack and discards it.
+
+## Array-first keywords
+- **`@`**: the `@` keyword allows you to grab a specific value from an array by index, e.g. `[10 20 30] 2 @` would return the value `20`.
+- **`@+`**: The `@+` keyword adds the top two elements on the stack. It supports addition between two numbers, a number and an array, or two arrays.
+- **`@-`**: The `@-` keyword subtracts the second topmost element on the stack from the topmost element. It supports subtraction between two numbers, a number and an array, or two arrays.
+- **`@*`**: The `@*` keyword multiplies the top two elements on the stack. It supports multiplication between two numbers, a number and an array, or two arrays.
+- **`@/`**: The `@/` keyword divides the topmost element on the stack by the second topmost element. It supports division between two numbers, a number and an array, or two arrays.
+
+## Test cases
+You can create test cases using the `tc` function from lua. The `tc` function takes an input string and an expected output, runs the input string through the Chupacabra interpreter, and checks if the output matches the expected output.
+
+For example, `tc("[1 1 1] [2 3 4] @+", {3, 4, 5})` tests that adding the arrays {1, 1, 1} and {2, 3, 4} results in the array {3, 4, 5}.
+
+There is also a totally shit repl. I'll make that better, soon...maybe.
\ No newline at end of file