Ho letto un lotto di cose buone su Land of Lisp così ho pensato che potevo passare attraverso di esso per vedere cosa c'era da vedere.Land of Lisp esempio di ridondanza?
(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)))))))
(i commenti sono miei)
(. A proposito - la firma del metodo è (list-of-symbols bool-whether-to-caps bool-whether-to-treat-literally)
ma l'autore accorciato questi per (lst caps lit)
)
Ma in ogni caso, ecco la domanda:
Questo ha (cond... (lit ...) ((or caps lit) ...))
in esso. La mia comprensione è che ciò si tradurrebbe in if(lit){ ... } else if(caps || lit){...}
in una sintassi in stile C. Allora non è la dichiarazione o ridondante? C'è mai una condizione in cui verrà chiamata la condizione (or caps lit)
se le maiuscole sono nil
?
Grazie. Stavo cominciando a pensare che stavo impazzendo (ricorderò di controllare l'errata la prossima volta) – cwallenpoole