Tuesday, 14 February 2012

nth function in Autolisp


nth  - This function returns the Nth item in a list. The first item in a list is item zero.  
          Syntax : (nth integer list)
          integer - Any valid integer.
          list - Any valid list.
      
                 (nth) returns "Error: Too Few Arguments"      [cons requires an item and a list]
                 (nth 2 1 2 3) returns "Error: Bad Argument Type" [nth requires an integer and a list]
                 (nth 2 (list "cde" "Jeff" "Sanders")) returns "Sanders"
                 (nth 0 (list 1 2 3)) returns 1
                 (nth 1 (list 1 2 3)) returns 2
                 (nth 2 (list 1 2 3)) returns 3
                 (nth 1 (list "a" (list "b" "c") "d"))  returns ("b" "c")
                 (nth 4 (list 1 2 3 5 6 7)) returns 6