Parameterized Keywords

Bob the Viking via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 8 09:28:59 PST 2016


On Tuesday, 8 March 2016 at 04:43:11 UTC, Patience wrote:
> On Tuesday, 8 March 2016 at 00:47:10 UTC, Mike Parker wrote:
>> To be fair, this is a D newsgroup and you did not specify that 
>> you are talking about this as a general concept rather than 
>> something for D. My first reaction was the same. It's only 
>> natural to assume you are talking about this as a part of D.
>
> Yes, but that isn't the point. The point is that only retards 
> such as Bob takes abstractions literally.

I don't, really. I'm pointing out that you have given us far too 
little to have any sensible discussion. Your post is equivalent 
to 'What if cows could fly? Imagine the possibilities.' Yes, 
there may be advantages to flying cows, but if you can't think of 
good ideas, why should the onus be on the rest of us to do that 
for you?


> Why does it matter if I used [] or {} or . or \ or <> to 
> reference something doesn't exist yet and hence could be 
> defined any way one wants?

VGhpcyBpcyBidWxsc2hpdC4g

IOW:
If we are to discuss anything, we need to agree on a language. 
here, we tend to use English, and we tend to discuss in the 
context of D. Feel free to transcend these borders, but say so 
clearly, and don't be surprised if people misunderstand you when 
you don't. Even more, don't act like a total jackass when someone 
does (as was the reason for my somewhat more spirited post 
yesterday).


> That is, I except someone to have to think about what I'm 
> saying and interpret it properly instead of just adding there 2 
> cents and pretending like it's a dollar.

Your opening post fits exactly within this prison you just built 
- you have 2 very vague and unfinished ideas and seem to think 
they are a million dollars. Maybe there's something there, but 
you have failed to show it.

As for the int[size] idea, here's a template that could do 
everything you describe:

template Int(size_t bits)
{
   static if (!bits.isPowerOf2 || bits < 8)
     // use bitfields
   else static if (bits == 8)
     alias Int = byte;
   else static if (bits == 16)
     alias Int = short;
   else static if (bits == 32)
     alias Int = int;
   else static if (bits == 64)
     alias Int = long;
   else
     alias Int = FixedSizeBigInt!bits; // Does not exist yet. 
Please to write?
}

We are now down to one vague idea. Let's kill that off while 
we're at it:

auto possiblyNullRange(R)(R r) if (isInputRange!R)
{
   static if (isBidirectionalRange!R)
   {
     static if (hasAssignableElements!R)
       alias resultType = BidirectionalAssignable;
     else
       alias resultType = BidirectionalRange;
   }
   else static if (...) // And so on for all the different range 
variations.

   alias E = ElementType!R;
   if (r is null)
     return resultType!E(r);
   else
     return resultType!E([]);
}

We could even rename that to q, and we end up with the same 
number of characters: 'foreach (e; q(myRange))' vs 'foreach[?] 
(e; myRange)'.

We now have but a nebulous concept of keywords that take 
parameters, and no idea how to use them. That and your tone are 
what I object to, not your careless use of syntax.


More information about the Digitalmars-d mailing list