Arc Forumnew | comments | leaders | submitlogin
1 point by evanrmurphy 3401 days ago | link | parent

From a comment on Stack Overflow [1]:

> A simple way to simulate keyword args in clojure is using hash-map on rest parameters

I had never considered this before. Maybe some variation on the idea could give us keyword args in Arc. Some sketches (making use of curly braces for dictionary literals):

  (def foo (a b . {c 1 d 2})
    (list a b c d))

  (def bar {a 1 b 2}
    (list a b))

  arc> (foo 1 2)
  (1 2 1 2)
  arc> (foo 1 2 3 4)
  (1 2 3 4)
  arc> (bar)
  (1 2)
  arc> (bar 3)
  (3 2)
  arc> (bar 3 4)
  (3 4)
hasenj posted a similar idea in the original thread [2].




1 point by akkartik 3401 days ago | link

Yeah it also sounds similar to ruby's approach.


1 point by evanrmurphy 3401 days ago | link

Well what do you think of it?

I like how this approach dodges the controversy about having special characters like `o`, `?` and `&` in the arg list. The main thing that bothers me is giving dictionaries more of the spotlight. Wasn't arc supposed to be about alists, or have we cooled off on that idea?


2 points by akkartik 3401 days ago | link

The only reason lisp is about lists is that it gets us homoiconicity. I think you could include more than lists without losing homoiconicity. I've thought about that in the past.

I'm not sure the benefit of {} is lack of syntax controversy, though. You still need some syntax, whether it's {} or &, and punctuation chars will still be precious, and there'll be disputes about whether this use is worth using up this char.

Well what do you think of it?

If it existed I would totally try such an approach out to see how I liked it. In general I think I'd like more ssyntax-like infrastructure, the ability to use {} for different things to see how it fits.

The big drawback of {} vs a delimiter in this specific case is more typing (and more shift-key presses). Hmm, hey how about if we just allowed rest args to be more than a symbol, and implicitly converted to a hash table?

  (fn(a b . c 1 d 2) ..)
Implicit hash-tables like ruby would be totally awesome.