util: provide pointer (ptr = (make-array nil)

This commit is contained in:
Helmut Merz 2024-09-01 16:45:55 +02:00
parent f6a361f4b8
commit 1e6ffc1fa2
2 changed files with 9 additions and 1 deletions

View file

@ -67,6 +67,10 @@
(util:lgi (crypt:create-secret)) (util:lgi (crypt:create-secret))
(let ((now (get-universal-time))) (let ((now (get-universal-time)))
(== (util:from-unix-time (util:to-unix-time now)) now)) (== (util:from-unix-time (util:to-unix-time now)) now))
(let* ((x (util:ptr))
(y x))
(setf (aref y) 42)
(== (aref x) 42))
(== (util:rfill '(1 2 3 4 5) '(a b c)) '(a b c nil nil)) (== (util:rfill '(1 2 3 4 5) '(a b c)) '(a b c nil nil))
(== (util:rtrim '(1 2 nil 3 nil)) '(1 2 nil 3)) (== (util:rtrim '(1 2 nil 3 nil)) '(1 2 nil 3))
(== (util:to-keyword "hello-kitty") :hello-kitty) (== (util:to-keyword "hello-kitty") :hello-kitty)

View file

@ -6,6 +6,7 @@
#+sbcl (:import-from :sb-ext #:add-package-local-nickname) #+sbcl (:import-from :sb-ext #:add-package-local-nickname)
(:export #:make-vars-format #:lg #:lgd #:lgi #:lgw (:export #:make-vars-format #:lg #:lgd #:lgi #:lgw
#:from-unix-time #:to-unix-time #:from-unix-time #:to-unix-time
#:ptr
#:rfill #:rtrim #:rfill #:rtrim
#:loop-plist #:filter-plist #:plist-pairs #:plist-equal #:plist-add #:loop-plist #:filter-plist #:plist-pairs #:plist-equal #:plist-add
#:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string #:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string
@ -41,7 +42,10 @@
(defun to-unix-time (time) (defun to-unix-time (time)
(when time (- time +unix-time-base+))) (when time (- time +unix-time-base+)))
;;;; lists and loops ;;;; pointers, lists, loops
(defun ptr (&optional x)
(make-array nil :initial-element x))
(defun rfill (ll ls) (defun rfill (ll ls)
(mapcar #'(lambda (x) (pop ls)) ll)) (mapcar #'(lambda (x) (pop ls)) ll))