Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lambda Functions in LISP

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will discuss lambda functions in LISP. The Lambda function is used to evaluate a mathematical expression in our program. They are also known as anonymous functions.

We can create these functions using lambda expression.

Syntax:

(lambda (parameters) expression_code)

where,

  1. The parameters are the numbers of operands in the expression
  2. The expression_code is the mathematical logic expression

Example 1: LISP program to evaluate the mathematical expression through a lambda expression

Lisp




;lambda expression to get sum of product of four numbers
;mathematical expression is (val1*val2) + (val3*val4)
  
(write ((lambda (val1 val2 val3 val4)
   (+  (* val1 val2) (+ (* val3 val4))))
   ;pass the values
   2 4 6 8)
)
(terpri)
(write ((lambda (val1 val2 val3 val4)
   (+  (* val1 val2) (+ (* val3 val4))))
   ;pass the values
   10 20 30 40)
)

Output:

56
1400

Example 2: LISP Program to evaluate an expression

Lisp




;lambda expression to get product of two numbers
;mathematical expression is (val1*val2) 
  
(write ((lambda (val1 val2 )
   (* val1 val2))
   ;pass the values
   60 4 )
)
(terpri)
(write ((lambda (val1 val2 )
   (* val1 val2))
   ;pass the values
   10 20 )
)

Output:

240
200

My Personal Notes arrow_drop_up
Last Updated : 09 Nov, 2021
Like Article
Save Article
Similar Reads