Fork me on GitHub
#beginners
<
2017-06-11
>
sakalli16:06:49

hi all! so in clojure this seems to work

user> (def op "+")
#'user/op
user> ((eval (symbol op)) 1 1)
2

sakalli16:06:10

but not in cljs, why is that. can i get it to work in cljs?

sakalli16:06:07

calculator.core> (def op "+")
#'calculator.core/op
calculator.core> ((eval (symbol op)) 1 1)
WARNING: Use of undeclared Var calculator.core/eval at line 1 <cljs repl>
#object[TypeError TypeError: calculator.core.eval is undefined]

noisesmith17:06:42

clojurescript isn't self hosting - at least the normal version isn't

noisesmith17:06:29

if you use resolve, you can still look up the symbol without needing the compiler

noisesmith17:06:56

never mind, resolve doesn't exist in cljs either anyway

sakalli17:06:39

Cheers @noisesmith

joshkh21:06:39

i'd like to define a lein task that seeds my database and it would run a function in a particular namespace. is this possible? all the aliases i've seen tend to run external commands and not functions within the application.

weavejester21:06:10

@joshkh Yes, you can use the lein run -m namespace/function command.

weavejester21:06:41

:aliases {"foo" ["run" "-m" "foo.core/foo"]}

joshkh21:06:28

ah! fantastic. thanks. 🙂

noisesmith21:06:38

also if you define a -main you can run that from an uberjar without lein, with java -cp my-uber.jar clojure.main -m foo.core