On Aug 16, 2009, at 11:56 PM, tsuraan wrote:
(defh a[b:String [c:Double :as list:java.util.List] {d:java.util.Random :d}](.toCharArray b) (.size list) (.floatValue c) (.nextInt d))What's that :as in the [ c:Double :as list:java.util.List ] vector?
The entire expression you quoted requests destructuring of a sequential thing (such as a vector, seq, list, or something seq-able) as the second argument to a. The :as clause allows you to give a name to the entire sequential thing.
This desctruturing can be read as: bind c to the first item in the sequential thing bind list to the entire sequential thing Here are a few examples: user=> (let [[c :as b] [5 4 3 2 1]] (prn c b)) 5 [5 4 3 2 1] nil user=> (let [[c m :as b] [5 4 3 2 1]] (prn c m b)) 5 4 [5 4 3 2 1] niluser=> (let [[c m :as b] (java.util.ArrayList. [:a :b :c])] (prn c m b))
:a :b #<ArrayList [:a, :b, :c]> nilThe official docs for this are at: http://clojure.org/ special_forms#let .
(and (doc let) contains a pointer there) --Steve
smime.p7s
Description: S/MIME cryptographic signature