From time to time it becomes necessary to determine if the item that is currently set to a variable or the information that is passed to a program is in the form of a list. AutoLISP currently supplies two functions for this purpose, the LISTP function and the TYPE function. While the syntax for both functions are identical, ((LISTP item) and (TYPE item)) the result returned by these functions are different. The LISTP function when supplied with an item returns either T (if the item is a list) or nil (if the item is not a list). The TYPE function returns the actual data type. Therefore, this function has a wider range of applications that it can be used for. It is not limited to only identifying lists. In the following example, both the LISTP and the TYPE functions are used to check a variety of data types.
(LISTP 3.4) ;Tests the item 3.4 to determine if the item
; is a list.
nil ;The item is a real number and the value
; returned by this function is nil.
(LISTP 3) ;Tests the item 3 to determine if the item
; is a list.
nil ;The item is an integer and the value
; returned by this function is nil.
(LISTP "Text String") ;Tests the item "Text String" to determine
; if the item is a list.
nil ;The item is a string and the value
; returned by this function is nil.
(LISTP (LIST "apple" "orange" "grape")) ;Test the result supplied by the LIST
; function. Because the LIST function is
; used to create a list, the result returned by
; this function is T.
(TYPE 3.4) ;Tests the item 3.4 to determine its data
; type.
REAL ;The result returned by the previous test
; indicates that the item is a real number.
(TYPE 3) ;Tests the item 3 to determine its data
; type.
INT ;The result returned by the previous test
; indicates that the item is an integer.
(TYPE "Text String") ;Tests the item "Text String" to determine
; its data type.
STR ;The result returned by the previous test
; indicates that the item is a string.
(TYPE (LIST "apple" "orange" "grape")) ;Tests the result supplied by the LIST
; function.
LIST ;Because the LIST function is used to create
; a list, the result returned by this function is
; a list.
No comments:
Post a Comment