all repos — hex @ 78163ab82462934a443b32008d7c3ce263a3170e

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

Tested all utils symbols.
h3rald h3rald@h3rald.com
Fri, 23 May 2025 08:05:20 +0200
commit

78163ab82462934a443b32008d7c3ce263a3170e

parent

c1f35694c7fc138c8c0356ad613cbc6034ca6955

2 files changed, 66 insertions(+), 53 deletions(-)

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

@@ -136,36 +136,36 @@ "_ends_suffix" #

"_ends_s" # ) "ends" :: -;; insert +;; ins ;; q1 a i -> q2 ;; Inserts item %:a%% before position %:i%% within a quotation. ( - "_insert_index" : - "_insert_item" : - "_insert_list" : - 0x0 "_insert_c" : - () "_insert_result" : - _insert_list len "_insert_len" : - (_insert_index _insert_len >= _insert_index 0x0 < or) - ("[symbol insert] Index out of bounds" throw) + "_ins_index" : + "_ins_item" : + "_ins_list" : + 0x0 "_ins_c" : + () "_ins_result" : + _ins_list len "_ins_len" : + (_ins_index _ins_len >= _ins_index 0x0 < or) + ("[symbol ins] Index out of bounds" throw) when - (_insert_c _insert_len <) + (_ins_c _ins_len <) ( - (_insert_c _insert_index ==) - (_insert_result _insert_item ' cat "_insert_result" :) + (_ins_c _ins_index ==) + (_ins_result _ins_item ' cat "_ins_result" :) when - _insert_result _insert_list _insert_c get ' cat "_insert_result" : - _insert_c 0x1 + "_insert_c" : + _ins_result _ins_list _ins_c get ' cat "_ins_result" : + _ins_c 0x1 + "_ins_c" : ) while - _insert_result - "_insert_index" # - "_insert_item" # - "_insert_list" # - "_insert_c" # - "_insert_result" # - "_insert_len" # -) "insert" :: + _ins_result + "_ins_index" # + "_ins_item" # + "_ins_list" # + "_ins_c" # + "_ins_result" # + "_ins_len" # +) "ins" :: ;;; reverse ;; q1 -> q2

@@ -340,33 +340,33 @@ "_max_result" #

"_max_c" # ) "max" :: -;;; intpl +;;; fmt ;; s1 q -> s2 ;; Substitutes %:$0%% to %%$9%% placeholders in %:s1%% with items in %:q%%. ( - "_intpl_q" : - "_intpl_s" : - 0x0 "_intpl_c" : - (_intpl_q len 0xa >) - ("[symbol intpl] Only a maximum of 10 placeholders are supported" throw) + "_fmt_q" : + "_fmt_s" : + 0x0 "_fmt_c" : + (_fmt_q len 0xa >) + ("[symbol fmt] Only a maximum of 10 placeholders are supported" throw) when - (_intpl_c _intpl_q len <) + (_fmt_c _fmt_q len <) ( - _intpl_s "$" _intpl_c str cat _intpl_q _intpl_c get gsub "_intpl_s" : - _intpl_c 0x1 + "_intpl_c" : + _fmt_s "$" _fmt_c str cat _fmt_q _fmt_c get gsub "_fmt_s" : + _fmt_c 0x1 + "_fmt_c" : ) while - _intpl_s - "_intpl_s" # - "_intpl_q" # - "_intpl_c" # -) "intpl" :: + _fmt_s + "_fmt_s" # + "_fmt_q" # + "_fmt_c" # +) "fmt" :: ;;; each ;; q1 q2 -> * ;; Applies %:q2%% to each element of %:q1%%. ( - 0x0 ' cat map pop + (0x0) cat map drop ) "each" :: ;;; filter

@@ -378,7 +378,7 @@ "_filter_list" :

() "_filter_result" : _filter_list ( "_filter_each_item" : - (_filter_each_item _filter_fn) + (_filter_each_item _filter_fn .) ( _filter_result _filter_each_item push "_filter_result" : )

@@ -397,15 +397,20 @@ (

"_slice_end" : "_slice_start" : "_slice_str" : - (_slice_start _slice_end <) - (0x0 "_slice_result" :) + "" "_slice_result" : + (_slice_end _slice_str len >= _slice_start 0x0 < or) + ("[symbol slice] Index out of bounds" throw) + when + (_slice_start _slice_end <=) ( - _slice_str _slice_start get _slice_result : + _slice_result _slice_str _slice_start get cat "_slice_result" : _slice_start 0x1 + "_slice_start" : ) while - "_slice_end" # - "_slice_start" # - "_slice_str" # + _slice_result + "_slice_end" # + "_slice_start" # + "_slice_str" # + "_slice_result" # ) "slice" ::
M scripts/test.hexscripts/test.hex

@@ -310,7 +310,7 @@

((0x1 0x2 0x3) 0x0 swons (0x0 0x1 0x2 0x3) ==) ((0x1 0x2 0x3) unswons stack ((0x2 0x3) 0x1) == swap drop swap drop) ("a" "b" over stack "_r" : drop drop drop ("a" "b" "a") _r == "_r" #) - (0x1 (0x2) dip stack "_r" : (0x2 0x1) _r == "_r" #) + (0x1 (0x2) dip stack "_r" : (0x2 0x1) _r == "_r" # drop drop) ;162 ("This is a test" "This" begins)

@@ -319,10 +319,10 @@ ("This is a test" "test" ends)

("This is a test" "Test" ends not) ;166 - ((0x1 0x2 0x3 0x5 0x6) "a" 0x3 insert (0x1 0x2 0x3 "a" 0x5 0x6) ==) - ((0x1 0x2 0x3 0x5 0x6) "a" 0x0 insert ("a" 0x1 0x2 0x3 0x5 0x6) ==) - ((0x1 0x2 0x3 0x5 0x6) "a" 0x4 insert (0x1 0x2 0x3 0x5 "a" 0x6) ==) - ((0x1 0x2 0x3 0x5 0x6) "a" 0x1 insert (0x1 "a" 0x2 0x3 0x5 0x6) ==) + ((0x1 0x2 0x3 0x5 0x6) "a" 0x3 ins (0x1 0x2 0x3 "a" 0x5 0x6) ==) + ((0x1 0x2 0x3 0x5 0x6) "a" 0x0 ins ("a" 0x1 0x2 0x3 0x5 0x6) ==) + ((0x1 0x2 0x3 0x5 0x6) "a" 0x4 ins (0x1 0x2 0x3 0x5 "a" 0x6) ==) + ((0x1 0x2 0x3 0x5 0x6) "a" 0x1 ins (0x1 "a" 0x2 0x3 0x5 0x6) ==) ;170 ((0x4 0x3 "c" 0x2 "b" 0x1 "a") reverse ("a" 0x1 "b" 0x2 "c" 0x3 0x4) ==)

@@ -355,12 +355,20 @@ ((0x1 0x4 0x5) min 0x1 ==)

((0x1 0x4 0x5) max 0x5 ==) ;190 - ("$0, $1!" ("hello" "world") intpl "hello, world!" ==) - (("" ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n") intpl) (error) try "[symbol intpl] Only a maximum of 10 placeholders are supported" ==) - ("This is a $0, and another $0, and yet another $0" ("test") intpl "This is a test, and another test, and yet another test" ==) - ("$0, $2, $1!" ("first" "third") intpl "first, $2, third!" ==) + ("$0, $1!" ("hello" "world") fmt "hello, world!" ==) + (("" ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n") fmt) (error) try "[symbol fmt] Only a maximum of 10 placeholders are supported" ==) + ("This is a $0, and another $0, and yet another $0" ("test") fmt "This is a test, and another test, and yet another test" ==) + ("$0, $2, $1!" ("first" "third") fmt "first, $2, third!" ==) ;194 + (0x0 "_a" : (0x1 0x2 0x3) (_a + "_a" :) each _a 0x6 == "_a" #) + ((0x1 0x2 0x3 0x4) (0x2 % 0x0 ==) filter (0x2 0x4) ==) + ("Testing" 0x1 0x3 slice "est" ==) + (("a" 0xffffffff 0x0 slice) (error) try "[symbol slice] Index out of bounds" ==) + ;198 + + (("a" 0x0 0x1 slice) (error) try "[symbol slice] Index out of bounds" ==) + ("a" 0x0 0x0 slice "a" ==) ) "TESTS" :