পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Friday, February 3, 2017

LISP - Predicates

Predicates are functions that test their arguments for some specific conditions and returns nil if the condition is false, or some non-nil value is the condition is true.
The following table shows some of the most commonly used predicates:

Predicate Description
atom It takes one argument and returns t if the argument is an atom or nil if otherwise.
equal It takes two arguments and returns t if they are structurally equal or nil otherwise
eq It takes two arguments and returns t if they are same identical objects, sharing the same memory location or nil otherwise
eql It takes two arguments and returns t if the arguments are eq, or if they are numbers of the same type with the same value, or if they are character objects that represent the same character, or nil otherwise
evenp It takes one numeric argument and returns t if the argument is even number or nil if otherwise.
oddp It takes one numeric argument and returns t if the argument is odd number or nil if otherwise.
zerop It takes one numeric argument and returns t if the argument is zero or nil if otherwise.
null It takes one argument and returns t if the argument evaluates to nil, otherwise it returns nil.
listp It takes one argument and returns t if the argument evaluates to a list otherwise it returns nil.
greaterp It takes one or more argument and returns t if either there is a single argument or the arguments are successively larger from left to right, or nil if otherwise.
lessp It takes one or more argument and returns t if either there is a single argument or the arguments are successively smaller from left to right, or nil if otherwise..
numberp It takes one argument and returns t if the argument is a number or nil if otherwise.
symbolp It takes one argument and returns t if the argument is a symbol otherwise it returns nil.
integerp It takes one argument and returns t if the argument is an integer otherwise it returns nil.
rationalp It takes one argument and returns t if the argument is rational number, either a ratio or a number, otherwise it returns nil.
floatp It takes one argument and returns t if the argument is a floating point number otherwise it returns nil.
realp It takes one argument and returns t if the argument is a real number otherwise it returns nil.
complexp It takes one argument and returns t if the argument is a complex number otherwise it returns nil.
characterp It takes one argument and returns t if the argument is a character otherwise it returns nil.
stringp It takes one argument and returns t if the argument is a string object otherwise it returns nil.
arrayp It takes one argument and returns t if the argument is an array object otherwise it returns nil.
packagep It takes one argument and returns t if the argument is a package otherwise it returns nil.

Example 1

Create a new source code file named main.lisp and type the following code in it.
(write (atom 'abcd))
(terpri)
(write (equal 'a 'b))
(terpri)
(write (evenp 10))
(terpri)
(write (evenp 7 ))
(terpri)
(write (oddp 7 ))
(terpri)
(write (zerop 0.0000000001))
(terpri)
(write (eq 3 3.0 ))
(terpri)
(write (equal 3 3.0 ))
(terpri)
(write (null nil ))
When you execute the code, it returns the following result:
T
NIL
T
NIL
T
NIL
NIL
NIL
T

Example 2

Create a new source code file named main.lisp and type the following code in it.
(defun factorial (num)
   (cond ((zerop num) 1)
      (t ( * num (factorial (- num 1))))
   )
)
(setq n 6)
(format t "~% Factorial ~d is: ~d" n (factorial n))
When you execute the code, it returns the following result:
Factorial 6 is: 720

No comments:

Post a Comment