Implemented and tested rem symbol
h3rald h3rald@h3rald.com
Thu, 22 May 2025 10:04:09 +0200
2 files changed,
33 insertions(+),
1 deletions(-)
M
lib/utils.hex
→
lib/utils.hex
@@ -215,6 +215,32 @@ "_set_list" #
"_set_result" # ) "set" :: +;;; rem +;; q1 i -> q2 +;; Removes the item at index %:i%% of %:q1%%. +( + "_rem_index" : + "_rem_list" : + () "_rem_result" : + (_rem_index _rem_list len >= _rem_index 0x0 < or) + ("[symbol rem] Index out of bounds" throw) + when + 0x0 "_rem_c" : + (_rem_c _rem_list len <) + ( + (_rem_c _rem_index !=) + (_rem_result _rem_list _rem_c get ' cat "_rem_result" :) + when + _rem_c 0x1 + "_rem_c" : + ) + while + _rem_result + "_rem_index" # + "_rem_c" # + "_rem_list" # + "_rem_result" # +) "rem" :: + ;;; sort ;; q1 q2 -> q3 ;; Sorts the items of q1 based on the comparison quotation q2 (must push 0x0 or 0x1 on the stack).
M
scripts/test.hex
→
scripts/test.hex
@@ -131,7 +131,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 0x63 ==) + (symbols len 0x64 ==) ;60 ((0x2 0x0 /) (error "[symbol /] Division by zero" ==) try)@@ -342,6 +342,12 @@ ((0x3 0x5 0x2 0x1 0x4) (<) sort (0x5 0x4 0x3 0x2 0x1) ==)
(("a" "c" "b") (>) sort ("a" "b" "c") ==) (("a" "c" "b") (<) sort ("c" "b" "a") ==) ;182 + + ((0x1 0x2 0x3 0x4) 0x2 rem (0x1 0x2 0x4) ==) + (((0x1 0x2 0x3 0x4) 0x4 rem) (error) try "[symbol rem] Index out of bounds" ==) + ((0x1 0x2 0x3 0x4) 0x0 rem (0x2 0x3 0x4) ==) + ((0x1 0x2 0x3 0x4) 0x3 rem (0x1 0x2 0x3) ==) + ;186 ) "TESTS" :