Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Colin Yates
One answer to my question would be to force Clojure to throw an exception if querying a non-existant property on the data-structure...is that possible? For example, in the following snippet, (t {:c 10}) would fail. I assume a macro-or-something? Clojure (defn t [a] (print (str (:b a

Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Baishampayan Ghose
One answer to my question would be to force Clojure to throw an exception if querying a non-existant property on the data-structure...is that possible?  For example, in the following snippet, (t {:c 10}) would fail.  I assume a macro-or-something? Clojure (defn t [a] (print (str (:b a

Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Meikel Brandmeyer (kotarak)
Hi, Baishampayan beat me to it. But to elaborate more: You have to expose each contract up the function chain. Say it looks like this: (defn calculate-insurance [ items] {:pre [(every? #(contains? % :cost-replace-with-new) items)]} ...) Then funcE and funcD have to check

Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Colin Yates
Thanks both - DBC is one answer - yes. Very nice - I hadn't realised this was there. So this is the issue - funcD and funcE shouldn't know about the contract because they have no requirement for :cost-replace-with-new - they are simply wrappers for logging and performance monitoring for

Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Timo Mihaljov
As I understand the problem in your example, you do have a definition for what an Insurable is, but it's implicit: there's no way to check whether an object is insurable and thus no way to check which parts of the code break when the notion of being Insurable changes. Luckily Clojure provides us

Re: (OTP slightly) - ensuring assumptions about structure of function arguments in dynamic languages

2012-01-30 Thread Colin Yates
This is very helpful. I think my false assumption was that structural contracts weren't enforced, even with protocols. Your example is very helpful. On 30 January 2012 11:43, Timo Mihaljov t...@mihaljov.info wrote: As I understand the problem in your example, you do have a definition for

Exchange value between refs

2012-01-30 Thread Jonathan Cardoso
Hi, I want to change state of two refs, exchanging between them. Currently this is what I do: (dosync (let [a (first @v) b (second @v)] (alter a assoc :color (:color @b)) (alter b assoc :color (:color @a I wonder if there's a better approach,

Re: Exchange value between refs

2012-01-30 Thread Jonathan Cardoso
Actually this is wrong, I bind the value of the :color of a first, before I alter b -- 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

Re: Exchange value between refs

2012-01-30 Thread Meikel Brandmeyer (kotarak)
Hi, a simple let does the trick, no? (dosync (let [av @a bv @b] (alter a assoc :color (:color bv)) (alter b assoc :color (:color av Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: Exchange value between refs

2012-01-30 Thread Jonathan Cardoso
Yes, that's what I've been doing What I want to know is if there's a single function that does this exchange between refs. -- 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

Re: Exchange value between refs

2012-01-30 Thread Meikel Brandmeyer (kotarak)
Hi, (defn exchange! [a b {:keys [getter setter] {getter identity setter (fn [_ v] v)}}] (let [av @a bv @b] (alter a setter (getter bv)) (alter b setter (getter av (defn exchange-color! [a b] (exchange! a b :getter :color :setter #(assoc %1 :color %2))) (exchange-color! a b)

Re: Exchange value between refs

2012-01-30 Thread Jonathan Cardoso
yes, that works! thanks -- 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

Re: Exchange value between refs

2012-01-30 Thread Meikel Brandmeyer (kotarak)
Hi again, or more like this: (defn exchange! [a b {:keys [f] {f (fn [_ v] v)}}] (let [av @a bv @b] (alter a f bv) (alter b f av))) (defn exchange-color! [a b] (exchange! a b :f #(assoc %1 :color (:color %2 (exchange-color! a b) Sincerely Meikel -- You received this

Re: Exchange value between refs

2012-01-30 Thread Jay Fields
Here's a bit more of playing around at the repl. clojure.core= a b #Atom@7b603522: {:color :blu} #Atom@69408a75: {:color :red} clojure.core= (for [[x y] [[a @b] [b @a]]] (swap! x assoc :color (:color y))) ({:color :red} {:color :blu}) clojure.core= a b #Atom@7b603522: {:color :red}

Re: Literate programming in emacs - any experience?

2012-01-30 Thread daly
On Sat, 2012-01-28 at 10:04 -0500, daly wrote: On Sat, 2012-01-28 at 06:51 -0800, Folcon wrote: Hi Tim, Personally if you have done or would be interested in doing a quick vid cast of how you progress through your workflow, I think that would be very interesting. Sort of extreme

Re: Exchange value between refs

2012-01-30 Thread Jonathan Cardoso
Nice! I liked the use of *merge* , it seems even more semantic! -- 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

Re: got trouble when combine use condition-map and doc-string

2012-01-30 Thread z huang
It works now, thank you, Jonas. -- 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

optimizations for serving binary with ring

2012-01-30 Thread Brent Millare
I'm dynamically generating images for a website and I'm hosting the content using ring. Currently I use moustache for routing, where I have a handler that returns a response map and the response map contains a bytearrayinputstream. Currently I wrap the handler that makes the image file with

Re: optimizations for serving binary with ring

2012-01-30 Thread Brent Millare
Hmm I seemed to have figured it out. Calling memo-lru on the handler was not a good idea since there are elements that change with each request, therefore all calls were a cache miss. Also I, I can't wrap memo-lru on a function that outputs a bytearrayinputstream since that object has state. I