Skip to content

Instantly share code, notes, and snippets.

@laurentpetit
Created July 26, 2012 08:53
Show Gist options
  • Save laurentpetit/3181088 to your computer and use it in GitHub Desktop.
Save laurentpetit/3181088 to your computer and use it in GitHub Desktop.
complete-record? avant/apres
; Avant
(defn complete-record?
"Returns if a line is a complete record or finalizes a complete record."
([line] (let [c (seq line) initial-status (if (= (first c) \") false true) ]
(complete-record? initial-status line))
)
([initial-status line] (let [c (seq line) ]
(if (reduce new-open-status initial-status (partition 2 1 c)) (= (last c) \") true))
)
)
; Après : plus d'espace pour le code, moins pour les parenthèses fermantes isolées, indentation correcte
(defn complete-record?
"Returns if a line is a complete record or finalizes a complete record."
([line]
(let [c (seq line) initial-status (if (= (first c) \") false true)]
(complete-record? initial-status line)))
([initial-status line]
(let [c (seq line)]
(if (reduce new-open-status initial-status (partition 2 1 c))
(= (last c) \")
true))))
; Après simplifications pour rendre plus idiomatique :
; la fonction first appelle seq implicitement
; utiliser not= permet d'eviter d'ecrire un if qui renvoie juste les litteraux false/true
(defn complete-record?
"Returns if a line is a complete record or finalizes a complete record."
([line]
(let [initial-status (not= (first line) \")]
(complete-record? initial-status line)))
([initial-status line]
(if (reduce new-open-status initial-status (partition 2 1 line))
(= (last line) \")
true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment