Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion ClassCastException clojure.lang.Var$Unbound Help
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Ray  
View profile  
 More options Apr 30 2012, 9:30 pm
From: Dave Ray <dave...@gmail.com>
Date: Mon, 30 Apr 2012 21:30:47 -0400
Local: Mon, Apr 30 2012 9:30 pm
Subject: Re: ClassCastException clojure.lang.Var$Unbound Help
I think what you actually want is:

(defn get-id []
  (session/get :uid))

in your code, you're trying to call #'session/get directly and bind it
to get-id. Of course, the problem with this is that #'session/get
expects to be called in the context of a request which is where your
Unbound var exception is coming from.

Hope this helps,

Dave

On Mon, Apr 30, 2012 at 11:39 AM, Travis Smith <tra...@legomaster.net> wrote:
> What does 'java.lang.ClassCastException: clojure.lang.Var$Unbound cannot be
> cast to clojure.lang.IDeref' mean. I'm getting this a lot and I want to
> understand it better, make it easier for me to avoid this. Most of the time
> I just end up adjusting my def/defn's around until it works. This is hardly
> optimal.

> (this is all on clojure 1.3.0)

> An example...

> (ns app-admin.models.current-user
>   (:require [noir.session :as session]
>             [app-admin.models.users :as users]))

> (def get-id
>   (session/get :uid))

> (defn set-user! [user]
>   (session/put! :uid {:_id user}))

> Give me an exception for get-id

> ClassCastException clojure.lang.Var$Unbound cannot be cast to
> clojure.lang.IDeref  clojure.core/deref (core.clj:2078)

> So set-user! binds correctly, but get-id doesn't seem to...

> => (get-id)
> llegalStateException Attempting to call unbound fn:
> #'app-admin.models.current-user/get-id  clojure.lang.Var$Unbound.throwArity
> (Var.java:43)

> Then I check it...

> => (meta #'get-id)
> {:ns #<Namespace app-admin.models.current-user>, :name get-id}

> So it's there, the fn is bound; I'm not exactly sure what's going on and nor
> what I'm missing about how this works to help me avoid problems like this in
> future. Just guessing and tweaking has gotten me so far, but that's not
> sustainable.

> Thanks!

> -Travis

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.