Skip to content
Related Articles

Related Articles

Basic Syntax in LISP

View Discussion
Improve Article
Save Article
  • Last Updated : 26 May, 2022

LISP is a list processing programming language. It is widely used in the manipulation of data strings. It provides an input and output library. LISP provides a macro system and provides well control structures for the manipulation of data.

Basic Blocks in LISP:

There are three basic building blocks of the LISP program:

  • Atom
  • List
  • String

Atom: An atom includes numbers, special characters, and Strings.

hello-Geeks-Learn-coding
8789902
Color#268
atom145
Ayush
*Namaste*

List: A list is a sequence of number or string contiguous characters in parentheses.

(g ( e e a) 12 34 5)
(sun mon tue wed thur fri sat)
( )
( People call me list)
(Geeks ( Love coding program))

String: A string is a group of characters enclosed in double quotation marks.

" People call me string"
"Steps require to solve this is:"
"Hello 'How are you Geeks'! "
"a ba c d efg #$%^&!"

Comments in LISP:

A ;(semicolon) is used to represent a single line comment in LISP.

; I am a comment in LISP 
; I will not be executed in the program.

Example 1:

Lisp




;Here we are multiplying the two number .
(write-line "Multiplication")
(write (* 2 3))

Output:

 

Naming Conventions in LISP:

 Syntax:

(write-line string)

Example 2:

Lisp




(write-line "GeeksforGeeks")

Output:

GeeksforGeeks

Importance of Single Quotation Mark Note:

A single quote is used in representing data literal. It returns data.

Using a Single quote:

(student? ‘Geek)

The list is a function, so the student gets evaluated to a function. ‘Geek is a notation for (quote Geek). Evaluating (quote Geek) gives the symbol Geek. So next the function is applied to the symbol Geek and a return value is computed.

Without using a single quote:

(student? Geek)

Here we have a function application and the student gets evaluated for a function. This time Geek is a variable. Evaluating Geek gives the value that is bound to it – whatever it is. So then the function is applied to the value of the variable Geek.

Example 3:  

Lisp




(write-line "single quote used, it inhibits evaluation")
(write '(* 2 3))
(write-line " ")
(write-line "single quote not used, so expression evaluated")
(write (* 2 3))

Output:

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!