Advertisement
Guest User

Untitled

a guest
Dec 12th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.30 KB | None | 0 0
  1. (:import-from :alexandria
  2.               :assoc-value)
  3.  
  4. (defparameter *issues*
  5.   (let ((vector (make-array 0
  6.                             :fill-pointer 0
  7.                             :adjustable t
  8.                             :element-type 'list)))
  9.     (vector-push-extend
  10.      (pairlis '(:id :title :description :status)
  11.               '(1 "Is working well!" "Blah blah blah" :open))
  12.      vector)
  13.    
  14.     (vector-push-extend
  15.      (pairlis '(:id :title :description :status)
  16.               '(2 "That feature doesn't work!" "Bleh.." :closed))
  17.      vector)
  18.    
  19.     (vector-push-extend
  20.      (pairlis '(:id :title :description :status)
  21.               '(3 "Found a bug!" "Bloh!" :open))
  22.      vector)
  23.    
  24.     (vector-push-extend
  25.      (pairlis '(:id :title :description :status)
  26.               '(4 "Need something to do X!" "Need this ASAP!" :open))
  27.      vector)
  28.  
  29.     vector))
  30.  
  31. (defun remove-issue (issues id)
  32.   "Remove an issue by ID"
  33.   (remove-if #'(lambda (issue)
  34.                  (= id (assoc-value issue :id)))
  35.              issues
  36.              :count 1))
  37.  
  38. (remove-issue *issues* 1)
  39. ; #(((:STATUS . :CLOSED) (:DESCRIPTION . "Bleh..") (:TITLE . "That feature doesn't work!") (:ID . 2)) ((:STATUS . :OPEN) (:DESCRIPTION . "Bloh!") (:TITLE . "Found a bug!") (:ID . 3)) ((:STATUS . :OPEN) (:DESCRIPTION . "Need this ASAP!") (:TITLE . "Need something to do X!") (:ID . 4)))
  40.  
  41. (array-has-fill-pointer-p *issues*)
  42. ; T
  43.  
  44. (setf *issues* (remove-issue *issues* 1))
  45.  
  46. (array-has-fill-pointer-p *issues*)
  47. ; NIL
  48.  
  49. (vector-push-extend
  50.      (pairlis '(:id :title :description :status)
  51.               '(9 "new!!" "different" :open))
  52.      *issues*)
  53. ; The value #(((:STATUS . :CLOSED) (:DESCRIPTION . "Bleh..")
  54. ;             (:TITLE . "That feature doesn't work!") (:ID . 2))
  55. ;            ((:STATUS . :OPEN) (:DESCRIPTION . "Bloh!")
  56. ;             (:TITLE . "Found a bug!") (:ID . 3))
  57. ;            ((:STATUS . :OPEN)
  58. ;             (:DESCRIPTION . "Need this ASAP!")
  59. ;             (:TITLE . "Need something to do X!")
  60. ;             (:ID . 4))) is not of the expected type (AND
  61. ;                                                      ARRAY
  62. ;                                                      (SATISFIES
  63. ;                                                       ARRAY-HAS-FILL-POINTER-P)).
  64. ;   [Condition of type TYPE-ERROR]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement