Arc Forumnew | comments | leaders | submitlogin
Simple genome analysis with Arc (arcfn.com)
8 points by listic 3461 days ago | 4 comments


4 points by twilightsentry 3461 days ago | link

  > I'm sure there must be a better way to initialize the
  > count in Arc, but I couldn't figure one out.
Table lookups can take a default value as a third arg, so you could do something like:

  (def hist (seq)
    (w/table h
      (each n seq
        (++ (h n 0)))
      h))

-----

3 points by palsecam 3460 days ago | link

FTR, 'hist could be just:

  (def hist (seq)
    (w/table h
      (each n seq
        (++ (h n 0)))))
I just learned about 'w/table reading your post, and I checked, and it returns the created hash. This is quite smart, I often find myself doing things like:

  (let h (table)
    ...  ; do stuff with h
    h)  ; return it
Where it's actually possible to do:

  (w/table h
    ...)  ; implicit return of "h"
But yes, here, use 'counts.

-----

4 points by aw 3461 days ago | link

Also see "counts" in arc.arc:

  arc> (counts '(a b c a a a c))
  #hash((a . 4) (c . 2) (b . 1))

-----

3 points by kens 3461 days ago | link

Oh, yeah, I forgot that Arc 3 has default values for table. Someone should write some documentation on this :-)

Thanks for the suggestions; I've updated my blog post.

-----