Re: Simple data structure access macro

2009-07-21 Thread James Sofra
You can also use destructuring for this: (def nested-ds ["foo", {:hi "there" :hello ["buddy"]}, "hi"]) (let [[foo {there :hi [buddy] :hello} hi] nested-ds] (print foo there buddy hi)) James On Jul 21, 6:31 am, Moses wrote: >   I come primarily from a perl programming background, but am tryi

Re: Simple data structure access macro

2009-07-21 Thread James Sofra
The get-in that ataggart suggested is probably what you want but destructuring can also be used here. (def nested-ds ["foo", {:hi "there" :hello ["buddy"]}, "hi"]) (let [[foo {there :hi [buddy] :hello} hi] nested-ds] (print foo there buddy hi)) On Jul 21, 6:31 am, Moses wrote: >   I come pri

Re: Simple data structure access macro

2009-07-21 Thread John Harrop
On Mon, Jul 20, 2009 at 4:31 PM, Moses wrote: > > I come primarily from a perl programming background, but am trying > to learn Clojure. > > I'm looking for a clojure equivalent to the following. > > Perl: > > my $nestedDS = [ "foo", { hi => there, hello => ["buddy"] }, "hi"] > > my $foo =

Re: Simple data structure access macro

2009-07-20 Thread ataggart
How about: (get-in nestedDS [1 "hello" 0]) http://clojure.org/api#toc279 On Jul 20, 1:31 pm, Moses wrote: >   I come primarily from a perl programming background, but am trying > to learn Clojure. > >   I'm looking for a clojure equivalent to the following. > >   Perl: > >    my $nestedDS = [

Re: Simple data structure access macro

2009-07-20 Thread kyle smith
You'll want to look at the -> macro. Read http://clojure.org/data_structures. You can also omit nth in two cases.   (let [nestedDS ["foo", {"hi" "there", "hello", ["buddy"]}, "hi"]        foo (nestedDS 0)        there (-> nestedDS (nth 1) (get "hi"))        buddy (-> nestedDS (nth 1) (get "h