The line below shows the first element which is not nil.

(message "%s" (cl-some  #'(lambda (x) x) '(nil nil "hello" nil)))
;; Output: hello

Is there a built-in function which is equivalent to (lambda (x) x)?


identity is a built-in function that returns its argument unchanged:

(identity ARG)
  • Thanks. What should I do to find a built-in function easily? I searched a lot but could not find it.
    – Zheng Qu
    Feb 2 '20 at 15:28
  • 1
    I don't know of any magic formula for finding such things, but in this case, it's helpful if you know other functional programming languages as well, as it's common for them to support some sort of an identity function. Feb 2 '20 at 16:20
  • 1
    To discover the existence of a function you can match either its doc or its name. Matching the doc means you can sometimes use words that might be used to describe the function. The apropos commands are your friend. See, e.g., apropos and apropos-documentation. For this function, "identity" is the typical name and describer, AFAIK.
    – Drew
    Feb 2 '20 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.