digitalmars.D.bugs - [Issue 3572] New: declaring pure function with void return type should be compile time error
- d-bugmail puremagic.com Dec 04 2009
- d-bugmail puremagic.com Dec 04 2009
- d-bugmail puremagic.com Dec 04 2009
- d-bugmail puremagic.com Dec 04 2009
- d-bugmail puremagic.com Feb 17 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3572 Summary: declaring pure function with void return type should be compile time error Product: D Version: 2.036 Platform: x86 OS/Version: Windows Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: michal.minich gmail.com --- Comment #0 from Michal Minich <michal.minich gmail.com> 2009-12-04 02:37:33 PST --- In D specification is written: "Pure functions are functions that produce the same result for the same arguments. To that end, a pure function has parameters that are all immutable or are implicitly convertible to immutable void function cannot produce any result, thus they are meaningless as pure functions. Also when all parameters are implicitly immutable, there is no possibility to modify "out" parameters. So the only way for function to produce result, is by returning it (and void has no value). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 04 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3572 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug yahoo.com.au --- Comment #1 from Don <clugdbug yahoo.com.au> 2009-12-04 12:01:56 PST --- (In reply to comment #0)In D specification is written: "Pure functions are functions that produce the same result for the same arguments. To that end, a pure function has parameters that are all immutable or are implicitly convertible to immutable void function cannot produce any result, thus they are meaningless as pure functions. Also when all parameters are implicitly immutable, there is no possibility to modify "out" parameters. So the only way for function to produce result, is by returning it (and void has no value).
I think the restriction on 'out' parameters will be removed. I don't think there's any reason for it. A void pure function that doesn't have any 'out' parameters does seem to be pretty useless (you can use it as a metaprogramming test that anything inside it is pure, but that's about all I can think of). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 04 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3572 David Simcha <dsimcha yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dsimcha yahoo.com --- Comment #2 from David Simcha <dsimcha yahoo.com> 2009-12-04 15:52:01 PST --- ????? Why would you allow out parameters in a pure function? This seems reasonable for simple value types (ints, floats, etc.), but when you start passing objects in, you start allowing the modification of whole object subgraphs from pure functions. This makes no sense. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 04 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3572 --- Comment #3 from Don <clugdbug yahoo.com.au> 2009-12-04 18:28:11 PST --- (In reply to comment #2)????? Why would you allow out parameters in a pure function? This seems reasonable for simple value types (ints, floats, etc.), but when you start passing objects in, you start allowing the modification of whole object subgraphs from pure functions. This makes no sense.
Why doesn't it make sense? Aren't you thinking of inout parameters? A pure function void foo(out A a); ought to be exactly the same as A foo(); together with an assignment. I'm not seeing anything impure in that. BTW, it works fine in CTFE. (CTFE isn't quite the same concept as pure, but it's close). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 04 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3572 --- Comment #4 from David Simcha <dsimcha yahoo.com> 2010-02-17 18:38:36 PST --- (In reply to comment #3)Why doesn't it make sense? Aren't you thinking of inout parameters? A pure function void foo(out A a); ought to be exactly the same as A foo(); together with an assignment. I'm not seeing anything impure in that. BTW, it works fine in CTFE. (CTFE isn't quite the same concept as pure, but it's close).
You're right, I did get confused between out and ref. Allowing out parameters in pure functions makes sense. I tend to forget how out parameters work because I almost never use them. I almost always just return a tuple or a struct. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 17 2010









d-bugmail puremagic.com 