Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure REPL Unable to resolve symbol

When executing this function from lein run, the program executes as expected. But I am trying out atom.io's proto-repl package and when I call the function using the proto-repl, it gives a "CompilerException java.lang.RuntimeException: Unable to resolve symbol: can-vote in this context." Here is my function:

(defn can-vote
  []
   (println "Enter age: ")
   (let [age (read-line)]
    (let [new-age (read-string age)]
     (if (< new-age 18) (println "Not old enough")))
      (println "Yay! You can vote")))
like image 399
Mahmud Adam Avatar asked Feb 01 '16 20:02

Mahmud Adam


1 Answers

When your repl starts, it likely puts you in the user namespace. You either need to move to your clojure-noob.core namespace or call it with the fully qualified symbol.

If you want to switch namespaces

(ns clojure-noob.core) ;; switch to the correct namespace
(can-vote) ;; call the function

If you want to call it with the fully qualified symbol from the user namespace

(require 'clojure-noob.core) ;; first require the namespace
(clojure-noob.core/can-vote) ;; call the fully qualified function

You can read much more about namespaces and calling functions from other namespaces and libraries here.

like image 128
Josh Avatar answered Sep 30 '22 12:09

Josh