Open In App

Atoms in LISP

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

Pre-requisites: Introduction to LISP

Function Languages are those languages in which the basic building block is functions. In functional programming, the programmer is concerned only with functionality and not memory related variable storage and assignment sequence. There are some commonly used Functional Programming Languages as follows: 

  • LISP
  • Haskell
  • ML
  • APL

Lisp was invented by John McCarthy in 1958. It is a high level programming language. It was first implemented by Steve Russel on an IBM 704 computer.

The group of characters represented the words, group of words represents the sentences. the group of sentences from paragraphs. Thus, by adding more and more grouping eventually, larger and larger structures are possible. 

In a similar manner, In LISP, the fundamental unit used is an atom. The group of atoms forms a list. The group of many lists forms higher-order lists. atoms and lists collectively called symbolic expressions. hence symbol manipulation is nothing to list processing.

Basic LISP Functions:

There are three main building blocks of LISP:

  • Atoms
  • List
  • Symbolic Expressions
Basic Building Blocks of LISP

 

Atoms

ALL expressions in LISP are made up of lists. The list is a linear arrangement of objects separated by blanks and surrounded by parentheses. The objects are made up of either atom. Space-separated elements of a list are known as ATOMS.

Example:

name
123
Abc
a
c d

Lists

Lists are parenthesized collections of sublists or atoms. 

Example:

(a b (c d) e)
(10 20 30)

Symbolic Expressions

Expressions can be created with the help of operators. There are various arithmetic operators such as +,-,*, and / used for manipulating the LISP. 

Example:

Lisp




:LISP - ATOM example
(format t "Adding 2 and 3")
(print(+ 2 3))
 
(format t "Multiply 2 and 3")
print((* 2 3))
 
(format t "Subtract 3 from 5")
print((- 5 3))
 
(format t "Evaluate expression")
print((* (+2 3 )(- 5 3) ))


Output: 

 

Note that the evaluation of expressions is based on prefix notation. The prefix is a notation in which operators come first and then two operands appear. For instance, + 2 3 will be converted to 2+3 and results in 5.

Similarly, we can use various comparison operators such as =. <, > ,/= and so on.


Last Updated : 18 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads