optional (), what is done elsewhere
deadalnix
deadalnix at gmail.com
Sun Feb 3 19:34:32 PST 2013
I finally did my homework. Many languages have been presented as
example of optional parenthesis, and not posing ambiguity
problems. As I'm not a specialist of such languages, I wanted to
do some homework and check what is the reality.
See for instance
http://forum.dlang.org/thread/doeutcaammauwgaskawl@forum.dlang.org?page=2#post-ju0d0o:241bvh:241:40digitalmars.com
for example of such claim.
1/ Ruby.
In Ruby, method are called without (). This is not ambiguous as
fields are always private.
2/ Scala.
In scala, the method name is evaluated to the method itself. If
this ends up being a NOOP, then the function is evaluated. See
example below :
scala> def method1() = { println("method1") }
method1: ()Unit
scala> method1
method1
scala> method1()
method1
scala> def method2(f: () => Unit) = { f() }
method2: (f: () => Unit)Unit
scala> method2
<console>:9: error: missing arguments for method method2;
follow this method with `_' if you want to treat it as a
partially applied function
method2
^
scala> method2(method1)
method1
scala> method2(method1())
<console>:10: error: type mismatch;
found : Unit
required: () => Unit
method2(method1())
^
As we can see, mthod1 is evaluated only when simply returning the
function is a NOOP.
3/ Haskell
In haskell, all functions are pure, which make the conflation
between the function and its result possible in an unambiguous
manner.
4/ Coffescript
Example given on that page http://coffeescript.org/ tends to show
that the behavior is similar to scala's. Note function square
that is stored into a structure as a function, and not evaluated.
It seems that none does what D try to achieve.
More information about the Digitalmars-d
mailing list