:arglists question

2011-12-29 Thread vitalyper
Came across the following in one of the clojure libs (congomongo to be
exact)
https://github.com/aboekhoff/congomongo/blob/master/src/somnium/congomongo.clj:464

(defn command
  Executes a database command.
  {:arglists '([cmd {:options nil :from :clojure :to :clojure}])}
  [cmd  {:keys [options from to]
  :or {options nil from :clojure to :clojure}}]
  (let [db (get-db *mongo-config*)
coerced (coerce cmd [from :mongo])]
(coerce (if options
  (.command db ^DBObject coerced (int options))
  (.command db ^DBObject coerced))
[:mongo to])))

My question is why do we have BOTH :arglists metadata and usual fn
args destructuring?
  {:arglists '([cmd {:options nil :from :clojure :to :clojure}])}
  [cmd  {:keys [options from to]
  :or {options nil from :clojure to :clojure}}]

-- 
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: :arglists question

2011-12-29 Thread Meikel Brandmeyer
Hi,

Am 29.12.2011 um 20:27 schrieb vitalyper:

 My question is why do we have BOTH :arglists metadata and usual fn
 args destructuring?

Probably to make things a bit clearer in the docstring. The usual destructuring 
is powerful but rather unreadable for a quick glance at the reference. Similar 
example from clojure.core is for example defn itself.

Sincerely
Meikel


-- 
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: :arglists question

2011-12-29 Thread Sean Corfield
On Thu, Dec 29, 2011 at 11:27 AM, vitalyper vitaly...@yahoo.com wrote:
 My question is why do we have BOTH :arglists metadata and usual fn
 args destructuring?

As Meikel surmised, it's to improve the docstring (shown by the doc
function). We (the CongoMongo team) have not been terribly consistent
about it tho' :(

In the command function you highlighted, we show defaults for keyword
arguments (and the implication is that it takes two arguments: cmd and
a map - which is not the case). In the mongo! function, we show
keyword argument defaults more in line with usage:

  {:arglists '([:db ? :host localhost :port 27017])}
  [ {:keys [db host port]
  :or {db nil host localhost port 27017}}]

In other functions, we just show the possible keyword arguments
without defaults:

;; create-collection!
  {:arglists
   '([collection :capped :size :max])}
  ([collection  {:keys [capped size max] :as options}]

;; fetch
  {:arglists
   '([collection :where :only :limit :skip :as :from :one? :count?
:sort :options])}
  [coll  {:keys [where only as from one? count? limit skip sort options]
   :or {where {} only [] as :clojure from :clojure
one? false count? false limit 0 skip 0 sort nil options []}}]

Hopefully you can see the intent...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

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