পৃষ্ঠাসমূহ

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 - Symbols

In LISP, a symbol is a name that represents data objects and interestingly it is also a data object.
What makes symbols special is that they have a component called the property list, or plist.

Property Lists

LISP allows you to assign properties to symbols. For example, let us have a 'person' object. We would like this 'person' object to have properties like name, sex, height, weight, address, profession etc. A property is like an attribute name.
A property list is implemented as a list with an even number (possibly zero) of elements. Each pair of elements in the list constitutes an entry; the first item is the indicator, and the second is the value.
When a symbol is created, its property list is initially empty. Properties are created by using get within a setf form.
For example, the following statements allow us to assign properties title, author and publisher, and respective values, to an object named (symbol) 'book'.

Example 1

Create a new source code file named main.lisp and type the following code in it.
(write (setf (get 'books'title) '(Gone with the Wind)))
(terpri)
(write (setf (get 'books 'author) '(Margaret Michel)))
(terpri)
(write (setf (get 'books 'publisher) '(Warner Books)))
When you execute the code, it returns the following result:
(GONE WITH THE WIND)
(MARGARET MICHEL)
(WARNER BOOKS)
Various property list functions allow you to assign properties as well as retrieve, replace or remove the properties of a symbol.
The get function returns the property list of symbol for a given indicator. It has the following syntax:
get symbol indicator &optional default
The get function looks for the property list of the given symbol for the specified indicator, if found then it returns the corresponding value; otherwise default is returned (or nil, if a default value is not specified).

Example 2

Create a new source code file named main.lisp and type the following code in it.
(setf (get 'books 'title) '(Gone with the Wind))
(setf (get 'books 'author) '(Margaret Micheal))
(setf (get 'books 'publisher) '(Warner Books))

(write (get 'books 'title))
(terpri)
(write (get 'books 'author))
(terpri)
(write (get 'books 'publisher))
When you execute the code, it returns the following result:
(GONE WITH THE WIND)
(MARGARET MICHEAL)
(WARNER BOOKS)
The symbol-plist function allows you to see all the properties of a symbol.

Example 3

Create a new source code file named main.lisp and type the following code in it.
(setf (get 'annie 'age) 43)
(setf (get 'annie 'job) 'accountant)
(setf (get 'annie 'sex) 'female)
(setf (get 'annie 'children) 3)

(terpri)
(write (symbol-plist 'annie))
When you execute the code, it returns the following result:
(CHILDREN 3 SEX FEMALE JOB ACCOUNTANT AGE 43)
The remprop function removes the specified property from a symbol.

Example 4

Create a new source code file named main.lisp and type the following code in it.
(setf (get 'annie 'age) 43)
(setf (get 'annie 'job) 'accountant)
(setf (get 'annie 'sex) 'female)
(setf (get 'annie 'children) 3)

(terpri)
(write (symbol-plist 'annie))
(remprop 'annie 'age)
(terpri)
(write (symbol-plist 'annie))
When you execute the code, it returns the following result:
(CHILDREN 3 SEX FEMALE JOB ACCOUNTANT AGE 43)
(CHILDREN 3 SEX FEMALE JOB ACCOUNTANT)

No comments:

Post a Comment