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

At a loss for something useful to contribute (sorry), I thought it might help discussion to rewrite the code to be simpler -- people won't need to wrestle as much with the auxiliary definitions that way.

I know you probably meant to use things like merge-tables in the large, but in the example you only use it for a degenerate case that happens to be fill-table. I also assume all the unbound things in the macro are defined elsewhere (i.e., you define nav somewhere, param is bound (is it supposed to be arg?), req is gotten from macro-expansion context, etc.). So, I'm left with

  (mac paginate(url numitems . block)
    (let (params body) (kwargs block 'nextcopy "next" 'prevcopy "prev")
       `(withs (start-index (param req "from")
                end-index   (+ start-index ,numitems))
          (nav ,url start-index end-index ',params))))

  (def kwargs (args-and-body . defaults)
    (let (kws body) (regroup args-and-body)
      (list (fill-table (listtab:pair defaults) kws)

  (def regroup (seq)
    (let (kws body) (split seq (or (pos ':do seq) (len seq)))
      (list kws (cdr body))))
On a side note, you might consider changing alist? so that it doesn't cons/compute every length needlessly:

  (def an-alist (l)
    (and (acons l)
         (all (andf acons [is (len _) 2]) l)))

  arc> (do1 nil (= xs (coerce (rand-string 10000) 'cons)))
  arc> (time (repeat 1000 (alist? xs)))
  time: 11948 msec.
  arc> (time (repeat 1000 (an-alist xs)))
  time: 8 msec.

2 points by akkartik 3887 days ago | link

Awesome comments, thanks! I'm new to lisp. Not reading about lisp, but actually hacking on it :)

Yes I was aware I was leaving nav, etc. unspecified, I was trying to evoke say the 'Goooogle' nav line in searches. I've been using 'req' purely as the arg to defops, which wasn't clear at all, sorry.

Thanks for the pointers to fill-table and arg. I just wasn't aware of them.


2 points by akkartik 3887 days ago | link

Speeding up alist? along a different dimension - on really long lists:

  (def pair? (l)
    (and (acons l)
         (acons:cdr l)
         (no:acons:cddr l)))

  (def alist? (l)
    (and (acons l)
         (all pair? l)))
Thanks for the inspiration!