Jump to content

Talk:D (programming language)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Rich Farmbrough (talk | contribs) at 16:36, 31 August 2011 (Date maintenance tags and minorl fixes: build a606: using AWB). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconComputing Start‑class
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
WikiProject iconComputer science Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Things you can help WikiProject Computer science with:

HelloWorld

Where is HelloWorld? —Preceding unsigned comment added by 12.15.136.26 (talk) 21:03, 14 October 2010 (UTC)[reply]

D's Hello World is pretty boring. I think it'd only waste space in the article. --Vladimir (talk) 01:05, 23 October 2010 (UTC)[reply]
But all the others have HelloWorld. In VB it's just MsgBox("Hello, World!") but we still have it. --Joshua Issac (talk) 00:47, 15 November 2010 (UTC)[reply]

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:

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;
    }

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 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:

pivot = 4;
mySum(3, 5);

would yield 3, but

pivot = 5;
mySum(3, 5);

would yield 8

Unfortunately I don't have a D compiler installed on my computer, so I cannot check this myself. —Preceding unsigned comment added by 67.168.77.169 (talk) 08:16, 6 November 2010 (UTC)[reply]

The code indeed compiles. I think that the idea is that nested functions have a hidden argument - a pointer to their enclosing scope (main's local variables). However, that doesn't explain why the code continues to compile when pivot is moved outside main(), or if you add a call to a non-pure function in mySum - these sound like compiler bugs. --Vladimir (talk) 11:45, 6 November 2010 (UTC)[reply]

Pull the C# reference until examples?

Given the way it reads, I'm not sure why C# is even listed without more direct examples as to what it inherited from C# that isn't already considered from Java (a predecessor).68.163.243.231 (talk) 22:07, 12 November 2010 (UTC)[reply]