Arc Forumnew | comments | leaders | submitlogin
2 points by fallintothis 5134 days ago | link | parent

Ah, that's a fun one. Could use counts to get a table in vanilla Arc, except that it hard-codes recursion on cdrs, so it won't work for strings. From arc.arc:

  (def counts (seq (o c (table)))
    (if (no seq)
        c
        (do (++ (c (car seq) 0))
            (counts (cdr seq) c))))
It's also easy to not notice the built-in sortable from srv.arc:

  (def sortable (ht (o f >))
    (let res nil
      (maptable (fn kv
                  (insort (compare f cadr) kv res))
                ht)
      res))
So,

  (= count-up (compose sortable counts [coerce _ 'cons]))
until counts gets fixed to use each, at which point it's just

  (= count-up sortable:counts)


1 point by akkartik 5134 days ago | link

Ah, getting rid of the optional arg lets me define counts using defgeneric!

I've updated my repo with your suggestions: https://github.com/akkartik/arc/commit/a5b3c6d6bf616f51bc4ab...

-----