Probably would have been more clear if I showed an example in a function
argument vector also:
(defn foo {:count 2 :name "billy"})
(defn print-foo [{c :count n :name}]
(println "count:" c "name:" n))
(print-foo foo)
On Mon, Nov 22, 2010 at 9:30 AM, Mark Rathwell <[email protected]>wrote:
>
> as for replacing accessor methods:
>
> java:
>
> class Foo {
> private int count;
> private String name;
>
> public Foo(String name) {
> this.name = name;
> }
>
> public String getName() {
> return this.name;
> }
>
> public String getCount() {
> return this.count;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public void setCount(int count) {
> this.count = count;
> }
> }
>
> clojure equivalent using destructuring:
>
> (def foo {:count 2 :name "billy"})
>
> (let [{:keys [count name]} foo]
> (println "count:" count "name:" name))
>
> >> count: 2 name: billy
>
>
> On Mon, Nov 22, 2010 at 9:07 AM, nickik <[email protected]> wrote:
>
>> as for first and next:
>>
>> You can do this
>>
>> (let [fst (first [1 2 3 4 5 6])
>> rst (rest [1 2 3 4 5 6])]
>> (println "first: " fst)
>> (println "rest: "rst))
>>
>> or
>>
>> (let [[fst & rst] [1 2 3 4 5 6]]
>> (println "first: " fst)
>> (println "rest: "rst))
>>
>> both print this:
>> first: 1
>> rest: (2 3 4 5 6)
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]<clojure%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>>
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en