Arc Forumnew | comments | leaders | submitlogin
1 point by almkglor 6107 days ago | link | parent

NON-recursive modification of your solution ^^.

Turns out that 'withs is recursive enough for this ^^.

  (mac dsb (params data . body)
    (let (reqs keys opts) (dsb-params-parse params)
      (w/uniq (tree kvs)
        (withs (optfn
                (afn (l)
                  `()))
          ; turn reqs into the argument list, adding
          ; the ,tree as a rest argument
          (if (no reqs)
              (= reqs tree)
              ((afn (l)
                 (aif (cdr l)
                      (self it)
                      (= (cdr l) tree)))
               reqs))
          `(withs (,reqs ,data
                   ,@(mappend [list (carif _)
                                    `(do1 (if ,tree
                                              (car ,tree)
                                              ,(cadrif _))
                                          (= ,tree (cdr ,tree)))]
                              opts)
                   ,kvs (pair ,tree)
                   ,@(mappend [list (carif _)
                                    ; don't use aif - dsb might be
                                    ; used itself in an aif context
                                    (w/uniq it
                                      `(let ,it (assoc ',(carif _) ,kvs)
                                            (if ,it
                                                (cadr ,it)
                                                ,(cadrif _))))]
                              keys))
            ,@body)))))
Yep, I concede. The recursive solution won't easily handle the cases in http://arclanguage.org/item?id=4423 . So this is really the best way to do it ^^.