This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How do I call vectorp and aref twice in a cond statement

2 posts · 2612 views

;I got this whittled down as much as I can...for some reason I cant call (aref arg i) in a cond statement twice in a row. I do have to verify it is a vector 2 different ways, before I run (aref arg 0) and (aref arg i) as below...How can I do this?...I'm getting deleting unreachable code error.
(defun vector-test (&optional arg i)
  (cond ((vectorp arg)  (aref arg 0))
        ((and (vectorp arg) i)  (aref arg i))))

Re: How do I call vectorp and aref twice in a cond statement

If the second condition is true, the first condition also is true, so the first will be executed.
you could change the lines or use multiple ifs like this:
(defun vector-test (&optional arg i)
  (if (vectorp arg)
    (if i
      (aref arg 0)
      (aref arg i))))