I'm on a no-AutoCAD computer, so I can't check, but does that assume their original list is always going to start with 0, or that if it doesn't, they want all the slots from 0 up covered? That is, given a list like:
'(12 14 15 17)
wouldn't it return:
(nil nil nil nil nil nil nil nil nil nil nil nil 12 nil 14 15 nil 17)
? And what if there are any negative numbers?
@Moshe-A , do you want only the positions within the range of your original numbers? If so, and for a list of integers only [including negative], maybe something like [untested]:
(defun nilgaps (lst / n result)
(repeat (- (setq n (1+ (apply 'max lst))) (apply 'min lst))
(setq result (cons (if (member (setq n (1- n)) lst) n nil) result))
)
)
That [if it works...] would not require a list already in numerical order, but would sort the list in the process. However, it would not account properly for multiple instances of the same integer in the source list, if that's a possibility.
EDIT: Tested now, and it works for me, including the self-sorting and negative-number aspects.
Kent Cooper, AIA