Reflective method invocation

2013-06-11 Thread N8Dawgrr
Hi All, 

I have a question regarding ambiguity in reflective dynamic invocation.

In Clojure you can dynamically invoke a method on a Java class like so:

(. some-instance bar arg)

where bar is a method name.
If the type inferencer can't ascertain the type of some-instance a runtime 
reflective path is used to perform the method invocation.
Lets suppose some-instance is of type Foo which has two overloads of method 
bar:

bar(Apple arg) 

and 

bar(Orange arg)

Now lets suppose Apple is an interface which extends Fruit and so is Orange.

Now lastly lets suppose we have a class MutantFruit which implements BOTH 
Apple and Orange. 

My question is what method is invoked at runtime for the following code:

(. some-instance bar mutant) 

where mutant is an instance of MutantFruit

Regards,

Nathan

-- 
-- 
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/groups/opt_out.




Re: Reflective method invocation

2013-06-11 Thread N8Dawgrr
Thanks for the responses Ambrose and Gary,

I suppose the answer is its dependent on JVM implementation/version. As 
Gary pointed out his code broke on the JVM upgrade. The real question is, 
if there is ambiguity what should the behaviour be? It seems far from 
ideal atm, brodering on non-deterministic. One option would be to throw a 
RuntimeException if multiple methods match.

On Tuesday, June 11, 2013 3:14:46 PM UTC+1, Ambrose Bonnaire-Sergeant wrote:

 Hi Nathan,

 I just had a quick look at the implementation: I think Clojure picks the 
 first matching method if several are found.


 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java#L70

 It's probably worth testing this out though.

 Thanks,
 Ambrose


 On Tue, Jun 11, 2013 at 9:24 PM, N8Dawgrr nathan.r...@gmail.comjavascript:
  wrote:

 Hi All, 

 I have a question regarding ambiguity in reflective dynamic invocation.

 In Clojure you can dynamically invoke a method on a Java class like so:

 (. some-instance bar arg)

 where bar is a method name.
 If the type inferencer can't ascertain the type of some-instance a 
 runtime reflective path is used to perform the method invocation.
 Lets suppose some-instance is of type Foo which has two overloads of 
 method bar:

 bar(Apple arg) 

 and 

 bar(Orange arg)

 Now lets suppose Apple is an interface which extends Fruit and so is 
 Orange.
  
 Now lastly lets suppose we have a class MutantFruit which implements BOTH 
 Apple and Orange. 

 My question is what method is invoked at runtime for the following code:

  (. some-instance bar mutant) 

 where mutant is an instance of MutantFruit

 Regards,

 Nathan

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
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/groups/opt_out.




defrecord and map

2013-03-24 Thread N8Dawgrr
Hi,

I'm transforming a recursive form structure to an equivalent structure 
represented by Clojure records. I want polymorphic dispatch across my newly 
created structure of records. I also want to be able to apply a function to 
transform the structure of records, in much the same way as say 
clojure.walk/walk. 

The problem is this: the resulting structure loses the record type. A 
record type of Foobar just becomes a IPersistentMap and loses its 
Foobar'iness.

Is there a mechanism in Clojure to say apply f to all the values of a 
record and return me a new record of the same type? 

-- 
-- 
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/groups/opt_out.




Puzzle with lazy sequences

2013-02-05 Thread N8Dawgrr
If the head is retained on a lazy sequence we have a potential memory leak.

I set my JVM memory low, 64mb and ran the following:

user (defn test1 [coll] (reduce + coll))
#'user/test1
user (test1 (take 1000 (iterate inc 0)))
499500
user 

Now if we do:

user (defn test2 [coll] [(reduce + coll) (reduce + coll)])
#'user/test2
user (test2 (take 1000 (iterate inc 0)))
OutOfMemoryError Java heap space  [trace missing]
user 

Which OOMs as expected. The question is, why doens't the first example blow 
up? What magics happening?

I would expect coll which is a function argument to be retained by the 
garbage collector and hence blow up.

-- 
-- 
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/groups/opt_out.




Re: Puzzle with lazy sequences

2013-02-05 Thread N8Dawgrr
Hi Thanks for the super fast response, Still a little confused. If coll is 
set to nil before reduce is called, then what is reduce called with?

On Tuesday, February 5, 2013 3:21:14 PM UTC, Herwig Hochleitner wrote:

 Clojure has a feature called locals clearing, which sets 'coll to nil 
 before calling reduce in test1, because the compiler can prove it won't be 
 used afterwards.
 In test2, coll has to be retained, because reduce is called a second time 
 on it.


 2013/2/5 N8Dawgrr nathan.r...@gmail.com javascript:

 If the head is retained on a lazy sequence we have a potential memory 
 leak.

 I set my JVM memory low, 64mb and ran the following:

 user (defn test1 [coll] (reduce + coll))
 #'user/test1
 user (test1 (take 1000 (iterate inc 0)))
 499500
 user 

 Now if we do:

 user (defn test2 [coll] [(reduce + coll) (reduce + coll)])
 #'user/test2
 user (test2 (take 1000 (iterate inc 0)))
 OutOfMemoryError Java heap space  [trace missing]
 user 

 Which OOMs as expected. The question is, why doens't the first example 
 blow up? What magics happening?

 I would expect coll which is a function argument to be retained by the 
 garbage collector and hence blow up.

  -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@googlegroups.comjavascript:
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com javascript:
 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+u...@googlegroups.com javascript:.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  




-- 
-- 
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/groups/opt_out.




Object identity and with-meta

2012-11-23 Thread N8Dawgrr
I have unexplained behavior for with-meta.

As far as I understand with-meta should not alter object identity. E.g. if 
we have the (= a b) = true for some a and b then 
(= (with-meta a ma) (with-meta b mb)) = true should also hold for any ma 
and mb.

So why do I get the following behavior at the REPL?

user (def f (partial * 2))

user (= f f)
true

user (= (with-meta f {:a 1}) (with-meta f {:a 1}))
false

Any help appreciated.

-- 
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

Consuming web services in Clojure

2012-11-05 Thread N8Dawgrr
Hi All,

Does anyone know of a good simple library to call/consume web-services from 
Clojure? Note I don't want to create a web-service just call one.



-- 
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

bug in clojure.lang.ASeq

2012-10-10 Thread N8Dawgrr
Hi, stumbled on a nasty bug in Clojure. I'm transferring Clojure objects 
around using java serialization. When de-serializing a List 
(clojure.lang.ASeq) it has a hashCode of 0. This means lookups for the 
object in HashMaps PersistentHashMaps HashSets etc fail. The pre-serialized 
version of the object has a valid non-zero hashCode.

The reason for this is that the cached hashCode value is marked as 
transient and its default un-cached value is -1. E.g. if he hashCode is -1 
compute the hashCode. Of course when an Object is de-serialized any integer 
transient fields are set to 0.

This bug seems to be in all Clojure versions.

-- 
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

Re: bug in clojure.lang.ASeq

2012-10-10 Thread N8Dawgrr
I don't think that's a realistic option for me. I have java objects 
embedded in the Clojure forms, and the graph is pretty big.

On Wednesday, October 10, 2012 2:02:45 PM UTC+1, Stuart Sierra wrote:

 I would recommend serializing as strings via pr/read over Java 
 serialization, but this still sounds like a legitimate bug.
 -S

  

-- 
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

Idea around SCMs and Clojure

2012-07-17 Thread N8Dawgrr
Hi All,

One of my first posts to Clojure mailing list. I had an idea around SCMs 
and Clojure. I'd basically like to put the idea out there and get some 
feedback. I hope I'm not breaking any etiquette linking to my blog post but 
I've outlined the idea here:

http://clojurian.blogspot.co.uk/ 

In a nutshell its about why use files for source in Clojure, can we do 
better?

Regards,

Nathan

-- 
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

Re: Idea around SCMs and Clojure

2012-07-17 Thread N8Dawgrr
Hi Tassilo,

Thanks for your reply. I agree that you need a persistence layer and a VCS 
provides additional useful capabilities other than persistence. My 
suggestion isn't to dispense with a persistence or VCS layer. Its more that 
the REPL connects directly to the VCS layer (which may be remote or local) 
to retrieve its code artifacts. Persistence would of course be a 
requirement of the VCS layer. The workflow would change, instead of 
checking out a filesystem from a VCS and then starting a REPL to load the 
checked out code, you would first start the REPL and then point it to the 
VCS endpoint, bypassing the local filesystem. This enables the user to work 
directly with the VCS inside the REPL without the intermediate local 
filesystem. In this mode I ask what value would writing source files to a 
local filesystem provide?

Regards,

Nathan

On Tuesday, July 17, 2012 12:40:09 PM UTC+1, Tassilo Horn wrote:

 N8Dawgrr nathan.r.matth...@gmail.com writes: 

  http://clojurian.blogspot.co.uk/ 
  
  In a nutshell its about why use files for source in Clojure, can we do 
  better? 

 Interesting thoughts.  With a dynamic, interactive language like Clojure 
 it would certainly be possible to omit files at all and instead hack 
 everything together at the repl where all def-forms would carry all 
 previous versions in their metadata. 

 But I think that's not better than the traditional file-based approach. 
 Version control systems provide far more than just keeping previous 
 revisions.  You want do diffs, do branching, merge across different 
 branches on possibly different repositories, etc, etc. 

 That's all already provided by modern VCS in a language independent way, 
 so I hardly see a reason to reinvent the wheel here.  And in the end, 
 such an approach will also need some persistency layer, since you don't 
 want to loose your program and all its history if the JVM crashes. 

 Bye, 
 Tassilo 


On Tuesday, July 17, 2012 12:40:09 PM UTC+1, Tassilo Horn wrote:

 N8Dawgrr nathan.r.matth...@gmail.com writes: 

  http://clojurian.blogspot.co.uk/ 
  
  In a nutshell its about why use files for source in Clojure, can we do 
  better? 

 Interesting thoughts.  With a dynamic, interactive language like Clojure 
 it would certainly be possible to omit files at all and instead hack 
 everything together at the repl where all def-forms would carry all 
 previous versions in their metadata. 

 But I think that's not better than the traditional file-based approach. 
 Version control systems provide far more than just keeping previous 
 revisions.  You want do diffs, do branching, merge across different 
 branches on possibly different repositories, etc, etc. 

 That's all already provided by modern VCS in a language independent way, 
 so I hardly see a reason to reinvent the wheel here.  And in the end, 
 such an approach will also need some persistency layer, since you don't 
 want to loose your program and all its history if the JVM crashes. 

 Bye, 
 Tassilo 


On Tuesday, July 17, 2012 12:40:09 PM UTC+1, Tassilo Horn wrote:

 N8Dawgrr nathan.r.matth...@gmail.com writes: 

  http://clojurian.blogspot.co.uk/ 
  
  In a nutshell its about why use files for source in Clojure, can we do 
  better? 

 Interesting thoughts.  With a dynamic, interactive language like Clojure 
 it would certainly be possible to omit files at all and instead hack 
 everything together at the repl where all def-forms would carry all 
 previous versions in their metadata. 

 But I think that's not better than the traditional file-based approach. 
 Version control systems provide far more than just keeping previous 
 revisions.  You want do diffs, do branching, merge across different 
 branches on possibly different repositories, etc, etc. 

 That's all already provided by modern VCS in a language independent way, 
 so I hardly see a reason to reinvent the wheel here.  And in the end, 
 such an approach will also need some persistency layer, since you don't 
 want to loose your program and all its history if the JVM crashes. 

 Bye, 
 Tassilo 


-- 
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

Re: eval seq of forms in another ns

2012-03-24 Thread N8Dawgrr
If I remember rightly I solved this by binding *ns* before the eval, e.g.

(binding [*ns* some-namespace]
  (eval form))

On Saturday, March 24, 2012 5:12:29 PM UTC, Renat Yuldashev wrote:

 How to evaluate each form from the vector of forms inside of the different 
 namespace?
 I want to have a seq of the evaluation results as a result.
 Smth. like this:

 (eval-with-ns 'user ['(+ 1 2 3) '(- 5 4) '(defn f [] [])])
 = (6 3 #'user/f)

 I know about with-ns, but don't know how to use it to solve this problem.


-- 
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

How to submit clojure bug report?

2012-02-29 Thread N8Dawgrr
I found a bug in Clojure core, and know its solution, question is how
to submit a bug report?

FYI here is the bug:

= (.withMeta list {:a 1})
#CompilerException java.lang.UnsupportedOperationException
(NO_SOURCE_FILE:0)

This is reporducable in Clojure 1.2 and Clojure 1.3

This cause of this issue is in:

svn/trunk/src/jvm/clojure/lang/PersistentList.java

with the static method:

public static IFn creator = new RestFn(0){
protected Object doInvoke(Object args) throws Exception{
if(args instanceof ArraySeq)
{
Object[] argsarray = (Object[]) ((ArraySeq)
args).array;
IPersistentList ret = EMPTY;
for(int i = argsarray.length - 1; i = 0; --i)
ret = (IPersistentList)
ret.cons(argsarray[i]);
return ret;
}
LinkedList list = new LinkedList();
for(ISeq s = RT.seq(args); s != null; s = s.rest())
list.add(s.first());
return create(list);
}
};

The withMeta() method should be overriden from AFn where it is
throwing the UnsupportedOperationException. This is being done with
the EmptyList static class further down the file.



-- 
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


Re: Odd error evaling

2011-12-03 Thread N8Dawgrr
Ok not to worry, my environment was bust, a repl restart sorted the
issue.

On Dec 2, 11:27 pm, N8Dawgrr nathan.r.matth...@gmail.com wrote:
 Hi Clojurians,

 I hit the following error today. My environment is Clojure 1.3

 (eval (read-string (clojure.repl/source-fn 'keep-indexed)))

 #CompilerException java.lang.ClassCastException: clojure.lang.Compiler
 $InvokeExpr cannot be cast to clojure.lang.Compiler$ObjExpr, compiling:
 (NO_SOURCE_PATH:1)

 Do other people get the same exception? If so what am I doing wrong?

 Regards

 Nathan

-- 
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


Odd error evaling

2011-12-02 Thread N8Dawgrr
Hi Clojurians,

I hit the following error today. My environment is Clojure 1.3

(eval (read-string (clojure.repl/source-fn 'keep-indexed)))

#CompilerException java.lang.ClassCastException: clojure.lang.Compiler
$InvokeExpr cannot be cast to clojure.lang.Compiler$ObjExpr, compiling:
(NO_SOURCE_PATH:1)

Do other people get the same exception? If so what am I doing wrong?

Regards

Nathan

-- 
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


Adding forms to fn

2011-11-04 Thread N8Dawgrr
Hi Clojure Group,

I'm new to the group, apologies if this topic has been raised before.
Basically I'm wondering if there is a reason why the form used to
defined a function isn't attached as meta-data to the function.
Clojure is a isomorphic language and this capability would really help
me out with some libraries I'm building.

Clojure forms are pretty compact, much smaller than the compiled byte-
code, I can't see it having a big impact on the memory footprint.

People might argue that I could provide a local fn macro which
captures the form meta-data and calls the clojure.core/fn macro to do
the real work. The problem with this approach is that the reader macro
#(%) expands to fn*. There is no way of overriding the fn* symbol.

What are peoples thoughts?

-- 
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