mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
added adjustable vectors
This commit is contained in:
parent
424fc8ce80
commit
edf839bfae
@ -219,7 +219,7 @@ nil ; for false - and the empty list
|
|||||||
|
|
||||||
;;; Vectors
|
;;; Vectors
|
||||||
|
|
||||||
;; Vectors are fixed-length arrays
|
;; Vector's literals are fixed-length arrays
|
||||||
#(1 2 3) ; => #(1 2 3)
|
#(1 2 3) ; => #(1 2 3)
|
||||||
|
|
||||||
;; Use concatenate to add vectors together
|
;; Use concatenate to add vectors together
|
||||||
@ -253,6 +253,23 @@ nil ; for false - and the empty list
|
|||||||
|
|
||||||
; => 0
|
; => 0
|
||||||
|
|
||||||
|
;;; Adjustable vectors
|
||||||
|
|
||||||
|
;; Adjustable vectors have the same printed representation
|
||||||
|
;; as fixed-length vector's literals.
|
||||||
|
|
||||||
|
(defparameter *adjvec* (make-array '(3) :initial-contents '(1 2 3)
|
||||||
|
:adjustable t :fill-pointer t))
|
||||||
|
|
||||||
|
*adjvec* ; => #(1 2 3)
|
||||||
|
|
||||||
|
;; Adding new element:
|
||||||
|
(vector-push-extend 4 *adjvec*) ; => 3
|
||||||
|
|
||||||
|
*adjvec* ; => #(1 2 3 4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Naively, sets are just lists:
|
;;; Naively, sets are just lists:
|
||||||
|
|
||||||
(set-difference '(1 2 3 4) '(4 5 6 7)) ; => (3 2 1)
|
(set-difference '(1 2 3 4) '(4 5 6 7)) ; => (3 2 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user