diff options
-rw-r--r-- | blog/img/stack.png | bin | 0 -> 8826 bytes | |||
-rw-r--r-- | blog/stem.org | 28 | ||||
-rw-r--r-- | index.org | 5 |
3 files changed, 29 insertions, 4 deletions
diff --git a/blog/img/stack.png b/blog/img/stack.png Binary files differnew file mode 100644 index 0000000..f4c2c4d --- /dev/null +++ b/blog/img/stack.png diff --git a/blog/stem.org b/blog/stem.org index 17820cd..25b8979 100644 --- a/blog/stem.org +++ b/blog/stem.org @@ -105,8 +105,13 @@ There are also some basic math operations you can do: : 0.750000 One can independently verify that these results are accurate. These basic math operations take /two/ things off of the stack, does the operation -on those two numbers, and then puts them back on the stack. Then, the period character prints the value and pops them off the stack. There are predefined -words for other mathematical operations too, all listed here: +on those two numbers, and then puts the new value back on the stack, deleting the old values. Then, the period character prints the value and pops +them off the stack. + +#+CAPTION: Demonstration of the stack effect of the plus word +[[file:./img/stack.png]] + +There are predefined words for other mathematical operations too, all listed here: #+begin_src stem :exports both 0.0 sin . @@ -293,3 +298,22 @@ loop-some [ dup 0 <= [ ] [ dup . 1 - loop-some ] if ] def and we can see that it actually loops. You can modify the code to do more complex looping, and in the standard library (the ~stemlib~ folder), there is a ~loop~ function that loops any code any amount of times, written by Matthew Hinton. + +* Metaprogramming +So what is this talk of metaprogramming? To put it simply, metaprogramming is a method by which one can autonomously build code and then evaluate it, +thus allowing oneself to talk about code, or make decisions to make different code based on some inputs, before running the code. So how might +we use metaprogramming? In the standard library, we define a couple of words ~dupd~, ~dupt~: +#+begin_src stem :exports both +dupd [ [ dup ] dip ] def +dupt [ [ [ dup ] dip ] dip ] def +3 2 dupd ? +#+end_src + +#+RESULTS: +: 3 +: 3 +: 2 + +which duplicates the second and third value on the stack respectively. However, we might want to define ~dupn~ for any n, which takes in an integer +and computes ~dup~ ~n~ values down. We can do that with metaprogramming, or less abstractly, we can do it by repeatedly putting quotes inside quotes, +and then we can ~eval~ the resultant quote. @@ -31,7 +31,8 @@ If you're interested, you can read my [[file:journal/index.org][journal]]. Note entire personal life but instead will be a focus on interesting things that I think of or things that are of a technical nature. * [[file:blog/index.org][Blog]] -My blog contains many longer writings that do not fit into the mindmap format. +My blog contains many longer writings that do not fit into the mindmap format, and some +of my writings on some of the projects that I've done. * [[file:mindmap/index.org][Mindmap]] I also have a mindmap, for those of you who are interested in knowing everything. ** What is a mindmap? @@ -62,7 +63,7 @@ website: #+begin_src shell :exports code :results silent cd ~/org/website git add . -git commit -m "add blog post" +git commit -m "add image and start of metaprogramming article" git push github main rsync -azvP ~/website_html/ root@nullring.xyz:/var/www/ret2pop/ #+end_src |