User Tools

Site Tools


ch2_3_predic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ch2_3_predic [2022/02/20 06:43] adminch2_3_predic [2022/03/30 04:28] (current) admin
Line 1: Line 1:
 **//Predicates//** **//Predicates//**
  
-Simple functions that return ''T'' or ''NIL''.+Simple functions that return ''T'' or ''NIL''. They have no side effects.
  
 ''EQ'' ''EQ''
Line 17: Line 17:
 ''EQUAL'' ''EQUAL''
  
-Tests if two things are the same, is case and type senstive.+Tests if two things are the same, is case and type senstive.  
 + 
 +<code lisp> 
 +>(equal "aa" "AA"
 +NIL 
 + 
 +>(equal 1 1.0)   ; different type 
 +NIL             
 +</code>
  
 ''NOT'' ''NOT''
Line 64: Line 72:
  
 Tests if the argument is a list, that means cons-cell or nil. Tests if the argument is a list, that means cons-cell or nil.
- 
-''PROPER-LIST-P'' 
- 
-Tests if the argument is a proper list. Proper list means list ending with ''NIL'' in the cdr of the last cons cell. Improper list might be dotted, or even cyclic. 
  
 <code lisp> <code lisp>
Line 76: Line 80:
 T T
  
->(proper-list-p (cons 'a 'b)) ; this is conscell with B in cdr+>(listp (cons 'a 'b)) ; this is conscell with B in cdr, improper list 
 +
 +</code> 
 + 
 +''PROPER-LIST-P'' 
 + 
 +Tests if the argument is a proper list. Proper list means list ending with ''NIL'' in the cdr of the last cons cell. Improper list might be dotted, or even cyclic. 
 + 
 +<code lisp> 
 +>(proper-list-p (cons 'a 'b)) ; this is conscell with B in cdr, improper list
 NIL NIL
 </code> </code>
  
 ''SYMBOLP'' ''SYMBOLP''
 +
 +Tests if the argument is a symbol. All versions of NIL are symbol. 
 +
 +<code lisp>
 +>(symbolp 'a)          ; symbol A
 +T
 +
 +>(symbolp 13)
 +NIL
 +
 +>(symbolp nil)          ; symbol NIL
 +T
 +</code>
  
 ''STRINGP'' ''STRINGP''
 +
 +Tests if the argument is a string. 
 +
 +<code lisp>
 +>(stringp "hello"         
 +T
 +
 +>(stringp 'hello) 
 +NIL
 +</code>
  
 ''NUMBERP'' ''NUMBERP''
 +
 +Tests if the argument is a number (integer or float). 
 +
 +<code lisp>
 +>(numberp pi)          
 +T
 +
 +>(numberp (/ 10 5))
 +T
 +
 +>(numberp (/ 10 0))
 +;Division by zero.
 +NIL
 +</code>
  
 ''INTEGERP'' ''INTEGERP''
 +
 +Tests if the argument is a integer number. 
 +
 +<code lisp>
 +>(integerp (/ 10 5))     ; integer division
 +T
 +
 +>(integerp (/ 10 5.0))   ; poisoned by float 5.0
 +NIL
 +</code>
  
 ''ZEROP'' ''ZEROP''
 +
 +Tests if the argument is number zero. 
 +
 +<code lisp>
 +>(zerop (- 10 10))     
 +T
 +
 +>(zerop nil)
 +;Applying ZEROP on non-numeric data type!
 +NIL
 +</code>
  
 ''ODDP'' ''ODDP''
 +
 +Tests if the argument is an odd integer. 
 +
 +<code lisp>
 +>(oddp 3)     
 +T
 +
 +>(oddp 3.0) 
 +;Applying ODDP on non-integral number!
 +NIL
 +</code>
  
 ''EVENP'' ''EVENP''
 +
 +Tests if the argument is an even integer. 
 +
 +<code lisp>
 +>(evenp 2)     
 +T
 +
 +>(evenp 0)     
 +T
 +</code>
  
 ''FUNCTIONP'' ''FUNCTIONP''
 +
 +Tests if the argument is a function object. 
 +
 +<code lisp>
 +>(functionp #'+)     
 +T
 +</code>
  
 ''PACKAGEP'' ''PACKAGEP''
 +
 +Tests if the argument is a package object. 
 +
 +<code lisp>
 +>(packagep *package*)
 +T
 +</code>
  
 ''BOUNDP'' ''BOUNDP''
 +
 +Expects symbol as argument. Tests if the symbol has value binding.
 +
 +<code lisp>
 +>(boundp 'pi)
 +T
 +</code>
  
 ''FBOUNDP'' ''FBOUNDP''
 +
 +Expects symbol as argument. Tests if the symbol has function or macro binding.
 +
 +<code lisp>
 +>(fboundp '+)
 +T
 +
 +>(fboundp 'if)    ; also works for special forms
 +T
 +</code>
  
 ''SPECIAL-OPERATOR-P'' ''SPECIAL-OPERATOR-P''
 +
 +Expects symbol as argument. Tests if the symbol represents special operator.
 +
 +<code lisp>
 +>(special-operator-p '+)     ; ordinary function
 +NIL
 +
 +>(special-operator-p 'if)    ; special operator IF
 +T
 +</code>
  
ch2_3_predic.1645364603.txt.gz · Last modified: 2022/02/20 06:43 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki