0

Hi I am starting to write clojure code and practicing Hackerrank questions.

The problem requires me to take input as

2
RGRG
BGYG

where 2 is number of test cases followed by 2 strings.

I have written following code to take input and print the output of it where fullballs? is my function :

(defn Start [FuncToCall inputParse outputParse]
  (let [lines (line-seq (java.io.BufferedReader. *in*))
        input (rest lines)
        times (first lines)]
    (for [i (range (Integer. times))]
      (outputParse (FuncToCall (inputParse (nth input i)))))
    ))

(Start fullballs? 
       (fn [x] x)
       (fn [x]
         (if x
           (println "True")
           (println "False"))
         x))

However, Hackerrank says that nothing gets printed on the stdout.

Also when i am trying it int cider repl it is not something like usual

(False

False

false false)

for my two test cases..

Is this problem with for or where is my code wrong ?

Ashish Negi
  • 5,193
  • 8
  • 51
  • 95

1 Answers1

1

for is lazy. This means that unless and until you force evaluation of the result, side effects will not be executed.

The reason this works in your REPL is that it tries to print out the result of your function. This forces evaluation of the lazy sequence produced by for.

Use doseq instead.

For further reading.

I don't understand the second half of your question: "It is not something like usual for my two test cases."

Community
  • 1
  • 1
galdre
  • 2,319
  • 17
  • 31