Fandom

AutoCAD

Nth-remove (AutoLISP function)

45pages on
this wiki
Add New Page
Talk0 Share
;;;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)
)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.