Content deleted Content added
Cybercobra (talk | contribs) section |
|||
Line 9:
Where is HelloWorld? <span style="font-size: smaller;" class="autosigned">—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/12.15.136.26|12.15.136.26]] ([[User talk:12.15.136.26|talk]]) 21:03, 14 October 2010 (UTC)</span><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
:[http://rosettacode.org/wiki/Hello_world/Text#D D's Hello World] is pretty boring. I think it'd only waste space in the article. --[[User:CyberShadow|Vladimir]] ([[User talk:CyberShadow|talk]]) 01:05, 23 October 2010 (UTC)
== Purity of mySum function in the "Functional" section (1.1.4) ==
I am not a D programmer, so I may misunderstand the language's semantics, but I am confused about how the mySum function could be considered pure:
<source lang="D">
int main()
{
int[] a1 = [0,1,2,3,4,5,6,7,8,9];
int[] a2 = [6,7,8,9];
int pivot = 5;
pure int mysum(int a, int b) // pure function
{
if (b <= pivot) // ref to enclosing-scope
return a + b;
else
return a;
}
</source>
The value mySum produces depends on the value of pivot from the enclosing scope. If the numerical value of pivot in mySum was fixed at the time mySum is defined, then mySum would be only depend on its arguments, and could arguably be called a pure function, but from what I infer from the section on nested functions on [http://www.digitalmars.com/d/2.0/function.htm the function page] of D's reference manual, the value of pivot in mySum is the value of pivot in the enclosing scope at the time mySum is called.
So I would expect that:
<source lang="D">
pivot = 4;
mySum(3, 5);
</source>
would yield 3, but
<source lang="D">
pivot = 5;
mySum(3, 5);
</source>
would yield 8
Unfortunately I don't have a D compiler installed on my computer, so I cannot check this myself.
|