2

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)?

Drew
  • 77,472
  • 10
  • 114
  • 243
Zheng Qu
  • 123
  • 5

1 Answers1

4

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

(identity ARG)
Steve Vinoski
  • 251
  • 1
  • 4
  • Thanks. What should I do to find a built-in function easily? I searched a lot but could not find it. – Zheng Qu Feb 02 '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. – Steve Vinoski Feb 02 '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 02 '20 at 16:31