@tobin이 제안한 Common Lisp 확장을 쓰지 않는다면 선택 인자가 주어졌는지 검사해야 해요. 이 경우에는 사실 let이 필요하지 않아요. 제게는 이쪽이 더 자연스러워 보여요:
(defun perform (entry &optional extra)
(or extra (setq extra fallback))
(perform-body entry extra))
댓글에서는 or보다 unless가 나을 수 있다는 의견도 나왔어요:
(defun perform (entry &optional extra)
(unless extra (setq extra fallback))
(perform-body entry extra))
댓글에서 나온 또 다른 얘기로, 좀 더 순수 함수형인 방식은 질문처럼 let을 쓰되 이름을 두 개로 나누지 않는 거예요:
(defun my-perform (entry &optional extra)
(let ((extra (or extra fallback)))
(perform-body entry extra)))
물론 선택 인자를 한 번만 쓴다면 이렇게 쓰면 돼요:
(defun my-perform (entry &optional extra)
(perform-body entry (or extra fallback)))
영어에서 번역·원문 보기Without the Common Lisp additions @tobin suggested, you have to test whether an optional argument was provided. Note that a let isn't actually necessary in this situation. I'd find this version more idiomatic:
(defun perform (entry &optional extra)
(or extra (setq extra fallback))
(perform-body entry extra))
The comments suggest that unless could be a better choice than or:
(defun perform (entry &optional extra)
(unless extra (setq extra fallback))
(perform-body entry extra))
Another point from the comments: a more purely functional approach uses let, like the question does, without needing two different names:
(defun my-perform (entry &optional extra)
(let ((extra (or extra fallback)))
(perform-body entry extra)))
Naturally, when the optional argument occurs only once, you can simply write:
(defun my-perform (entry &optional extra)
(perform-body entry (or extra fallback)))