VOOZH about

URL: https://www.geeksforgeeks.org/lisp/vectors-in-lisp/

⇱ Vectors in LISP - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vectors in LISP

Last Updated : 26 Nov, 2021

In this article, we will discuss Vectors in LISP. Vectors in LISP are one-dimensional arrays which are also known as sequences. We can create a vector using vector function and # symbol

Syntax:

variable_name(vector element1 element2 ... element n)
or
variable_name #(element1 element2 ... element n)

Example: LISP Program to create integer and character vectors and display

Output:

#(12 34 56 22 34)
#(12 34 56 22 34)
#(G E E K S)
#('G 'E 'E 'K 'S)

Vector operations:

In the given vector we can perform two operations. They are:

  • push operation
  • pop operation

1. Push Operation:

This is used to insert an element into a vector

Syntax:

(vector-push element array_name)

where

  1. array_name is an input array
  2. element is an element to be pushed in an array

Example: LISP Program to create an empty array with size 10 and perform the vector push operation

Output:

#()
#(1 2 3 4)

2. Pop Operation:

This function will remove the last inserted element at a time

Syntax:

(vector-pop array_name)

where

  1. array_name is the input array

Example: POP items in an array

Output:

#()
#(1 2 3 4)
#(1 2 3)
#(1 2)
Comment