load-file fails to work in REPL

1 minute read

I had a strange problem with load-file yesterday, for some reason it did not work in REPL. This was the code I had:

;; lcm.clj

(load-file "gcd_function.clj")

(defn lcm [first-number second-number]
  (/ (* first-number second-number)
     (gcd first-number second-number)))

(println (lcm 12 14))

This worked when I did this:

$ clj lcm.clj

A function to calculate LCM of two numbers, this file needs to load a file named gcd_function.clj and it failed. gcd_function.clj is listed below:

 ;; gcd-function.clj

(defn gcd [first-number second-number]
  (let [bigger-number (max first-number second-number)
        smaller-number (min first-number second-number)
        remainder (rem bigger-number smaller-number)]
    (if (= remainder 0)
      (recur smaller-number remainder))))

I had no clue, but there I started to look where is lein, it turns out asdf had messed up with it, I tried to uninstall it, it did not. asdf is still in beta I think, I removed the lein shim using rm -rf and and checked. Looked like lein was in /usr/local/bin/lein, I did a cat and it looked like it was installed using brew. I uninstalled it using brew uninstall leiningen, and went to https://leiningen.org/, followed the installation instructions, and load-file in REPL worked like charm.

Then after this all the peasant’s in village celebrated with joy and lived happily ever after.