He leído un lote de cosas buenas sobre Land of Lisp, así que pensé que podría verlo para ver qué había para ver.Land of Lisp example redundency?
(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)))))))
(los comentarios son míos)
(. FYI - la firma del método es (list-of-symbols bool-whether-to-caps bool-whether-to-treat-literally)
pero el autor acortados éstos a (lst caps lit)
)
Pero de todos modos, aquí está la pregunta:
Esto tiene (cond... (lit ...) ((or caps lit) ...))
en eso. Según entiendo, esto se traduciría en if(lit){ ... } else if(caps || lit){...}
en una sintaxis de estilo C. ¿No es la declaración o redundante entonces? ¿Hay alguna vez una condición en la que se llame a la condición (or caps lit)
si caps es nil
?
Gracias. Estaba empezando a pensar que me estaba volviendo loco (recordaré revisar la errata la próxima vez) – cwallenpoole