Я читал много хороших отзывов о Land of Lisp Вот я и подумал, что мог бы пройтись по нему, чтобы посмотреть, что там можно было увидеть.
(defun tweak-text (lst caps lit)
(when lst
(let ((item (car lst))
(rest (cdr lst)))
(cond
; If item = space, then call recursively starting with ret
; Then, prepend the space on to the result.
((eq item #\space) (cons item (tweak-text rest caps lit)))
; if the item is an exclamation point. Make sure that the
; next non-space is capitalized.
((member item '(#\! #\? #\.)) (cons item (tweak-text rest t lit)))
; if item = " then toggle whether we are in literal mode
((eq item #\") (tweak-text rest caps (not lit)))
; if literal mode, just add the item as is and continue
(lit (cons item (tweak-text rest nil lit)))
; if either caps or literal mode = true capitalize it?
((or caps lit) (cons (char-upcase item) (tweak-text rest nil lit)))
; otherwise lower-case it.
(t (cons (char-downcase item) (tweak-text rest nil nil)))))))
(комментарии мои)
(К сведению, сигнатура метода (list-of-symbols bool-whether-to-caps bool-whether-to-treat-literally)
, но автор сократил ее до (lst caps lit)
.)
Но в любом случае, вот вопрос:
Здесь есть (cond... (lit ...) ((or caps lit) ...))
. Насколько я понимаю, это будет означать if(lit){ ... } else if(caps || lit){...}
в синтаксисе стиля C. Тогда разве оператор or не является излишним? Есть ли когда-нибудь условие, при котором будет вызываться условие (or caps lit)
, если заглавные буквы равны nil
?