Fork me on GitHub
#planck
<
2016-05-29
>
fasiha01:05:20

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

fasiha01:05:44

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]]))

mfikes01:05:56

Hmm… does the second planck.core :refer blow away the first? I’m actually not sure what that might do.

fasiha01:05:10

I just noticed that and fixed it—problem persists

fasiha01:05:26

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]))

fasiha01:05:40

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 🙂

mfikes01:05:22

I can’t reproduce what I think you are describing by putting (prn slurp) after the stuff below.

mfikes01:05:31

Perhaps a minimal repro would help

fasiha02:05:49

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

fasiha02:05:57

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):

fasiha02:05:33

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 evaluated, "file" has a binding.

fasiha02:05:08

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')

fasiha02:05:11

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?

mfikes03:05:27

@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.

mfikes03:05:22

@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.

fasiha04:05:28

@mfikes: you are too hardworking, I feel bad for asking questions like this on the weekend—thank you!!! 🙇🙏