Arc Forumnew | comments | leaders | submitlogin
Another small idea for parameters...
5 points by drcode 6117 days ago | 5 comments
I think, in hindsight, my idea of allowing "optional parameters" in destructurings was too byzantine to work... http://arclanguage.org/item?id=2540

...but here's another idea to resolve this issue that I think is better.

You be the judge!

Remember, this very succinct function (which removes identical pairs) has a rare bug when there is an item in the list that is nil.

  (def rem-pairs ((a . (b . c)))
       (when a
             (if (is a b) (rem-pairs c)
                 (cons a (rem-pairs:cons b c)))))
What, however, if we could do THIS:

  (def rem-pairs ((a . (b . c)))
       (when _
             (if (is a b) (rem-pairs c)
                 (cons a (rem-pairs:cdr _)))))
Is there any reason we couldn't just bind the _ to the first parameter of the current function across the board? (This would also synergize nicely if we had _2, _3, etc. which I support, as well)

This would mean that [...] no longer means "a function that has a single parameter bound to _" Instead, it would just mean "a function" and would have all optional parameters. The user would have the ability to refer the first parameter with _, but that would be a feature independent of the bracket syntax.



1 point by greatness 6117 days ago | link

So, in this case would _ bind to the same thing as a, or do you mean it would bind to the entire construct before it was destructured?

  _ = a
or

  _ = (a . ( b . c))
I don't know if I like the idea of using [] to accept an indeterminate amount of parenthesis, it seems like it would make the functions created inside of them more complicated. On the other hand, I think this might be one of those cases where it SEEMS like a bad idea, but is actually better than it appears, so you can't really judge it until you've tried it out.

-----

1 point by drcode 6117 days ago | link

_ = (a . ( b . c))

What I'm arguing is that the _ would let you grab the original parameter without destructuring. Sometimes (like in my example) it's useful to have access to the original parameter. This is especially since, unlike CL, arc destructuring is lossy, since it allows (car nil) -> nil.

-----

1 point by almkglor 6117 days ago | link

nitpick: I think you meant rem-pairs:cdr not rem-pairs:car

An interesting idea. Although you could just use my p-m: macro^^.

-----

1 point by drcode 6117 days ago | link

Thanks for the bug report- now fixed.

:) I agree your pm macro solves this almkglor.

-----

3 points by almkglor 6117 days ago | link

What I really wanted to see was some method by which to determine if the caller specified an optional param, or didn't. I didn't want to depend on (o param 'some-random-value), because the user might actually want that value, and wrapping functions in w/uniq isn't exactly terse.

-----