AutoCAD
Advertisement
;;;WIKI-NTH-REMOVE
;;;Removes the nth item from a list
;;;Usage: (wiki-nth-remove
;;;         [n integer]
;;;         [list]
;;;       )
;|
   Edit the source code for this function at 
  http://autocad.wikia.com/wiki/Nth-remove_(AutoLISP_function)
|;
(DEFUN
   WIKI-NTH-REMOVE (N INPUTLIST / INDEXCOUNTER CURRENTATOM
                    RETURNLIST
                   )
  ;;Initialize the variables for clarity's sake
  (SETQ
    ;;For the AutoLISP (nth i list) function, the first atom index is 0
    INDEXCOUNTER 0
    CURRENTATOM NIL
    RETURNLIST NIL
  )
  ;;Loop through the list putting atoms in the return list.
  (WHILE INPUTLIST
    (SETQ CURRENTATOM (CAR INPUTLIST))
    ;;Chop current atom off the input list
    (SETQ INPUTLIST (CDR INPUTLIST))
    ;;If indexcounter /= n,
    (IF (/= INDEXCOUNTER N)
      ;;Then put the current atom in the return list
      (SETQ RETURNLIST (CONS CURRENTATOM RETURNLIST))
    )
    ;;Bump up the index counter.
    (SETQ INDEXCOUNTER (1+ INDEXCOUNTER))
  )
  ;;Reverse the backwards return list and we are done.
  (REVERSE RETURNLIST)
)
Advertisement