www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3572] New: declaring pure function with void return type should be compile time error

reply d-bugmail puremagic.com writes:
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



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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au




 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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com



?????  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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572





 ?????  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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572





 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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, diagnostic
                 CC|                            |mrmocool gmx.de
           Platform|x86                         |All
         OS/Version|Windows                     |All
           Severity|enhancement                 |normal



Also you shouldn't be able to throw away the result of a pure function.
http://d.puremagic.com/issues/show_bug.cgi?id=7235

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



15:53:14 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.
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).
Should we close this report then? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



In current, we can declare a pure function which has "weak" purity.

pure void foo(int* p, out string s, ref int[] arr);

All results are returned through its parameters.
So, returning void itself has no problem in pure functions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3572


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |yebblies gmail.com
            Version|2.036                       |D2
         Resolution|INVALID                     |
           Severity|normal                      |enhancement




 In current, we can declare a pure function which has "weak" purity.
 
 pure void foo(int* p, out string s, ref int[] arr);
 
 All results are returned through its parameters.
 So, returning void itself has no problem in pure functions.
This would still be meaningful for strongly-pure or const-pure functions. eg. pure void foo(string x) By definition calling foo does no observable work. While this might be WONTFIX or LATER like issue 3882, it is not invalid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 06 2013