Found a js library with an interesting implementation of getter/setter as one 
universal function

x = prop(5)
x() -> 5
x(6) -> 6
x() -> 6

Wondering how one would go about implementing something like this in CLJS 
(purely for learning purposes). 

Here's the equivalent js:

function prop(store) {
                var gs = function() {
                        if (arguments.length) store = arguments[0];
                        return store;
                };

                gs.toJSON = function() {
                        return store;
                };

                return gs;
        }

I couldn't figure out how to make a closure around a variable in a multi-arity 
function. (I'm trying to do this without using the arguments variable, which is 
a js-specific hack, and isn't even allowed in strict mode)

(defn prop [store]
  (fn ([] store) ([n] (set! store n) store)) ?



Vishesh

















-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to