Open In App

Structures in LISP

Last Updated : 29 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

LISP, is a list processing, is a programming language widely used in working with data manipulation. Structures are used defines data types, that have the ability to combine with another data type to complete the given task.

Attribute used:

  • The defstruct attribute is used to create an instance of a structure.
  • The setf attribute is a macro that calls the function.
  • The setq attribute store the variable.
  • The terpri attribute to produce a new line.

Example 1:

Lisp




/* LISP Creating a book.lisp file to 
/* store the information of book. 
  
(defstruct book 
   title 
   author 
   book-id 
)
  
( setq book1 (make-book :title "Geek Programming"
   :author "Ayush Agarwal" 
   :book-id "101")
)
  
( setq book2 (make-book :title "Harry Potter"
   :author "J. K.Rowling" 
   :book-id "102")
(write book1)
(terpri)
(write book2)
(setq book3( copy-book book1))
(setf (book-book-id book3) 100
(terpri)
(write book3)


Output:

 

Example 2: 

Lisp




/* Creating a Staff.lisp file to store
/* the information of Staff working in a company. 
  
(defstruct Staff
   employee
   salary
   Pin-code
)
  
( setq employee1 (make-Staff :employee "Rahul Raj"
   :salary "20 thousand" 
   :Pin-code "700055")
)
  
( setq employee2 (make-Staff :employee "Dhruv Rathee"
   :salary "10 thousand" 
   :Pin-code "400020")
(write employee1)
(terpri)
(write employee2)
(setq employee3( copy-Staff employee1))
(setf (Staff-Staff-id employee3) 100
(terpri)


Output:

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads