This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Clojure and the fly likes First function in tutorial fails: IllegalStateException - Attempting to call unbound function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Clojure
Bookmark "First function in tutorial fails: IllegalStateException - Attempting to call unbound function" Watch "First function in tutorial fails: IllegalStateException - Attempting to call unbound function" New topic
Author

First function in tutorial fails: IllegalStateException - Attempting to call unbound function

Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

Hi ,

I am going through the Try clojure tutorial.
It has a hello world function -

When i hit above command on the
clojure>
prompt , I get below-

#'sandbox24027/square
which looks like a success message.
But when I call it-

I get below exception -
java.lang.IllegalStateException- Attempting to call unbound function - 'sandbox24027/square

Looks like it can read the compiled function but can not call it. Any idea?

Same has happened with other functions I tried to create.


Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
Chas Emerick
author
Greenhorn

Joined: Jun 27, 2012
Posts: 27

You're calling the square function slightly wrong (you're passing a vector containing a number, and not a number; watch the brackets), but I actually get a different error than you (java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number).

It sounds like your TryClj session might be hosed, or the site was having issues at the time? Maybe try again.

FWIW, here's a session copy/pasted from TryClj:



--
(coauthor of Clojure Programming from O'Reilly; creator of Clojure Atlas)
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

I get the same error even after removing the square brackets -

Clojure> (def square (fn [x] (* x x)))
#'sandbox24027/square
Clojure> (square 45)
java.lang.IllegalStateException: Attempting to call unbound fn: #'sandbox24027/square
Clojure> (square 3)
java.lang.IllegalStateException: Attempting to call unbound fn: #'sandbox24027/square


let me try a new session.. maybe I've tried craeting the same function multiple times.
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

With a new browser session I am on the same page as you
Probably my sandbox went stale by trying multiple things on the same function.
Thanks!
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

Reproduced the problem, check below-


Clojure> (defn fuzz [x] ( * 1.23 ( / x 7 )) )
#'sandbox24027/fuzz
Clojure> fuzz 8
#<sandbox24027$fuzz sandbox24027$fuzz@3a790aaa>
Clojure> (fuzz 8)
java.lang.IllegalStateException: Attempting to call unbound fn: #'sandbox24027/fuzz


Which means if I call it incorrectly once, it goes for a toss?

What does
Clojure> fuzz 8
do ?
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 252
    
    5

Aniruddh Joshi wrote:What does
Clojure> fuzz 8
do ?

It evaluates fuzz then it evaluates 8. The former will either resolve to a symbol and it's internal name will be displayed (that sandbox...$fuzz... string you saw) or an exception if it is unknown. The latter will resolve to the value 8 which will be displayed.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Aniruddh Joshi wrote:Reproduced the problem, check below-


Clojure> (defn fuzz [x] ( * 1.23 ( / x 7 )) )
#'sandbox24027/fuzz
Clojure> fuzz 8
#<sandbox24027$fuzz sandbox24027$fuzz@3a790aaa>
Clojure> (fuzz 8)
java.lang.IllegalStateException: Attempting to call unbound fn: #'sandbox24027/fuzz


Which means if I call it incorrectly once, it goes for a toss?

What does
Clojure> fuzz 8
do ?


I didnt get any exceptions. See below:-



Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

@Palak- try reversing the order of your last 2 commands.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Aniruddh Joshi wrote:@Palak- try reversing the order of your last 2 commands.


It worked:-

Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

What exactly do you think the issue might be? I didn't receive any error.
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

Maybe like Chas said, something wrong with tryclj.
Will try it again when I get some time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: First function in tutorial fails: IllegalStateException - Attempting to call unbound function
 
Similar Threads
Clojure Programming - Few Questions
Clojure for teams
Questions on Clojure
Will Clojure be popular among Java programmers?