Re: How to disallow unlisted optional argument keys?

2011-02-01 Thread .Bill Smith
Yes, that's very succinct. Of course, it isn't cheap. I mean I wouldn't put it in the inner loop of Robert's image processing code. -- 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 t

Re: How to disallow unlisted optional argument keys?

2011-01-31 Thread Robert McIntyre
You win sir. That is the most beautiful way. sincerely, --Robert McIntyre On Sun, Jan 30, 2011 at 7:59 PM, Bill James wrote: > Alexander Yakushev wrote: >> Why not use a constraint? It looks much cleaner. >> >> (defn hello [& {:keys [a b] :as input}] >>          {:pre [(= (set (keys input)) #{:

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 5:08 PM, Alexander Yakushev wrote: >> Where is this documented? > > I couldn't find the documentation for it. I learned about them in Full > Disclojure screencasts by Sean Devlin. There is another, quite active thread on this topic right here, right now. It includes some m

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Bill James
Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] > {:pre [(= (set (keys input)) #{:a :b})]} > "hello") > > You can learn more about constraints here: > http://vimeo.com/channels/fulldisclojure#8399758 {:pre

How to disallow unlisted optional argument keys?

2011-01-30 Thread Alexander Yakushev
> Where is this documented? I couldn't find the documentation for it. I learned about them in Full Disclojure screencasts by Sean Devlin. -- 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

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 4:03 PM, Aaron Cohen wrote: > On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: >> On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar >> wrote: >>> On Jan 30, 2:17 pm, Alexander Yakushev >>> wrote: Why not use a constraint? It looks much cleaner. (defn hell

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Aaron Cohen
On Sun, Jan 30, 2011 at 12:12 PM, Ken Wesson wrote: > On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar > wrote: >> On Jan 30, 2:17 pm, Alexander Yakushev >> wrote: >>> Why not use a constraint? It looks much cleaner. >>> >>> (defn hello [& {:keys [a b] :as input}] >>>          {:pre [(= (set (key

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Ken Wesson
On Sun, Jan 30, 2011 at 5:36 AM, Shantanu Kumar wrote: > On Jan 30, 2:17 pm, Alexander Yakushev > wrote: >> Why not use a constraint? It looks much cleaner. >> >> (defn hello [& {:keys [a b] :as input}] >>          {:pre [(= (set (keys input)) #{:a :b})]} >>          "hello") Where is this docum

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Shantanu Kumar
On Jan 30, 2:17 pm, Alexander Yakushev wrote: > Why not use a constraint? It looks much cleaner. > > (defn hello [& {:keys [a b] :as input}] >          {:pre [(= (set (keys input)) #{:a :b})]} >          "hello") This is not the use case I was looking for (I listed it in a post above). Constrai

Re: How to disallow unlisted optional argument keys?

2011-01-30 Thread Alexander Yakushev
Why not use a constraint? It looks much cleaner. (defn hello [& {:keys [a b] :as input}] {:pre [(= (set (keys input)) #{:a :b})]} "hello") You can learn more about constraints here: http://vimeo.com/channels/fulldisclojure#8399758 -- You received this message because you are

Re: How to disallow unlisted optional argument keys?

2011-01-29 Thread Ken Wesson
On Sat, Jan 29, 2011 at 5:18 PM, Robert McIntyre wrote: > I see, so you wanted to allow some subset of the optional arguments. > > Might I recommend the following? > Sets are already functions that check for inclusion of the objects on > which you call them, so instead of (contains? some-set ele)

Re: How to disallow unlisted optional argument keys?

2011-01-29 Thread Shantanu Kumar
On Jan 30, 3:18 am, Robert McIntyre wrote: > I see, so you wanted to allow some subset of the optional arguments. > > Might I recommend the following? > Sets are already functions that check for inclusion of the objects on > which you call them, so instead of (contains? some-set ele) just > (som

Re: How to disallow unlisted optional argument keys?

2011-01-29 Thread Robert McIntyre
I see, so you wanted to allow some subset of the optional arguments. Might I recommend the following? Sets are already functions that check for inclusion of the objects on which you call them, so instead of (contains? some-set ele) just (some-set ele) will work. Also, upon actually making a typo

Re: How to disallow unlisted optional argument keys?

2011-01-29 Thread Shantanu Kumar
On Jan 30, 1:26 am, Robert McIntyre wrote: > you could do something like this, but I'm curious --- why do you want > to restrict the function's inputs in this way? As they are optional arguments, it's possible that somebody might misspell a key and spend time debugging. The intention is to avoid

Re: How to disallow unlisted optional argument keys?

2011-01-29 Thread Robert McIntyre
you could do something like this, but I'm curious --- why do you want to restrict the function's inputs in this way? (defn hello [& {:keys [a b] :as input}] (assert (= (set (keys input)) #{:a :b})) "hello") sincerely, --Robert McIntyre On Sat, Jan 29, 2011 at 1:19 PM, Shantanu Kumar wrote: >

How to disallow unlisted optional argument keys?

2011-01-29 Thread Shantanu Kumar
Hi, Given this example: (defn hello [& {:keys [a b]}] "hello") => (hello :foo "bar") ; :foo isn't listed! "hello" How can I disallow all keys except :a and :b in this example? Regards, Shantanu -- You received this message because you are subscribed to the Google Groups "Clojure" group. To