]> Untitled Git - monorepo.git/commitdiff
add image and start of metaprogramming article
authorPreston Pan <preston@nullring.xyz>
Fri, 26 Jan 2024 22:45:43 +0000 (14:45 -0800)
committerPreston Pan <preston@nullring.xyz>
Fri, 26 Jan 2024 22:45:43 +0000 (14:45 -0800)
blog/img/stack.png [new file with mode: 0644]
blog/stem.org
index.org

diff --git a/blog/img/stack.png b/blog/img/stack.png
new file mode 100644 (file)
index 0000000..f4c2c4d
Binary files /dev/null and b/blog/img/stack.png differ
index 17820cd87aadc872c470784145c7a3afc93d2e5c..25b89796fce455d80f54b5c4b41ca85edaa86a6a 100644 (file)
@@ -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.
index 43087aa3ec6acc26711464ef206a8f6f5409b368..89b09697f5f555ced9320554cd8704883c24ae61 100644 (file)
--- a/index.org
+++ b/index.org
@@ -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