Arc Forumnew | comments | leaders | submitlogin
2 points by evanrmurphy 4852 days ago | link | parent

I'm borrowing rocketnia's thread resurrection technique [1] since I was late to this party. ^_^

I don't think the following suggestion appeared anywhere in that thread: make all function arguments optional by default (as they are in JavaScript). This way you don't have to worry about a designating a special character like `o` or `?` to mark off optional args.

I think the main disadvantage of making all arguments optional is that it's another way programmers can shoot themselves in the foot. But that shouldn't be a problem for Arc, which in general tries not to protect programmers from themselves.

---

[1] http://arclanguage.org/item?id=12999



2 points by evanrmurphy 4852 days ago | link

Let's build on this with one of akkartik's earlier proposals [1] to allow for specifying default values:

> b) Quote destructured args to distinguish them from optional args.

  (a b '(c d)) ; destructured
  (a b (c 3) (d)) ; optional args
By making all arguments optional, we no longer need parentheses around the final argument in that list. This plus dot ssyntax allows us to rewrite the example as follows:

  (a b c.3 d)
For another example, take waterhouse's accumulate [2], which can now be rewritten:

  (def accumulate (over starting.nil taking.car 
                   folding-with.cons next.cdr until.no)
      ... )
Update: To be honest, however much I liked this idea in theory, I'm not sure I like how it turned out in these examples. :-/

Another Update: I think it's because I like implicit pairs so much [3] that I actually prefer akkartik's incumbent syntax for optional args:

  (def accumulate (over ? starting nil  taking car  
                          folding-with cons 
                          next cdr  until no)
    ... )
---

[1] http://arclanguage.org/item?id=12575

[2] http://arclanguage.org/item?id=12946

[3] http://arclanguage.org/item?id=13032

-----

2 points by akkartik 4852 days ago | link

Interesting train of thought.

Another idea is perhaps to use '=' as ssyntax for optional args.

  (def accumulate(over starting=nil taking=car folding-with=cons next=cdr until=no)
    ..)

-----