The Wayback Machine - https://web.archive.org/web/20240123093813/https://www.geeksforgeeks.org/lambda-functions-in-lisp/
Open In App
Related Articles

Lambda Functions in LISP

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

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

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 09 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials