Friday, June 20, 2014

Predicates Or Boolean Expressions

Predicates Or Boolean Expressions


We have done parametric drawing. Now we are going to talk about predicates or boolean expressions. AutoLISP has got a lot of them.


A predicate gives back true or lase. True is presented as T and false or untrue is presented as nil.


Predicates


(= <atom> <atom> …)


This function checks if two or more texts and numbers are equal. If so T is given back. Otherwise nil is given back.


Examples:


(= 4 4.0) T
(= 20 300) nil
(= 2.4 2.4 2.4) T
(= 400 500 400) nil
(= “I” “I”) T


(/= <atom> <atom>)


This fiction is the same as the one from before. Except. T is given back if untrue and nil is given back if true.


Examples:


(/= 10 20) T
(/= “You” “You”) nil
(/= 5.34 5.44) T

(< <atom> <atom>)


This function works on numbers and texts. T is given back if the first atom is smaller than the second atom.


Examples:


(< 10 20) T
(< “b” “c”) T
(< 357 2.4) nil
(< 2.3 88) T
(< 2.3 4.4) T


(<= <atom> <atom>)


Now there is checked if both atoms are equal or the first atom is smaller than the second atom.


Examples:


(<= 10 20) T
(<= “b” “b”) T
(<= 357 33.2) nil
(<= 2.9 9) T


(> <atom> <atom>)


Now there is checked if the first atom is more than the second atom. As before. The atoms can be numbers and texts.


Examples:


(> 120 17) T
(> “c” “b”) T
(> 3.5 1792) nil
(> 77.4 4.2) T
(> 77.4 4) T


(>= <atom> <atom>)


The same as before. Except now there is checked if the atoms are equal or the first atom is more than the second atom.


Examples:


(>= 120 17) T
(>= “c” “c”) T
(>= 3.5 1792) nil
(>= 77 4 4.0) T
(>= 77 4 9) nil


(equal <expression1> <expression2> <fuzz>)


The expressions are checked. Are they equal or not. If working with numbers, you want to introduce a fuzz.


Even if numbers are supposed to be equal, there can be a little difference between them. The difference is specified in the fuzz.


Examples:


(setq f1 '(a b c))
(setq f2 '(a b c))
(setq f3 f2)


(equal f1 f3) T
(equal f3 f2) T


(setq a 1.23456)
(setq b 1.23457)


(equal a b 0.00001) T


(eq <expression1> <expression2>)


This function is used to check if two lists are equal. Are they bound to the same object? If so T is given back.


Examples:


(setq f1 '(a b c))
(setq f2 '(a b c))
(setq f3 f2)


(eq f1 f3) nil
(eq f1 f3) T


(atom <item>)


This function gives back T if the item is an atom and not a list. If it is a list, then nil is given back.


Examples:


(setq a '(x y z))
(setq b 'a)


(atom 'a) T
(atom a) nil
(atom 'b) T
(atom b T
(atom '(a b c)) nil


(listp <item>)


You want to check if the item is a list. Use this function for doing that. It gives back T if it is an item.


Examples:


(listp '(a b c)) T
(listp 'a) nil
(listp 4.343) nil


(boundp <item>)


Use this fucntion to see whether the item has got a value. The value can be a number or a text.


Examples:


(setq a 2)
(setq b nil)


(boundp 'a) T
(boundp 'b) nil


(numberp <item>)


This function checks if the item is an integer number or an real number.


Examples:


(numberp 4) T
(numberp 3.824) T
(numberp “Hallo”) nil
(numberp (setq a 10)) T


(minusp <item>)


Is the item a negative integer number or a negative real number?


Examples:


(minusp -1) T
(minusp (- 1 4)) T
(minusp 830.3) nil


(zerop <item>)


Is the value of the item zero?


Examples:


(zerop 0) T
(zerop (- 4 4.0)) T
(zerop 0.00001) nil


(and <expression> …)


This function checks if all expressions have a value of that is not nil. If one value is nil, then it gives back nil.


Examples:


(setq a 100)
(setq b nil)
(setq c “text”)


(and 1.4 a c) T
(and 1.4 a b c) nil


(or <expression> …)


This function checks if at least one expression is unequal to nil. If all expressions are equal to nil, the it gives back nil.


Examples:


(setq a 100)
(setq b nil)
(setq c “text”)


(or nil a b c) T
(or nil b '()) nil




(not <item>)


The result of this function is T is the value of the item is nil. Otherwise it is is nil.


Examples:


(null <item>)


Now there is checked if the value of the item is nil. If so then T is given back.


Examples:


(setq a 123)
(setq b nil)
(setq c “text”)


(null a) nil
(null b) T
(null c) nil
(null '()) T


(type <item>)


Here the type of the item is found. These are the types that are known in AutoLISP.


REAL real number
FILE file descriptor
STR text
INT integer number
SYM symbol
LIST list and user function
SUBSR internal AutoLISP function
PICKSET selection set
ENAME entity name
PAGETB function page table


Examples:


(setq a 123)
(setq r 3.5)
(setq t “text”)
(setq l '(a b c))


(type 'a) SYM
(type a) INT
(type r) REAL
(type t) STR
(type l) LIST
(type *) SUBR




No comments:

Post a Comment