www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4272] New: x.typeof syntax

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272

           Summary: x.typeof syntax
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-06-04 15:42:55 PDT ---
A syntax like x.typeof can be considered.

There are situations where you will need to parenthesize anyway, like:

import std.stdio;
void main() {
    int x = 1;
    float y = 1.5;
    writeln(typeid(typeof(x + y)));
}


You will have to write:
(x + y).typeof


But in many situations with this change you will be able to avoid the ().

This syntax is more similar/uniform to the x.sizeof syntax too (that is
sizeof(x) in C).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de


--- Comment #1 from Trass3r <mrmocool gmx.de> 2010-06-13 17:49:40 PDT ---
Then typeid should probably also be .typeid instead of typeid()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 13 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #2 from monarchdodra gmail.com 2012-09-14 11:17:24 PDT ---
*** Issue 8661 has been marked as a duplicate of this issue. ***

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


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com


--- Comment #3 from Jonathan M Davis <jmdavisProg gmx.com> 2012-09-14 14:20:26
PDT ---
typeof isn't a property or a function, unlike sizeof. It's like an
is-expression, and I think that treating it like a property would be a mistake.

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


Nick Treleaven <ntrel-public yahoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ntrel-public yahoo.co.uk


--- Comment #4 from Nick Treleaven <ntrel-public yahoo.co.uk> 2012-10-06
06:22:10 PDT ---
(In reply to comment #3)
 typeof isn't a property or a function, unlike sizeof. It's like an
 is-expression, and I think that treating it like a property would be a mistake.
I think (x + y).typeof should not be allowed, use the existing syntax instead. However, x.typeof is a useful shorthand that helps cut down on nested brackets in is expressions and elsewhere. So I would allow both typeof(expression) and identifier.typeof to be used, but *not* expression.typeof. The type of an instance is a natural property of the instance IMO. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #5 from Maxim Fomin <maxim maxim-fomin.ru> 2012-10-06 06:41:10 PDT
---
(In reply to comment #4)
 (In reply to comment #3)
 typeof isn't a property or a function, unlike sizeof. It's like an
 is-expression, and I think that treating it like a property would be a mistake.
I think (x + y).typeof should not be allowed, use the existing syntax instead. However, x.typeof is a useful shorthand that helps cut down on nested brackets in is expressions and elsewhere. So I would allow both typeof(expression) and identifier.typeof to be used, but *not* expression.typeof. The type of an instance is a natural property of the instance IMO.
The problem is that UFCS was made to work with functions and typeof is not a function. Accepting identifier.typeof would result in questions about which identifiers are valid for this and what else works besides typeof with them. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 06 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272



--- Comment #6 from Nick Treleaven <ntrel-public yahoo.co.uk> 2012-10-06
10:28:49 PDT ---
(In reply to comment #5)
 The problem is that UFCS was made to work with functions and typeof is not a
 function. Accepting identifier.typeof would result in questions about which
 identifiers are valid for this and what else works besides typeof with them.
This is not to do with UFCS. There are already many built in properties like x.sizeof, x.init: http://dlang.org/property.html typeof fits nicely as a built in property, and helps cut down on nested brackets. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 06 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4272



--- Comment #7 from Maxim Fomin <maxim maxim-fomin.ru> 2012-10-07 01:08:41 PDT
---
(In reply to comment #6)
 (In reply to comment #5)
 The problem is that UFCS was made to work with functions and typeof is not a
 function. Accepting identifier.typeof would result in questions about which
 identifiers are valid for this and what else works besides typeof with them.
This is not to do with UFCS. There are already many built in properties like x.sizeof, x.init: http://dlang.org/property.html typeof fits nicely as a built in property, and helps cut down on nested brackets.
Typeof is not a property either. And it differs from all those properties which, given a type or expression, provide fundamental information about their types like size, default value, name, alignment. Typeof works in opposite direction - given some expression it gives its type. BTW, identifier is a primary expression (http://dlang.org/expression.html), so, making idenfier.typeof possible and expression.typeof not (as mentioned above), raises some questions. However, if typeof is made a property too, it would be logical and consistent. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 07 2012