Arc Forumnew | comments | leaders | submitlogin
2 points by akkartik 5126 days ago | link | parent

Yeah, the & is just a superficial point. But I've been thinking more about &key in common lisp. I thought it was pretty redundant if you get pervasive keyword args, but there's one case it doesn't cover: if you want your rest args to take priority over the optionals.

Consider the final versioning of updating that I came up with at http://arclanguage.org/item?id=12974:

  (mac updating(place ? expr t iff 'is . body)
    (w/uniq rhs
      `(let ,rhs ,expr
         (unless (,iff ,place ,rhs)
           (= ,place ,rhs)
           ,@body))))
It's nice to have the optional args when I need them, but I need to either specify both or say :body to begin the rest args:

  (mac firsttime(place . body)
    `(updating ,place
        :body
          ,@body))
If I had 'greedy rest args' or 'lazy optionals' I could make the rest args take precedence instead. Hmm.

Update: But it looks like I can't allow both these formulations at once:

  ; A
  (updating (uvar u last-login) (date)
    (++ karma.u))

  ; B
  (ret max 0
    (each elem '(1 3 2 6 5)
      (updating max :iff > elem
        (prn "max now: " max))))
Perhaps I can use ?? for lazy optionals:

  (mac updating(place ? expr t ?? iff 'is . body)
    (w/uniq rhs
      `(let ,rhs ,expr
         (unless (,iff ,place ,rhs)
           (= ,place ,rhs)
           ,@body))))
Now I can say both A and B above, but must have :body in:

  ; C
  (mac firsttime(place . body)
    `(updating ,place
        :body
          ,@body))
What do you think? Am I over-optimizing? :)

Update 2: Hmm, perhaps I should get rid of required args (your suggestion) and have eager optionals (default), lazy optionals after '?', and rest.