Fork me on GitHub
#clojure
<
2015-12-27
>
curtosis01:12:22

hmm. any suggestions where to troubleshoot an IllegalStateException Attempting to call unbound fn that shows up halfway through my functions? (as in, the first half of the file get properly defn'd; the second half are all unbound)

curtosis01:12:43

if I copy the defn into the repl, it works fine.

curtosis01:12:58

completely mystifying

val_waeselynck01:12:48

@curtosis: hard to tell without seing code examples... does it trigger when loading the function definitions or when calling the functions ?

curtosis01:12:41

aaaand I tracked it down.

curtosis01:12:35

stray close-paren at the end of the file was masking a missing close-paren earlier. operator error. sigh.

curtosis01:12:32

such a weird error, though.... it was different than "unable to resolve symbol", which is what I would have expected.

jimmy03:12:00

hi guys, is there anyway that we can add deps exclusion automatically when we have :pedantic? :abort on in project.clj

jimmy04:12:29

I got this error java.lang.IncompatibleClassChangeError, I wonder what is the possible causes of this error ?

cjmurphy04:12:18

If you compile with one version of Java and run with another, and they are incompatible. You won't get this error if you compile and run on the same version of Java.

jimmy04:12:51

hmm, in my case it's not. Since the whole thing is compiled and run on the same version of java

cjmurphy05:12:22

i.e. a jar file you are using may have been compiled on a older version of Java.

cjmurphy05:12:45

The java people have always allowed themselves to have binary incompatibility between major version changes. I've never used 1.8, but I presume there will be problems using 1.7 compiled jars when your main source code that calls it has been compiled with 1.8.

jimmy05:12:21

yeah it comes from the run-jetty from ring. But the lib itself doesn't have any problem with other people ( not the same project as mine ). But btw, I will ignore it for now since I use aleph server anyway

cjmurphy05:12:03

It is a runtime error so things could work fine for everyone else as they are not making the particular call you are making. The 'other people' are asking for trouble perhaps...

cjmurphy05:12:21

Hmm - taking a look at that SO answer shows that it can get more involved than any of my glib reasoning might suggest.

jimmy05:12:24

@cjmurphy: the problem occur when I just eval the deps and its function, I haven't made any function call yet.

jh39808:12:08

just started learning clojure, is this the right place to ask beginner questions?

rm08:12:21

jh398: yes, ask

jaen08:12:11

@curtosis: hah, for me errors like these happen relatively often (for some reason I tend to quite often get weird errors most Clojure people don't encounter), I guess that's the downside of having regular syntax. I'm trying to make myself use paredit, hopefully this will mitigate that.

jh39808:12:28

i couldnt get read-line to work inside nrepl with Cursive

jh39808:12:41

i have a very simple function

jh39808:12:42

(defn say-hello [] (do (print "please type your name") (flush) (let [name (read-line)] (println "Hi " name))))

jh39808:12:04

when i run this with nrepl, it just seem to hang

jh39808:12:20

i can still type stuff

jh39808:12:37

but the repl doesnt seem to be evaluting

jh39808:12:40

i am running with lein btw

johannjohann08:12:04

so you started your repl with lein repl in the terminal?

jh39808:12:03

i am starting in Cursive

johannjohann08:12:46

are you not seeing any dialogue or popup somewhere?

johannjohann08:12:02

heres what happens when you do read-line in a different repl

johannjohann08:12:33

notice the prompt for stdin on the bottom

jh39808:12:47

i tried lein repl on command line just now

jh39808:12:51

it works fine

johannjohann08:12:14

yeah its a cursive thing

jh39808:12:25

I saw that tweet too, but with Cursive 1.0 being released, i was hoping it might work now

johannjohann08:12:49

sorry about the painpoint, friend 😞

jh39808:12:05

@johannjohann: thanks for your help!

jh39808:12:50

am reading through land of lisp and trying out with all the coding exercise, i guess will just skip a chapter then

johannjohann08:12:00

thats a fun book!

jh39808:12:12

yeah! really enjoying it

cfleming08:12:35

@johannjohann: @jh398: Yeah, this is still a limitation in Cursive, sorry. I’ll try to fix it soon.

cfleming08:12:17

@johannjohann: When it prompts in the minibuffer in Cider, does it only allow a single line to be entered?

jh39808:12:25

@cfleming: no problem at all. Cursive is great! will get the license soon simple_smile

cfleming08:12:08

I’m glad it’s working well for you.

jh39809:12:22

so the only way is to use the command line for now?

cjmurphy10:12:32

@jaen "make myself use paredit" Is that something you can use with Cursive or has to be separately?

jaen10:12:01

Cursive has structural editing, yes.

Leonid10:12:44

Hi All! I have a question about core.async/timeout channels: can I actually treat them as values and declare a timeout channel once and reuse it, e.g. in alt! calls, or I do need a new instance of such channel when I want to do a select using it?

jaen10:12:31

IIRC you have to call timeout each time you want to use it, since the channel is closed when the timeout elapses (that's how it works - you block until it is closed)

jaen10:12:54

But if the timeout end times are close enough to each other it will reuse the channel

jaen10:12:24

So if you do (timeout 100) and (timeout 120) they will probably timeout at the same time, not with 20ms separation.

jaen10:12:27

Scratch that, 100 and 110, just checked the actual value

Leonid10:12:41

Thanks for the clarification, jaen! I was confused a bit, 'cause somewhere I heard / saw a statement that timeouts are like values

jaen10:12:09

Well, they are values in so far as a channel is a value.

jaen10:12:30

You basically get a channel that will close in n miliseconds, so you can block on it to sleep for that time.

jaen10:12:46

You can pass that channel around as you wish, as with a normal channel

jaen10:12:35

Just keep in mind the timeout is counted from the creation time - if you call (timeout 1000) keep the timeout channel around for 500msecs and only then take from it

jaen10:12:41

You'll block for only 500msecs.

Leonid10:12:57

OK, now it's clear

jaen10:12:22

So it's better to just straight up take from them at creation and if anything, pass around timeout duration as integer, or something like this.

Leonid10:12:46

Yep, thanks!

jaen10:12:08

No problem.

jaen10:12:21

Of course I can see some use cases for keeping a timeout channel around - for example you might want to delay the first time something happens by 2000msecs, but have it be instantaneous next time, so you can call timeout once, keep it around and alt on it.

jaen10:12:31

But that's a pretty specific use case.

ebaxt10:12:34

Hi all. I’m trying out stuartsierra/component. It’s working fine, but I’m trying to understand the repl workflow. Before when using the repl-reloaded “pattern” without component, I was able to access the running system map and play around with it in the repl. But since .start and .stop are the only methods on SystemMap I’m not able to access components directly in the repl. Am I missing something obvious here, and if not, how do I access components in the system that I would like to invoke directly from the repl?

jaen10:12:42

You're using just the component or also some helper like reloaded.repl or system?

jaen10:12:55

If only the component it's on you to store the system map somewhere

jaen10:12:02

And you can just use it like a map

jaen10:12:08

(:component your-system-map)

jaen10:12:14

Will net you that component.

jaen10:12:17

But I think you should try https://github.com/danielsz/system#boot-system (if you're using boot) or https://github.com/weavejester/reloaded.repl (if you're using lein)

jaen10:12:50

They handle the basic scaffolding to store/start/restart system automatically on code changes.

jaen10:12:14

(at least the boot task does, but I think lein has something similar)

ebaxt10:12:18

@jaen: Thanks… I was sure I had tried that facepalm

jaen10:12:37

Hah, that can happen ; d

mike_ananev16:12:56

hello all! i'm trying use refs in my code. i'm a bit confused when to use @ (deref) with refs? next code snippet works well without @ (deref)

mike_ananev16:12:57

(def vendor (ref {:id 102 :name "Alex" :money 150 :stones 5})) (def customer (ref {:id 102 :name "Mike" :money 50 :stones 20})) (defn stones-deal [customer vendor amount] (dosync (when (and (customer-has-stones? customer amount) (vendor-has-money? vendor amount)) (alter vendor assoc :stones (+ (vendor :stones) amount)) (alter vendor assoc :money (- (vendor :money) amount)) (alter customer assoc :money (+ (customer :money) amount)) (alter customer assoc :stones (- (customer :stones) amount)))))

mike_ananev16:12:12

is it correct to use (vendor :stones) in alter instead of (@vendor :stones)?

markf17:12:08

@mike1452: i'd use (:stones @vendor) as you're using a keyword as a function to access the value of the ref (a map)

markf17:12:40

the difference between using the deref and not using it is when you are updating it with alter you just name the ref, when you want to read anything out of it deref it. it's more normal to also use the (:keyword map) to access a value in a map, unless it's deeply nested, then use (get-in [:k1 :k2 ...] map).

srdjan17:12:05

Can anyone help with Pedestal SSE stuff?

srdjan17:12:27

I think I’m doing things correctly but the errors thrown aren’t helpful

mike_ananev18:12:43

@makrf: thanks!

mudphone22:12:09

Wondering if there’s a quick way to change a string into a function name, so I can call it at runtime?

mudphone22:12:27

Like, if I have two functions: fn1 and fn2

mudphone22:12:43

and I want to run one or the other depending on an argument supplied by the user

mudphone22:12:11

(let [x 1] 
  ((create-fn-name (str “fn” x)) args))

mudphone22:12:41

looks like I need resolve or ns-resolve

roberto22:12:37

hmmm, y not use multimethods ?

mudphone22:12:55

I’m not sure how multimethods would help. Assume I don’t know what the name of fn before it is called.

mudphone22:12:39

i need to take some arguments and turn it into an ns and fn name… and call the fn

christopherbui22:12:59

@mudphone: What are you trying to achieve?

mudphone22:12:16

just want to have a set of functions that I can call, like colors, one each

mudphone22:12:50

then depending on a color input by a user, call that function, or a default, if that function doesn’t exist

mudphone22:12:19

I don’t want to have to have a big cond with input to fn… just want to call the fn if it is in the ns

christopherbui22:12:17

So you know have the fns you want to call conditionally defined alredy?

mudphone22:12:03

yeah, just want to avoid the cond

mudphone22:12:24

i just want to be able to create the fns and not have to wire them up elsewhere

mudphone22:12:49

essentially, I want to use resolve to create my fn from a string

mudphone22:12:02

unless there’s another way, I think resolve will do it for me

christopherbui22:12:17

There are lots of ways to do this

christopherbui22:12:23

You could just use a map

christopherbui22:12:31

Or multimethods like roberto suggested

christopherbui22:12:36

I don’t think using resolve is idiomatic

christopherbui22:12:58

(def color-fns
  {"blue" (fn [color]
            :blue)
   "green" (fn [color]
             :green)})

((get color-fns "blue") "some-arg”)  ;=> :blue

christopherbui23:12:24

With multimethods:

(defmulti color :name)

(defmethod color "blue"
  [_]
  ;; Do some processing
  :blue)

(defmethod color "green"
  [_]
  ;; Do some processing
  :green)

(color {:name "blue"}) ;=> :blue

mudphone23:12:13

i understand that resovle isn’t idiomatic, but I don’t want to wire up the function (via cond or multimethod, etc.)

mudphone23:12:09

I will already be creating the function, and having other parts of the application be aware of it’s name (as a keyword)

mudphone23:12:12

It wouldn’t be too bad to use a multimethod or cond, but just thought I’d try out the resolve style first to see how much “convention” I could get away with