user interface - Different results when a function is evaluated in the REPL than in a program -


i have feeling answer question clojure's lazy evaluation (which still fuzzy on...)

so have function:

(defn fix-str-old [string]   (let [words (->> string                    (clojure.string/split-lines)                     (map #(clojure.string/replace % #"\w" "")))]     (apply str (interleave words (repeat " "))))) 

basically takes wacky sentence non-alphanumeric chars, chars, return characters, line feeds etc in place of space , turns regular sentence. reason if you're curious whenever try copy out of pdfs, puts line feeds , other mysterious characters in between words.

here example:

(fix-str "a    block    of       sql      statements       that     must     all      complete         before       returning    or       changing     anything  ")  ==> "a block of sql statements must complete  before returning or changing anything" 

it works fine in repl when evaluated inside of little swing gui this:

"ablockofsqlstatementsthatmustallcompletesuccessfullybeforereturningorchanginganything " 

(note space @ end of string)

i pretty sure because of gap in understanding of how clojure handles lazy seqs whipped function regex operations.

(defn fix-str [string]   (-> string       (clojure.string/replace #"[ \t\n\r]+" " ")       (clojure.string/replace #"[^a-za-z0-9 ]" "")       (clojure.string/trimr))) 

which isn't lazy , works fine in both repl , in gui.

note: tried putting doall statements in various places in original function though might make sense make sure forced evaluation of lazy seqs couldn't work either.

so question isn't if first way way fix strings, rather why getting different result in repl , in gui.

laziness should not problem here, because (apply str ...) forces output map realized (and because there's no bindings here, first clue laziness culprit).

looks me there's funky going on line-endings coming gui, , split-lines not splitting anything. function splits on \n or \r\n - maybe somehow you're getting \r line-endings gui? can verify adding beginning of fix-str function:

(doseq [c string] (println (int c))) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -