This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-29
Channels
- # admin-announcements (2)
- # beginners (4)
- # boot (6)
- # cider (18)
- # cljs-dev (22)
- # cljsrn (13)
- # clojure (76)
- # clojure-czech (2)
- # clojure-dusseldorf (2)
- # clojure-russia (45)
- # clojure-sg (1)
- # clojure-spec (15)
- # clojurebridge-ams (6)
- # clojurescript (58)
- # cursive (4)
- # datomic (14)
- # dirac (31)
- # emacs (6)
- # funcool (2)
- # hoplon (2)
- # lein-figwheel (1)
- # om (124)
- # planck (17)
- # re-frame (12)
- # slack-help (11)
- # specter (12)
- # tmp-json-parsing (6)
- # yada (4)
I have some code in a file that when I copy-paste into a fresh Planck, it works great. But when I run as planck script.cljs
(or prepend the file with #!/usr/bin/env planck
& chmod & run it), I get a warning, Use of undeclared Var cljs.user/slurp
, and the infamous undefined is not an object (evaluating 'cljs.user.slurp.call')
—feels like I'm doing something really stupid wrong but I can't find it
My namespace should import slurp
(and does when I paste the code into Planck):
(ns build.core
(:require [planck.core :refer [slurp spit]]
[clojure.string :as string]
[cljs.tools.reader :as reader]
[planck.core :refer [eval]]))
Hmm… does the second planck.core :refer
blow away the first? I’m actually not sure what that might do.
Now the first two lines of the script are:
#!/usr/bin/env planck
(ns build.core
(:require [planck.core :refer [slurp spit eval]]
[clojure.string :as string]
[cljs.tools.reader :as reader]))
Ok, so it's not something immediately obvious—that's what I wanted to verify, I'll continue poking it. I love planck's insta-startup (node spoiled me), so I'll make it work 🙂
I can’t reproduce what I think you are describing by putting (prn slurp)
after the stuff below.
Sorry @mfikes false alarm. The slurp error was being caused by me trying to eval (slurp …)
from a string. It was giving the error on line 1, which I thought was my ns, but no, it must be "line 1" of the eval
Ok, @mfikes, take a look at this minimum reproduction: if I paste this file exactly into planck, all is well & the println
succeeds. If I run as a planck script, it errors (latest 1.13):
This is part of a function that replaces Clojure expressions in text files with their evaluated values. So I have a plain string "(slurp file)"
which I read-string
to get as a seq
. I specify a binding vector which let
will use to ascribe a value for file
(in this example, it's script.cljs
but could be anything), so when that '(slurp file)
is eval
uated, "file" has a binding.
In the Planck REPL, I see "PRINTING" followed by the contents of script.cljs
. In the command line, I see
$ planck script.cljs
WARNING: Use of undeclared Var cljs.user/slurp
undefined is not an object (evaluating 'cljs.user.slurp.call')
I can try to verify that the code works in lein repl/JVM clojure. If it does work fine there, that may indicate something weird with planck script files?
@fasiha The problem is that Planck’s eval
should be executing in the build.core
namespace for your example, but it is evaluating in cljs.user
. It’s a bug.
@fasiha: Partial fix pushed. (Works for your example, unless you employ -K
or -k
to cache.) If you are using brew
, you can install it by following the “Install Master” section of http://planck-repl.org/setup.html The ticket is https://github.com/mfikes/planck/issues/288 Great catch! You can also work around it by qualifying as planck.core/slurp
in your eval call, or alternatively, by using planck.repl/eval
and adding a second argument specifying the symbol ’build.core
as the namespace to eval in.