(defun insert (number lst)
(let ((before nil))
(if (= (length lst) 0) (return-from insert (list number)))
(loop for n from 0 to (1- (length lst)) do
(if (< number (nth n lst)) (progn (nconc before (list number)) (nconc before lst) (return-from insert before) )
(progn (nconc before (list (pop lst))))))
(nconc before (list number))
(return-from insert before)))
So, I'm trying to insert a number sorted in the list. Forgive for my somehow bad LISP practice, I started learning not much time ago.
I'm going through the list and inserting the elements into a 'before' list. If the number I want to insert is less than the list element I'm currently in, I append the number to insert in the 'before' list then I append what's left of the original list 'lst' to the 'before' list, then returning 'before'.
However, this function always returns NIL. Any ideas why? I mean, both pop and nconc are destructive...