Why D is annoying =P

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 24 13:17:10 PDT 2012


On Wed, Oct 24, 2012 at 10:09:36PM +0200, Mehrdad wrote:
> On Wednesday, 24 October 2012 at 20:07:49 UTC, H. S. Teoh wrote:
> >On Wed, Oct 24, 2012 at 09:50:18PM +0200, Mehrdad wrote:
> >>On Wednesday, 24 October 2012 at 19:41:42 UTC, Mehrdad wrote:
> >>>So you can't really write a real program in D, to put it
> >>>bluntly.
> >>
> >>
> >>Case in point: there's no way to tell an arbitrary object/struct to
> >>give you its hash code.
> >
> >Huh?  All objects implement toHash().
> 
> 
> Not Tuples, apparently. (I didn't mean Object, I mean "object" in
> the general sense.)

Well, Object implements toHash(). Other things don't, but with UFCS you
can endow them with toHash(). :)


> >You can just use rt.util.hash.hashOf for structs.
> 
> Will try, thanks for the pointer.

hashOf works for pretty much anything (it's just a byte-based algo). So
it's not just structs, you can pass anything to it. Using UFCS to map
toHash() to hashOf will give you toHash() for literally everything,
which is apparently what you want (though I question the wisdom of
wanting a hash value of *everything*, including objects representing
network resources, the OS, etc., but hey, you can do it if you *really*
want to).


T

-- 
It won't be covered in the book. The source code has to be useful for
something, after all. -- Larry Wall


More information about the Digitalmars-d mailing list