Created
July 26, 2012 08:53
-
-
Save laurentpetit/3181088 to your computer and use it in GitHub Desktop.
complete-record? avant/apres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; 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