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
How to avoid "Attempting to call unbound fn:..."
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
Armando Blancas  
View profile  
 More options Aug 28 2012, 2:08 pm
From: Armando Blancas <abm221...@gmail.com>
Date: Tue, 28 Aug 2012 11:08:12 -0700 (PDT)
Local: Tues, Aug 28 2012 2:08 pm
Subject: How to avoid "Attempting to call unbound fn:..."

I'm playing around with a parser combinator library from the paper Monadic
Parser Combinators by Hutton and Meijer [1] and came up with this:

https://gist.github.com/3501273

That's just enough to show the error I'm getting when (expr) calls (factor):

Clojure 1.4.0
user=> (load-file "expr.clj")
#'user/expr
user=> (run expr "(5)")
IllegalStateException Attempting to call unbound fn: #'user/expr
 clojure.lang.Var$Unbound.throwArity (Var.java:43)

To avoid this error, I coded a new version of the parser (factor) but in
this case I use inline calls to (bind) instead of using parser (between),
which makes it work:

Now using (parser*) inside the definition of (expr): (def expr (bind
facfor* ...)

Clojure 1.4.0
user=> (load-file "expr.clj")
#'user/expr
user=> (run expr "(5)")      
5

I thought it was a bug but this may have to do with the forward declaration
of "expr" and when is deref'ed. After much trying I can't see why this
won't work:

(def factor
  (choice (between (match \() (match \)) expr)
  integer))

But this will:

(def factor*
  (choice (bind (match \() (fn [_]
          (bind expr       (fn [e]
  (bind (match \)) (fn [_] (result e)))))))
  integer))

When called from (expr), since the second case just expands the first.

[1] http://eprints.nottingham.ac.uk/237/1/monparsing.pdf


 
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.
Nelson Morris  
View profile  
 More options Aug 28 2012, 4:01 pm
From: Nelson Morris <nmor...@nelsonmorris.net>
Date: Tue, 28 Aug 2012 15:01:22 -0500
Local: Tues, Aug 28 2012 4:01 pm
Subject: Re: How to avoid "Attempting to call unbound fn:..."

(def factor ...) immediately gets the value of the body to assign to
the var #'factor.  (choice ...) is a function, so has to get the
values of it's arguments before invoking.  This means it gets the
value of expr, which unbound and uses that.

> But this will:

> (def factor*
>   (choice (bind (match \() (fn [_]
>           (bind expr       (fn [e]
>  (bind (match \)) (fn [_] (result e)))))))
>  integer))

This occurs similar to the above, except it hits a fn.  fn is a
"special form" defined to wait to get the value of its body until it
is executed.  By that time the (def expr ...) has occurred and #'expr
has a bound value.  A similar effect can be achieved with

(def factor
  (choice (between (match \() (match \)) (fn [x] (expr x)))
              integer))

I ran into the same thing re-exploring that paper in clojure.


 
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.
Armando Blancas  
View profile  
 More options Aug 28 2012, 5:25 pm
From: Armando Blancas <abm221...@gmail.com>
Date: Tue, 28 Aug 2012 14:25:30 -0700 (PDT)
Local: Tues, Aug 28 2012 5:25 pm
Subject: Re: How to avoid "Attempting to call unbound fn:..."

Nelson, that explained the case quite nicely. I appreciate it.


 
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.
End of messages
« Back to Discussions « Newer topic     Older topic »