2

I just started trying out clojure. I am doing my best to start vibing with the lisp syntax style. I am using vs-code on a mac, project is created with leiningen, calva is working (jack-in). Every time I try to import a library, for example

(ns asdf.core
  (:gen-class) 
  (:require [clojure.string :refer [index-of]]))

and then adding

(index-of "ab" "ab")

somewhere under my main and press opt + enter I get a syntax error with the message

; Syntax error compiling at (src/asdf/core.clj:40:1).
; Unable to resolve symbol: index-of in this context

I already tried googling but only found that my name space might have to be changed to (ns asdf.core) again, but adding that in front of the index-of call doesn't help. Functions that I don't need to import/require like (+ 1 1) just work fine with the repl.(obviously the whole file should be in asdf.core ns, or am I wrong?)

Carlos
  • 43
  • 7
  • Did you actually evaluate the rest of the namespace? If you just eval a single form in a namespace, then of course its `ns` clause won't have been evaluated. – amalloy Jun 17 '22 at 21:41
  • @amalloy no, I clicked behind the (index-of "ab" "ab") call and pressed opt + enter. This works with other function calls that don't need to be required too. If I compile the whole file it works, but I really like to evaluate single lines for testing and understanding. Is that not possible? Edit: by compile I mean "lein run" in terminal – Carlos Jun 17 '22 at 21:44
  • 3
    You must compile the file if you want the definitions/references in it to apply. Once you have compiled it, it will be in your REPL's state, and you can evaluate individual forms as much as you like. If you later make a change to the rest of the file, you'll have to evaluate the file again for them to take effect. – amalloy Jun 17 '22 at 21:50
  • 1
    Ahhhh, ok. Thank you really much, now I feel kind of dumb lol... But that makes sense, thanks a lot mate! – Carlos Jun 17 '22 at 21:51

0 Answers0