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/03/03 08:20] 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 87: Line 95:
 ''SYMBOLP'' ''SYMBOLP''
  
-Tests if the argument is symbol. All versions of NIL are symbol. +Tests if the argument is symbol. All versions of NIL are symbol. 
  
 <code lisp> <code lisp>
Line 113: Line 121:
  
 ''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.1646320837.txt.gz · Last modified: 2022/03/03 08:20 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki