Use standard formatting. See http://www.gigamonkeys.com/book/syntax-and-semantics.html#formatting-lisp-code.
(defun update-feature-list (feature)
(let ((feature-index))
(setq feature-index (position feature *features-list*))
(cond ((equal feature-index nil)
;;case 1 If feature index ==nil ;;we need to add the feature
(push feature (cdr (last *features-list*)))
(setq feature-index (position feature *features-list*))))))
A cond
with one clause is meaningless. I guess you meant when
, and that you
want to update the index in any case, i. e. outside of the conditional.
(defun update-feature-list (feature)
(let ((feature-index))
(setq feature-index (position feature *features-list*))
(when (equal feature-index nil)
(push feature (cdr (last *features-list*))))
(setq feature-index (position feature *features-list*))))
You do not need to set a local variable just to return it:
(defun update-feature-list (feature)
(let ((feature-index))
(setq feature-index (position feature *features-list*))
(when (equal feature-index nil)
(push feature (cdr (last *features-list*))))
(position feature *features-list*)))
You can create the binding directly in the let
head:
(defun update-feature-list (feature)
(let ((feature-index (position feature *features-list*)))
(when (equal feature-index nil)
(push feature (cdr (last *features-list*))))
(position feature *features-list*)))
Instead of checking for equal
… nil
, use null
:
(defun update-feature-list (feature)
(let ((feature-index (position feature *features-list*)))
(when (null feature-index)
(push feature (cdr (last *features-list*))))
(position feature *features-list*)))
You can inline that variable:
(defun update-feature-list (feature)
(when (null (position feature *features-list*))
(push feature (cdr (last *features-list*))))
(position feature *features-list*))
Instead of null
… position
, use not
… member
:
(defun update-feature-list (feature)
(when (not (member feature *features-list*))
(push feature (cdr (last *features-list*))))
(position feature *features-list*))
The cdr
of the last cons in a list is not a place that you would want to push
things onto. I guess that you want to append
, but in most cases, you should
instead push to the front of the list, which is much more efficient.
There is also pushnew
for exactly this. Returning the new position does not
make much sense now, however:
(defun update-feature-list (feature)
(pushnew feature *features-list*)
(position feature *features-list*))
If you really need this order and the positions, use adjustable vectors instead:
(defvar *features-list* (make-array 10
:adjustable t
:fill-pointer 0))
(defun add-feature (feature)
(or (position feature *features-list*)
(vector-push-extend feature *features-list*))) ; v-p-e returns the index