summaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-09 19:26:51 -0400
committerbd <bdunahu@operationnull.com>2025-04-09 19:26:51 -0400
commit6ba1871c3825e17d33b96ffd3051239dfe18d61a (patch)
tree5cfca6ae1a6885dfde5d3ff003467d6b3c40fc44 /src/util.lisp
parent4df084d3e2785412eb086fb02ac10be5def695d1 (diff)
Saving first part of large rewrite
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp
index 027a770..93db659 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -11,6 +11,25 @@
(declare (type (integer 0 *) len))
(format nil "~V,'0b" len num))
+(defun insert-in-middle (list element)
+ (append (list (car list)) (list element) (cdr list)))
+
+(defun iota (n)
+ "Generates a number sequence from 0 to N."
+ (when (> n 0)
+ (do ((i 0 (1+ i))
+ (item 0 (1+ item))
+ (result nil (push item result)))
+ ((= i n) (nreverse result)))))
+
+(defun riffle (lst1 lst2)
+ "Given LST1 and LST2, returns a new list which is the an alternative sequence
+of the elements from both lists. Returns nil if the lists are not equal size."
+ (when (eq (length lst1) (length lst2))
+ (loop for l1 in lst1
+ for l2 in lst2
+ append (list l1 l2))))
+
(defparameter type-r
'(ADD SUB MUL QUOT REM SFTR SFTL AND OR NOT XOR ADDV SUBV MULV DIVV CMP CEV)
"R-type instructions.")