Re: object identity

2014-02-27 Thread Andy Fingerhut
I will mention a case that I wasn't thinking about when I wrote my previous message in this thread. If one is commonly dealing with tree-like data structures, e.g. maps that contains maps as keys or values, which in turn contain other maps, or vectors, or sets, etc., it is relatively trivial in

Re: object identity

2014-02-26 Thread Brian Craft
Ok, trying a different way of asking this: Is it common practice in clojure to write data transforms in a way that will return the same object when possible (when the transform would be a noop), such as the mapv vs. reduce/assoc in my example? Would you do this to speed up equality checks, or

Re: object identity

2014-02-26 Thread Andy Fingerhut
There are likely to be common ways of writing data transforms that happen to return the same identical object as they were given, because 'primitives' like assoc often do. I don't know of anyone who intentionally relies upon this behavior for correctness of their code, and would strongly advise

Re: object identity

2014-02-26 Thread Mikera
I would try to write code that behaves like this where possible, because it certainly improves performance (because of faster identity checks + less GC pressure as you suggest). I think it is good practice in general when implementing immutable data structures. However I would generally not

Re: object identity

2014-02-26 Thread Bobby Eickhoff
This seems like a reasonable optimization. I read something similar a few years ago (http://lorgonblog.wordpress.com/2008/05/24/catamorphisms-part-four/): What we want is a function which will be smart, and only allocate new data structures when necessary. Indeed, one of the main advantages

Re: object identity

2014-02-26 Thread t x
[start slightly insane idea] Perhaps we need the following: * a way to tag a function as _pure_ * a map with uber_weak keys + values by uber_weak, I mean the k/v pair vanishes when either the key _or_ the value is gc-ed Then, what we do here, is that every function auto-memoizes: (func

Re: object identity

2014-02-25 Thread Brian Craft
No, my question isn't is there a way to do this. I'm sure there are a dozen ways to do it. My question is about a specific way of doing it. In particular, if your solution does not involve calling (identical? ..), then it's not what I'm asking about. In om core there's a call to identical?

Re: object identity

2014-02-25 Thread David Nolen
I don't really have anything to add to this thread but I will say that Om's use of identical? is an implementation detail that's likely to change. = already does an identical? check, ideally Om could use not= in the future instead of (not (identical? ...)). David On Tue, Feb 25, 2014 at 12:54

Re: object identity

2014-02-24 Thread t x
I finally have a chance to give back. :-) I hacked up a newb's half-React. It does tree diffing + dom updating, but not the virtual event handling system. I ran into this exact problem, and solved it as follows: ## problem definition: render: data - dom tree-diff: dom * dom - list of

Re: object identity

2014-02-24 Thread Brian Craft
You're solving a similar problem, but I'm asking specifically about using object identity, not equality, for tracking changes in a nested structure. On Monday, February 24, 2014 1:42:03 PM UTC-8, t x wrote: I finally have a chance to give back. :-) I hacked up a newb's half-React. It does

Re: object identity

2014-02-24 Thread t x
Perhaps I mis-interpreted your question. I thought the question asked was: GIven: * pure function func * some object obj * (def a (func obj)) * (def b (func obj)) Example: * obj = [1 2 3] * (defn func [lst] (map #(* 2 %) lst)) Then: * is there a O(1) way to check if (= a b) ?

Re: Object identity and with-meta

2012-11-23 Thread László Török
Hi, only for persistent data structures (with a few caveats) [1]. For other objects, such as function objects, equality check falls back to .equals(). Since with-meta returns a new object instance of an anonymous class, .equals will always be false. [1]

Re: Object identity and with-meta

2012-11-23 Thread Jonathan Fischer Friberg
When you compare functions, it only checks if it is the same function object (not if the function behaves the same way). For example: (= (fn []) (fn [])) ;= false The reason you get false in your case is because with-meta returns a new object every time you call it. We need a new object to keep