Arc Forumnew | comments | leaders | submitlogin
2 points by hasenj 2610 days ago | link | parent

optional args don't map nicely to a list, they map more naturally to a dictionary (hash table).

Perhaps, the `o` is not needed?

  (fn (a b c (d 1) (e) (f)) ....)
d is optional, but defaults to 1 e and f are optional with not default.

perhaps the builtin special function operator shouldn't take any named argument at all: just a list and a hash table, sort of like a generic python function:

  def barebones(*args, **kwargs):
      pass

  (bare-function args kwargs (body))
and, fn would be implemented as a macro on top of that.


2 points by akkartik 2610 days ago | link

Yeah perhaps we should just add dictionary literals to arc: http://news.ycombinator.com/item?id=1804558

My problem right now: fn((a b)) could define a function that takes a list of two args, or an optional arg a with a default value of b bound in the enclosing scope. This seems like a more serious problem than when I posted this thread.

Update: prior implementation of dictionary literals in arc: http://hacks.catdancer.ws/table-reader-writer.html. Discussion: http://arclanguage.org/item?id=10678

-----

2 points by aw 2610 days ago | link

Most recent implementation: http://awwx.ws/table-rw3

Though (for what it's worth) I've since realized that I don't like the {a 1 b 2} syntax; I find the key value pairs aren't grouped together well enough visually for me, and the curly brackets don't stand out enough themselves.

-----

1 point by zck 2610 days ago | link

Some optional arguments are better done as a list. The greater the number of optional arguments, though, the better off you are using keyword arguments.

-----