This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chas Emerick
author
Greenhorn
Posts: 27
Clojure
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 302
10
Clojure Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 328
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:-

 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Palak- try reversing the order of your last 2 commands.
 
Palak Mathur
Ranch Hand
Posts: 328
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aniruddh Joshi wrote:@Palak- try reversing the order of your last 2 commands.


It worked:-

 
Palak Mathur
Ranch Hand
Posts: 328
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you think the issue might be? I didn't receive any error.
 
Aniruddh Joshi
Ranch Hand
Posts: 275
Eclipse IDE jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe like Chas said, something wrong with tryclj.
Will try it again when I get some time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic