~nytpu/nytpu.lisp-utils

2d9f36f9f557e7dd1b8a10b834898dbb95f8f60f — nytpu 23 days ago fc8fa00
NYTPU.LISP-UTILS: add some type declarations
1 files changed, 7 insertions(+), 3 deletions(-)

M nytpu.lisp-utils.lisp
M nytpu.lisp-utils.lisp => nytpu.lisp-utils.lisp +7 -3
@@ 82,6 82,8 @@ with just that exception handler."
     ,restart))


(declaim (ftype (function (vector &optional (integer 0 *) (or (integer 0 *) null) boolean) vector)
                subvec))
(defun subvec (vec &optional (start 0) end (displace-to-root t))
  "Return a displaced vector that's displaced into VEC containing the elements in range
[start, end], equivalent a non-copying SUBSEQ.


@@ 92,7 94,8 @@ VEC).  Returns the root vector itself if START is the first element and END is t
the root vector."
  (declare (type vector vec)
           (type (integer 0 *) start)
           (type (or (integer 0 *) null) end))
           (type (or (integer 0 *) null) end)
           (type boolean displace-to-root))
  (let ((end (or end (length vec))))
    (declare (type (integer 0 *) end))
    ;; RECURSIVE-DISPLACE as a separate function so we don't need to recalculate END (instead just


@@ 176,12 179,15 @@ the root vector."
|#


(declaim (ftype (function (function &rest list) list) nmapcar))
(defun nmapcar (function &rest lists)
  "Equivalent to MAPCAR, but destructively modify the first list in LISTS.  Same semantics as
MAPCAR: \"FUNCTION is applied to the first element of each list, then to the second element of each
list, and so on.  The iteration terminates when the shortest list runs out, and excess elements in
other lists are ignored.  The value returned by MAPCAR is a list of the results of successive calls
to FUNCTION.\"  Perfect for pointless optimization of something really minor but still annoying!"
  (declare (type function function)
           (type list lists))
  ;; nearly equivalent to (apply #'map-into (car lists) function lists), but MAP-INTO doesn't remove
  ;; elements at end of the first list if it's longer than the shortest list given
  (loop with result = (car lists)


@@ 274,8 280,6 @@ new syntax."
                        (string '#:nytpu.lisp-utils.shorthand-lambdas))
           nil))))

(macroexpand-1 '(enable-syntaxes))


(defmacro togglef (&rest places)
  "Given a list of places, expand to a SETF form consisting of each place being set to (NOT place)."