Could we reserve void[T] for builtin set of T ?

Q. Schroll via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 1 04:52:37 PDT 2016


On Friday, 1 April 2016 at 09:55:58 UTC, cym13 wrote:
> On Friday, 1 April 2016 at 08:52:40 UTC, Q. Schroll wrote:
>> [...]
>
> I most of what is said here, assigning true or false makes for  
> an aweful API compared to add() and remove(). I agree with Adam 
> Ruppe that if we are to use AA-like syntax we have to keep a 
> coherent API.

I don't like the AA-like syntax also. But in some sense it is 
straightforward.
Look at
     s[x, y] = true;
You can have a overload of add making
     s.add(x, y)
do that. But wait, add has a return value. Let x be already 
present in s and y not. What would you expect s.add(x, y) to 
return? This is unclear and ambiguous. In this case, I find the 
AA-like syntax nicer.

I've read through the thread without exactly tracking who said 
what.

On Thursday, 31 March 2016 at 20:11:39 UTC, Adam D. Ruppe wrote:
> aa[x] returns void, which, having no value, would be a compile 
> error.

The idea is great and I've adopted it in some sense. I don't know 
the API, so I cannot tell if something slightly hurts it. Is the 
add-funtion coherent API?

> Also, I don't like join etc... Please, just take the python 
> semantics.

Interestingly, I've never seen meaningful Python code -- you can 
believe it or not. Most of the proposal is very near to Python, 
right? The link let's me at least believe it is. Actually this 
proves the stuff is natural to people.
Unfortunately, union is a keyword in D, so we just can't use it. 
You can propose another name for set union if you are 
dissatisfied with join. I don't stick very much to that. Syntax 
highlighting does a good job here to tell someone union will 
likely not compile.
Is this all? What does your "etc." mean?

> Sets have been a builtin type for a long time now in that 
> language and they just
> make sense, they are very polished.

Sounds like we should have sets too and profit from the 
experience.

> Not to mention that many people that expect sets to be part of 
> the language itself seem to come from python.


More information about the Digitalmars-d mailing list