Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function that just returns its argument?

Tags:

common-lisp

In Common Lisp, is there a function in the standard library that simply returns the parameter given (i.e. doesn't manipulate the data)? This function would be equivalent to (lambda (x) x). I'm looking to use it as the default for an optional parameter. For example, such a function would replace (lambda (x) x) in:

(defun some-function (value &optional (transformation (lambda (x) x)))
  (other-function (funcall transformation value))
like image 623
ElliotPenson Avatar asked Jul 08 '14 21:07

ElliotPenson


People also ask

What is a function that takes an argument?

A function that takes a single argument as input, such as. , is called a unary function. A function of two or more variables is considered to have a domain consisting of ordered pairs or tuples of argument values. The argument of a circular function is an angle.

What is a function that returns a function called?

In general a function that returns a function is the same as a function with an extra argument (possibly with lazier evaluation) so often there will not be a special name for this.

Which function returns the same value which was used as its argument?

The identity function is a function which returns the same value, which was used as its argument. It is also called an identity relation or identity map or identity transformation.


1 Answers

Take a look at identity:

Function IDENTITY

Syntax:

identity object ⇒ object

Arguments and Values:

object—an object.

Description:

Returns its argument object.

BTW, the ANSI CL standard specifies almost a thousand symbols. You cannot learn them all overnight. Also, Lisp is a language with a rich history, so if you want something "general purpose", chances are that either the language provides that, or some (semi-)standard library does.

Ask away! Do not reinvent the bike.

like image 198
sds Avatar answered Sep 18 '22 07:09

sds