Re: Strange behaviour of a callable record

2015-04-24 Thread Alex Miller
It would be great if the ticket has more of the original use case as 
motivation.

On Thursday, April 23, 2015 at 7:00:51 AM UTC-5, Nicola Mometto wrote:


 I've opened an enhancement ticket with a patch that changes this 
 behaviour btw: http://dev.clojure.org/jira/browse/CLJ-1715 
 http://www.google.com/url?q=http%3A%2F%2Fdev.clojure.org%2Fjira%2Fbrowse%2FCLJ-1715sa=Dsntz=1usg=AFQjCNF8bkUYdHtcFlrlNYUWyTHsbg5tRQ
  

 Alexey Cherkaev writes: 

  Hi, 
  
  I have encountered the problem with Clojure 1.6.0, when I create the 
 record 
  that implements IFn. 
  
  For example, 
  
  (defrecord Foo [x] 
  clojure.lang.IFn 
  (invoke [_ f] (f x))) 
  
  Than create an instance of this record: 
  
  (def f (-Foo 10)) 
  
  And we can call it without a problem: 
  
  user= (f inc) 
  11 
  
  Yet, if you try to define a value to keep the result, compiler throws an 
  error: 
  
  user= (def z (f inc)) 
  
  CompilerException java.lang.AbstractMethodError, 
  compiling:(form-init4774307052978984831.clj:1:8) 
  
  There is workaround: create local binding first and then assign the 
 value 
  to a global variable: 
  
  user= (def z (let [temp (f inc)] temp)) 
  #'user/z 
  user= z 
  11 
  
  Is this a bug or I don't fully understand why you can't do that? 
  
  Cheers, Alexey 

 -- 


-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange behaviour of a callable record

2015-04-24 Thread Alexey Cherkaev
Thanks, Nicola! It solved it. When I looked at docs, I couldn't figure out 
the role of `applyTo`. Well, now I know.

On Thursday, April 23, 2015 at 1:47:11 PM UTC+2, Nicola Mometto wrote:


 You're not implementing IFn.applyTo, you should. 

 Why applyTo is used in the second example while invoke is used in the 
 other cases has to do with implementation details of how def expressions 
 are compiled/evaluated. 

 Alexey Cherkaev writes: 

  Hi, 
  
  I have encountered the problem with Clojure 1.6.0, when I create the 
 record 
  that implements IFn. 
  
  For example, 
  
  (defrecord Foo [x] 
  clojure.lang.IFn 
  (invoke [_ f] (f x))) 
  
  Than create an instance of this record: 
  
  (def f (-Foo 10)) 
  
  And we can call it without a problem: 
  
  user= (f inc) 
  11 
  
  Yet, if you try to define a value to keep the result, compiler throws an 
  error: 
  
  user= (def z (f inc)) 
  
  CompilerException java.lang.AbstractMethodError, 
  compiling:(form-init4774307052978984831.clj:1:8) 
  
  There is workaround: create local binding first and then assign the 
 value 
  to a global variable: 
  
  user= (def z (let [temp (f inc)] temp)) 
  #'user/z 
  user= z 
  11 
  
  Is this a bug or I don't fully understand why you can't do that? 
  
  Cheers, Alexey 

 -- 


-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Strange behaviour of a callable record

2015-04-23 Thread Alexey Cherkaev
Hi,

I have encountered the problem with Clojure 1.6.0, when I create the record 
that implements IFn.

For example,

(defrecord Foo [x]
clojure.lang.IFn
(invoke [_ f] (f x)))

Than create an instance of this record:

(def f (-Foo 10))

And we can call it without a problem:

user= (f inc)
11

Yet, if you try to define a value to keep the result, compiler throws an 
error:

user= (def z (f inc))

CompilerException java.lang.AbstractMethodError, 
compiling:(form-init4774307052978984831.clj:1:8)

There is workaround: create local binding first and then assign the value 
to a global variable:

user= (def z (let [temp (f inc)] temp))
#'user/z
user= z
11

Is this a bug or I don't fully understand why you can't do that?

Cheers, Alexey

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange behaviour of a callable record

2015-04-23 Thread Nicola Mometto

I've opened an enhancement ticket with a patch that changes this
behaviour btw: http://dev.clojure.org/jira/browse/CLJ-1715

Alexey Cherkaev writes:

 Hi,

 I have encountered the problem with Clojure 1.6.0, when I create the record
 that implements IFn.

 For example,

 (defrecord Foo [x]
 clojure.lang.IFn
 (invoke [_ f] (f x)))

 Than create an instance of this record:

 (def f (-Foo 10))

 And we can call it without a problem:

 user= (f inc)
 11

 Yet, if you try to define a value to keep the result, compiler throws an
 error:

 user= (def z (f inc))

 CompilerException java.lang.AbstractMethodError,
 compiling:(form-init4774307052978984831.clj:1:8)

 There is workaround: create local binding first and then assign the value
 to a global variable:

 user= (def z (let [temp (f inc)] temp))
 #'user/z
 user= z
 11

 Is this a bug or I don't fully understand why you can't do that?

 Cheers, Alexey

--

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange behaviour of a callable record

2015-04-23 Thread Nicola Mometto

You're not implementing IFn.applyTo, you should.

Why applyTo is used in the second example while invoke is used in the
other cases has to do with implementation details of how def expressions
are compiled/evaluated.

Alexey Cherkaev writes:

 Hi,

 I have encountered the problem with Clojure 1.6.0, when I create the record
 that implements IFn.

 For example,

 (defrecord Foo [x]
 clojure.lang.IFn
 (invoke [_ f] (f x)))

 Than create an instance of this record:

 (def f (-Foo 10))

 And we can call it without a problem:

 user= (f inc)
 11

 Yet, if you try to define a value to keep the result, compiler throws an
 error:

 user= (def z (f inc))

 CompilerException java.lang.AbstractMethodError,
 compiling:(form-init4774307052978984831.clj:1:8)

 There is workaround: create local binding first and then assign the value
 to a global variable:

 user= (def z (let [temp (f inc)] temp))
 #'user/z
 user= z
 11

 Is this a bug or I don't fully understand why you can't do that?

 Cheers, Alexey

--

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.