<div dir="ltr">The reason Swift works like this is because you can assign a function value (independently of calling it) to a variable. So there aren't two separate namespaces separating function names and variable names.<div><br></div><div>To wit:</div><div><br></div><div><div>func randomArray(withCapacity capacity: Int) -> [Int] {</div><div> // ....</div><div>}</div><div><br></div><div>// An array of Ints, the result of calling the function.</div><div>let myValue : [Int] = randomArray(withCapacity: 10)</div><div>// A function, of type Int -> Array<Int>.</div><div>let myFunc : ((Int) -> [Int]) = randomArray</div></div><div><br></div><div>Best,</div><div>Austin</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 30, 2017 at 11:37 AM, Michael Gubik via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Example that does not compile:<br>
<br>
let randomArray = randomArray(withCapacity: 4096)<br>
<br>
Compiler error: “Variable used within its own initial value”<br>
The variable name unfortunately clashes with the function name.<br>
<br>
This problem forces the developer to think about an alternative name.<br>
IMHO that’s suboptimal since many times the most canonical naming would be one where these two go by the same name.<br>
<br>
It’s not a big problem in practice but I wonder if there are plans to change this?<br>
<br>
<br>
Thanks,<br>
Michael Gubik<br>
<br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</blockquote></div><br></div>