all repos — hex @ dc7681f7a07e1738aee66522219e0e937c5fc537

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Refactor utils: restore 'cons', 'over', and 'dip' (new) symbols with updated comments
h3rald h3rald@h3rald.com
Mon, 07 Apr 2025 11:03:11 +0200
commit

dc7681f7a07e1738aee66522219e0e937c5fc537

parent

1503aaedd8214c2ee27daacb99349b0a2d619584

2 files changed, 25 insertions(+), 19 deletions(-)

jump to
M lib/utils.hexlib/utils.hex

@@ -20,22 +20,6 @@ swap

if ) "unless" :: -;;; cons -;; a q1 -> q2 -;; Prepends %:a%% to %:q1%%. -( - swap quote swap cat -) "cons" :: - -;;; over -;; a1 a2 -> a1 a2 a1 -;; Copies the second item on the stack and pushes it on top -( - "_over_a" : - dup _over_a swap - "_over_a" # -) "over" :: - ;;; begins ;; s1 s2 -> s3 ;; Pushes $0x1$$ on the stack if %:s1%% begins with %:s2%%, or $0x0$$ otherwise.

@@ -136,13 +120,35 @@ "_insert_result" #

"_insert_len" # ) "insert" :: - ;;; push ;; q1 a -> q2 -;; Pushes %:a%% to the end of a quotation. +;; Appends %:a%% to the end of %:q1%%. ( ' cat ) "push" :: + +;;; cons +;; a q1 -> q2 +;; Prepends %:a%% to the beginning of %:q1%%. +( + swap quote swap cat +) "cons" :: + +;;; over +;; a1 a2 -> a1 a2 a1 +;; Copies the second item on the stack and pushes it on top +( + "_over_a" : + dup _over_a swap + "_over_a" # +) "over" :: + +;;; dip +;; a1 (a2) -> a2 a1 +;; Dequotes the first item on the stack and restores the second item on top. +( + swap ' cat . +) "dip" :: ;;; reverse ;; q1 -> q2
M scripts/test.hexscripts/test.hex

@@ -130,7 +130,7 @@

((args len 0x2 ==) ("two") ("no") if "two" ==) ((dup *) "square" :: 0x2 square 0x4 == "square" #) (0x1 "tmp-a" : (tmp-a 0x3 <) (tmp-a 0x1 + "tmp-a" :) while tmp-a 0x3 ==) - (symbols len 0x5d ==) + (symbols len 0x5e ==) ;60 ((0x2 0x0 /) (error "[symbol /] Division by zero" ==) try)