Arc Forumnew | comments | leaders | submitlogin
2 points by Pauan 4764 days ago | link | parent

Time to implement this in my Arc interpreter written in Python. I should be able to get (. (a b)) to work too.

Also, if (. (a b)) is equivalent to ((o a) (o b)), then how would you specify the value, like with ((o a 'x) (o b 'y))?



2 points by Pauan 4763 days ago | link

It only took about 30-60 minutes to implement it. My Arc interpreter now supports both forms of optional parameters:

  (def foo (a b (o c) (o d) . e))  ; works
  (def foo (a b . (c d . e)))      ; works
  
I plan to support this style of optionals too:

  (def foo (a b ? o d . e))
  
  
This could all change, though. I haven't yet seen the Perfect Holy Grail for optional arguments. I kinda like Python's take on it, though:

  def foo(a, b, c=None, d=None, *e):
      pass
      
Which would be this, in Arc:

  (def foo (a b c=nil d=nil . e))
  
Which would expand to:

  (def foo (a b (= c nil) (= d nil) . e))

-----

1 point by Pauan 4760 days ago | link

Okay, scrap that. Here's my new plan:

Make all arguments optional, as per evanrmurphy's suggestion. I'll still support the (o foo) form for backwards compatibility, but I think it has so many problems that it really should be avoided.

This isn't final, but I figure the simplicity of not supporting required parameters will be a net gain most of the time. If you really need required parameters, it's possible to write macros that do the checks at run-time. I might even provide such a macro in arc.arc so you don't have to write it yourself.

Also, for telling Arc what the default is (it's normally nil), you use the (= foo 'bar) form, like so:

  (def foo ((o a 1) (o b 2))) ; pgArc
  (def foo ((= a 1) (= b 2))) ; PyArc
I also plan to support argument-ssyntax, which is basically ssyntax that is only expanded in the argument list. Then you can do this:

  (def foo (a=1 b=2))
This should, of course, be customizable within Arc.

-----