Renamed pop to drop.
@@ -142,7 +142,7 @@
(0x2 dup stack (0x2 0x2) ==) ((dup *) "square" :: 0x3 square 0x9 == "square" #) (("test" throw) (error "test" ==) try) - (0x1 0x2 swap pop pop pop stack (0x2) ==) + (0x1 0x2 swap drop drop drop stack (0x2) ==) ;68 (("aaa" "puts" :) (error) try "[symbol :] Failed to store symbol 'puts'" ==)@@ -227,7 +227,7 @@ (
"test\ntest\\ntest\t\"hello\"!" "_str" : _str "test1.txt" write "test1.txt" read _str == "_str" # - "rm test1.txt" exec pop + "rm test1.txt" exec drop ) (("a" not) (error) try "[symbol not] Integer required" ==) ((0x1 () xor) (error) try "[symbol xor] Two integers required" ==)@@ -248,13 +248,13 @@ ;132
(("invalid-file.txt" read) (error) try "[symbol read] Could not open file for reading: invalid-file.txt" ==) (("test" "invalid-file//" write) (error) try "[symbol write] Could not open file for writing: invalid-file//" ==) - (((0x2 0x4 "a") "test.txt" write) (error) try "[symbol write] Quotation must contain only integers" == "rm test.txt" exec pop) + (((0x2 0x4 "a") "test.txt" write) (error) try "[symbol write] Quotation must contain only integers" == "rm test.txt" exec drop) ((0x2 "test.txt" write) (error) try "[symbol write] String or quotation of integers required" ==) ;136 (("a" () write) (error) try "[symbol write] String required" ==) (("aaa" "invalid-file//" append) (error) try "[symbol append] Could not open file for appending: invalid-file//" ==) - (((0x2 "" 0x5) "test.txt" append) (error) try "[symbol append] Quotation must contain only integers" == "rm test.txt" exec pop) + (((0x2 "" 0x5) "test.txt" append) (error) try "[symbol append] Quotation must contain only integers" == "rm test.txt" exec drop) ((0x2 "test.txt" append) (error) try "[symbol append] String or quotation of integers required" ==) ;140
@@ -51,7 +51,7 @@ hex_set_doc(docs, "throw", "s", "", "Throws error 's'.");
// Stack hex_set_doc(docs, "dup", "a", "a a", "Duplicates 'a'."); - hex_set_doc(docs, "pop", "a", "", "Removes the top item from the stack."); + hex_set_doc(docs, "drop", "a", "", "Removes the top item from the stack."); hex_set_doc(docs, "swap", "a1 a2", "a2 a1", "Swaps 'a2' with 'a1'."); hex_set_doc(docs, "stack", "", "q", "Returns the contents of the stack.");
@@ -176,7 +176,7 @@ HEX_OP_THROW = 0x18,
HEX_OP_DUP = 0x19, HEX_OP_STACK = 0x1a, - HEX_OP_POP = 0x1b, + HEX_OP_DROP = 0x1b, HEX_OP_SWAP = 0x1c, HEX_OP_I = 0x1d,@@ -372,7 +372,7 @@ int hex_symbol_map(hex_context_t *ctx);
int hex_symbol_swap(hex_context_t *ctx); int hex_symbol_dup(hex_context_t *ctx); int hex_symbol_stack(hex_context_t *ctx); -int hex_symbol_pop(hex_context_t *ctx); +int hex_symbol_drop(hex_context_t *ctx); // Opcodes uint8_t hex_symbol_to_opcode(const char *symbol);
@@ -49,9 +49,9 @@ else if (strcmp(symbol, "stack") == 0)
{ return HEX_OP_STACK; } - else if (strcmp(symbol, "pop") == 0) + else if (strcmp(symbol, "drop") == 0) { - return HEX_OP_POP; + return HEX_OP_DROP; } else if (strcmp(symbol, "swap") == 0) {@@ -290,8 +290,8 @@ case HEX_OP_DUP:
return "dup"; case HEX_OP_STACK: return "stack"; - case HEX_OP_POP: - return "pop"; + case HEX_OP_DROP: + return "drop"; case HEX_OP_SWAP: return "swap"; case HEX_OP_I:
@@ -2699,7 +2699,7 @@ }
return 0; } -int hex_symbol_pop(hex_context_t *ctx) +int hex_symbol_drop(hex_context_t *ctx) { HEX_POP(ctx, item); if (item != NULL)@@ -2778,5 +2778,5 @@ hex_set_native_symbol(ctx, "map", hex_symbol_map);
hex_set_native_symbol(ctx, "swap", hex_symbol_swap); hex_set_native_symbol(ctx, "dup", hex_symbol_dup); hex_set_native_symbol(ctx, "stack", hex_symbol_stack); - hex_set_native_symbol(ctx, "pop", hex_symbol_pop); + hex_set_native_symbol(ctx, "drop", hex_symbol_drop); }
@@ -275,8 +275,10 @@ a hex program, it is looked up in the registry, and its associated value or function is pushed onto the stack.
</p> <p>Native symbols can perform manipulations on the stack; they can pop values from the stack and push values back in.</p> - <p>In the canonical implementation, native symbols are implemented as native C functions that are executed whenever the corresponding native symbol is pushed on the stack.</p> - <p>By contrast, you can only store hex literals as user-defined symbols. When storing a quotation as a symbol, it can be used as data (a list of values) or a portion of an hex program which that can then + <p>In the canonical implementation, native symbols are implemented as native C functions that are executed whenever + the corresponding native symbol is pushed on the stack.</p> + <p>By contrast, you can only store hex literals as user-defined symbols. When storing a quotation as a symbol, it + can be used as data (a list of values) or a portion of an hex program which that can then be <em>dequoted</em> through symbols like {{sym-.}}, which pushes all the items in a quotations on the stack, one by one.</p> <p>Consider the following example hex program:</p>@@ -289,11 +291,14 @@ because the logic to do so is in a quotation. To "execute" (dequote) a quotation, you must use the {{sym-.}}
symbol, which pushes all the items in the quotation on the stack, which is equivalent to the following program:</p> <pre><code> $0x3$$ $:dup$$ $:*$$ $:*$$ $:puts$$ $; prints 9$$</code></pre> - <p>While the {{sym-:}} symbol can be used to store quotations that can then be dequoted later using {{sym-.}}, typically you want to define operators which are <em>immediately dequoted</em> when pushed on the stack, thus behaving in a similar way as their native counterparts.</p> + <p>While the {{sym-:}} symbol can be used to store quotations that can then be dequoted later using {{sym-.}}, + typically you want to define operators which are <em>immediately dequoted</em> when pushed on the stack, thus + behaving in a similar way as their native counterparts.</p> <p>You can achieve this using the {{sym-::}} symbol, and the previous example can be rewritten as follows:</p> <pre><code> ($:dup$$ $:*$$ $:*$$) $"square"$$ $:::$$ $0x3$$ $:square$$ $:puts$$ $; prints 9$$</code></pre> - <p>In this case, you no longer need to explicitly dequote $:square$$ using $:.$$, because it has been stored as an <em>operator</em> and hex knows it has to be immediately dequoted when pushed on the stack.</p> + <p>In this case, you no longer need to explicitly dequote $:square$$ using $:.$$, because it has been stored as an + <em>operator</em> and hex knows it has to be immediately dequoted when pushed on the stack.</p> <h3 id="registry">Registry<a href="#top"></a></h3> <p>The registry in hex is a simple dictionary that stores symbols and their associated values or functions. The registry is used to look up symbols when they are encountered in a hex program and to store user-defined symbols@@ -538,15 +543,17 @@ <p>Stores the literal <code>a</code> in the registry as the symbol <code>s</code>.</p>
<h5 id="operator-symbol"><code>$:::$$</code> Symbol<a href="#top"></a></h5> <p><mark>a s →</mark></p> <aside>OPCODE: <code>11</code></aside> - <p>Stores the literal <code>a</code> in the registry as the symbol <code>s</code>. If %:a%% is a quotation, it will be immediately dequoted when pushed on the stack.</p> - <h5 id="free-symbol"><code>$:#$$</code> Symbol<a href="#top"></a></h5> + <p>Stores the literal <code>a</code> in the registry as the symbol <code>s</code>. If %:a%% is a quotation, it will + be immediately dequoted when pushed on the stack.</p> + <h5 id="free-symbol"><code>$:#$$</code> Symbol<a href="#top"></a></h5> <p><mark>s →</mark></p> <aside>OPCODE: <code>12</code></aside> <p>Frees the symbol <code>s</code> from the registry.</p> <h5 id="symbols-symbol"><code>$:symbols$$</code> Symbol<a href="#top"></a></h5> <p><mark>→ q</mark></p> <aside>OPCODE: <code>13</code></aside> - <p>Pushes a quotation on the stack containing the identifiers of all the symbols currently stored in the registry.</p> + <p>Pushes a quotation on the stack containing the identifiers of all the symbols currently stored in the registry. + </p> <h4 id="control-flow-symbols">Control Flow Symbols<a href="#top"></a></h4> <h5 id="if-symbol"><code>$:if$$</code> Symbol<a href="#top"></a></h5> <p><mark>q1 q2 q3 → *</mark></p>@@ -555,7 +562,7 @@ <p>Dequotes quotation <code>q1</code>, if it pushes a positive integer on the stack it dequotes
<code>q2</code>, otherwise dequotes <code>q3</code>. - </p> + </p> <h5 id="while-symbol"><code>$:while$$</code> Symbol<a href="#top"></a></h5> <p><mark>q1 q2 → *</mark></p> <aside>OPCODE: <code>15</code></aside>@@ -572,7 +579,7 @@ <h5 id="try-symbol"><code>$:try$$</code> Symbol<a href="#top"></a></h5>
<p><mark>q1 q2 → *</mark></p> <aside>OPCODE: <code>17</code></aside> <p>Dequotes quotation <code>q1</code>, if it throws an error it dequotes <code>q2</code>.</p> - <h5 id="throw-symbol"><code>$:throw$$</code> Symbol<a href="#top"></a></h5> + <h5 id="throw-symbol"><code>$:throw$$</code> Symbol<a href="#top"></a></h5> <p><mark>s →</mark></p> <aside>OPCODE: <code>18</code></aside> <p>Throws an error printing error message %:s%%.</p>@@ -585,7 +592,7 @@ <h5 id="stack-symbol"><code>$:stack$$</code> Symbol<a href="#top"></a></h5>
<p><mark> → q</mark></p> <aside>OPCODE: <code>1a</code></aside> <p>Pushes the items currently on the stack as a quotation.</p> - <h5 id="pop-symbol"><code>$:pop$$</code> Symbol<a href="#top"></a></h5> + <h5 id="drop-symbol"><code>$:drop$$</code> Symbol<a href="#top"></a></h5> <p><mark> a →</mark></p> <aside>OPCODE: <code>1b</code></aside> <p>Removes the top item from the stack.</p>@@ -608,7 +615,7 @@ <h5 id="quote-symbol"><code>$:'$$</code> Symbol<a href="#top"></a></h5>
<p><mark>a → q</mark></p> <aside>OPCODE: <code>1f</code></aside> <p>Pushes the literal <code>a</code> wrapped in a quotation on the stack.</p> - <h5 id="debug-symbol"><code>$:debug$$</code> Symbol<a href="#top"></a></h5> + <h5 id="debug-symbol"><code>$:debug$$</code> Symbol<a href="#top"></a></h5> <p><mark>q → *</mark></p> <aside>OPCODE: <code>20</code></aside> <p>Dequotes <code>q</code> with debugging enabled.</p>@@ -805,7 +812,7 @@ <aside>OPCODE: <code>43</code></aside>
<p>Pushes the string <code>s4</code> obtained by replacing the first occurrence of <code>s2</code> in <code>s1</code> by <code>s3</code>. - </p> + </p> <h5 id="map-symbol"><code>$:map$$</code> Symbol<a href="#top"></a></h5> <p><mark> q1 q2 → q3</mark></p> <aside>OPCODE: <code>44</code></aside>