sds's answer describes the identity function, which meets the specification that you asked for: it's pretty much just (lambda (x) x)
. However, it is worth noting that in a function like
(defun some-function (value &optional (transformation (lambda (x) x)))
(other-function (funcall transformation value))
it might be more idiomatic to describe your transformation as a key, and to let nil indicate that no key function should be applied to the value. This behavior is present in many Common Lisp functions. For instance, member takes a key argument that is applied to each element of sequence to produce a value that's compared to the item being searched for:
CL-USER> (member nil '(1 2 3 4 nil 5 6 7 8))
(NIL 5 6 7 8)
CL-USER> (member nil '(1 2 3 4 nil 5 6 7 8) :key 'oddp)
(2 3 4 NIL 5 6 7 8)
The default behavior is the same as if you pass identity as the key:
CL-USER> (member nil '(1 2 3 4 nil 5 6 7 8))
(NIL 5 6 7 8)
CL-USER> (member nil '(1 2 3 4 nil 5 6 7 8) :key 'identity)
(NIL 5 6 7 8)
However, the default value isn't identity, but nil. The HyperSpec for member says about the key:
key—a designator for a function of one argument, or nil.
This is specified in 17.2.1 Satisfying a Two-Argument Test which states that:
If a :key argument is provided, it is a designator for a function of
one argument to be called with each Ei as an argument, and yielding an
object Zi to be used for comparison. (If there is no :key argument, Zi
is Ei.)
If you want to adopt this type of convention, then your code would be something like
(defun some-function (value &optional transformation)
(other-function (if (null transformation) value (funcall transformation value))))
In your case, this might not be a big difference, but it will avoid an extra function call. In general, this can be helpful because it makes it easier to pass key arguments to library functions without having to worry about whether they're nil or not.
identity
is what you are looking for – Lorrainelorrayne