From 1e6ffc1fa215c4c44b0fd71cf3b97167e9c065fb Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 1 Sep 2024 16:45:55 +0200 Subject: [PATCH] util: provide pointer (ptr = (make-array nil) --- test/test-core.lisp | 4 ++++ util/util.lisp | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test-core.lisp b/test/test-core.lisp index 56c9bcb..b0e550c 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -67,6 +67,10 @@ (util:lgi (crypt:create-secret)) (let ((now (get-universal-time))) (== (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:rtrim '(1 2 nil 3 nil)) '(1 2 nil 3)) (== (util:to-keyword "hello-kitty") :hello-kitty) diff --git a/util/util.lisp b/util/util.lisp index 747956d..95ad263 100644 --- a/util/util.lisp +++ b/util/util.lisp @@ -6,6 +6,7 @@ #+sbcl (:import-from :sb-ext #:add-package-local-nickname) (:export #:make-vars-format #:lg #:lgd #:lgi #:lgw #:from-unix-time #:to-unix-time + #:ptr #:rfill #:rtrim #:loop-plist #:filter-plist #:plist-pairs #:plist-equal #:plist-add #:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string @@ -41,7 +42,10 @@ (defun to-unix-time (time) (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) (mapcar #'(lambda (x) (pop ls)) ll))