Hello everyone.
I'm trying to implement ITERATIVE "last" function.
But it doesn't seem to work. It is important I use do* . However if you have any suggestion of good "alternatives" it's ok!
I know "last" function accepts &optional n , but this is a "simplified" one. However I accept any suggestion to do the "full" one.
(defun last-it (lista)
( do*
;; NO VARS ;;
(
(equal (list-length lista) 1) ;; <== when there is just one element left ==> stop
lista ; return lista
)
(set lista (cdr lista)) ; ** ;; <== like "cdr recursion"
)
)
What is wrong? It loads...but give error "setf has no value".
And if here ** I write
((set lista (cdr lista))
==> infinite loop
Thank you
I'm trying to implement ITERATIVE "last" function.
But it doesn't seem to work. It is important I use do* . However if you have any suggestion of good "alternatives" it's ok!
I know "last" function accepts &optional n , but this is a "simplified" one. However I accept any suggestion to do the "full" one.
(defun last-it (lista)
( do*
;; NO VARS ;;
(
(equal (list-length lista) 1) ;; <== when there is just one element left ==> stop
lista ; return lista
)
(set lista (cdr lista)) ; ** ;; <== like "cdr recursion"
)
)
What is wrong? It loads...but give error "setf has no value".
And if here ** I write
((set lista (cdr lista))
==> infinite loop
Thank you