planck

Planck ClojureScript REPL
fasiha 2016-05-29T01:47:20.000160Z

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

fasiha 2016-05-29T01:47:44.000161Z

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

mfikes 2016-05-29T01:48:56.000162Z

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

fasiha 2016-05-29T01:49:10.000163Z

I just noticed that and fixed it—problem persists

fasiha 2016-05-29T01:49:26.000164Z

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

fasiha 2016-05-29T01:50:40.000165Z

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 🙂

mfikes 2016-05-29T01:51:22.000166Z

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

mfikes 2016-05-29T01:51:31.000167Z

Perhaps a minimal repro would help

fasiha 2016-05-29T02:03:49.000168Z

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

👍 1
fasiha 2016-05-29T02:40:57.000169Z

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

fasiha 2016-05-29T02:45:33.000173Z

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.

fasiha 2016-05-29T02:47:08.000175Z

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

fasiha 2016-05-29T02:49:11.000176Z

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?

mfikes 2016-05-29T03:03:27.000177Z

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

mfikes 2016-05-29T03:46:22.000179Z

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

fasiha 2016-05-29T04:56:28.000181Z

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