extend foreach to work on non-arrays

IntegratedDimensions IntegratedDimensions at gmail.com
Fri May 25 19:49:51 UTC 2018


On Friday, 25 May 2018 at 04:28:31 UTC, Jordan Wilson wrote:
> On Friday, 25 May 2018 at 03:34:43 UTC, IntegratedDimensions 
> wrote:
>> On Friday, 25 May 2018 at 02:43:39 UTC, Jordan Wilson wrote:
>>> On Thursday, 24 May 2018 at 23:22:56 UTC, 
>>> IntegratedDimensions wrote:
>>>> the idea in the first place. I needed a hammer but no one 
>>>> invented it. If I give you my use case then there would be 
>>>> two main outcomes: You attempt to find a workaround for the 
>>>> use case or claim that it is not applicable. These are the 
>>>> "I have a rock that should work as good as that hammer 
>>>> thingy you want" and "Hammers are useless".
>>>
>>> 3rd outcome: noobs like me who read the forums who benefit 
>>> from such discussion.
>>>
>>> Of course, you could be as disinterested in the 3rd outcome 
>>> as you are the 1st and 2nd, and that's completely fair.
>>>
>>> Jordan
>>
>> Giving specific examples that are not applicable to your 
>> knowledge base won't help you. If you are too noobish to see 
>> how unifying foreach across non-arrays is useful then you have 
>> no experience where it is. Sure I could give some examples but 
>> then you have the option of excepting them as useful or saying 
>> they are too trivial.
>>
>> If you can't think of examples on your own then you are 
>> probably not ready for the increase expressiveness of what the 
>> feature allows. It simply means don' t use the new feature. 
>> Why worry about something you don't understand?
>>
>> void foo(T)(T t)
>> {
>>   foreach(a; t)
>>   {
>>
>>   }
>> }
>>
>> Does that help? I doubt it. If you are too much of a noob you 
>> won't get why the above makes certain things easier. If you 
>> don't have a good working knowledge of templates then you 
>> won't see how such a feature enhancement can simplify things.
>>
>> So, I will solve the homework problem for you:
>>
>> auto max(T)(T t)
>> {
>>   baseTypeOf(T) a;
>>   foreach(a; t)
>>      a = max(a,t)
>>   return a;
>> }
>>
>> max(3) = 3
>> max([3,4,5]) = 5
>>
>> See? and this is just an arbitrary example that I hope makes 
>> you happy. My examples are more complex and I don't see why it 
>> is necessary for me to waste 30m of my time extracting and 
>> developing a demo just to show that the feature is useful. It 
>> really boils down to the fact that if you can't see it being 
>> useful to you then it isn't and if you can then it is. A noob 
>> isn't going to be able to determine if the feature is sound or 
>> not so it is pointless for a noob to really worry about it.
>
> I genuinely read these forums to increase my learning, and it's 
> slow progress, but I believe it does help (obviously actually 
> programming and looking at the many resources available online 
> plays a big part too).
>
> My intention wasn't to make you justify yourself; not at all. 
> My intention was to simply to say that there are some people 
> (well, maybe it is just me) who genuinely learn from more 
> advanced programmers simply by reading their discussions with 
> other advanced programmers.
>
> I suppose I was just trying to be encouraging, but clearly it 
> was more annoying, so my apologies for that.

No, not necessarily. Don't be offended. Nothing person. Maybe in 
a different context things would be different but I was attacked 
initially and you might have been caught in the cross fire.

My point was that you can't expect others to provide ever detail 
to you so you can learn. That is not the way to learn. You must 
learn to by getting behind having to be spoon fed. The only 
difference between a noob and a profession is the profession has 
learned how to read in between the lines. Noobs want training 
wheels because it makes them feel safe, but that is also what 
keeps them being a noob.

Just for you! (well I did for the other guy cause he was being an 
ass but I guess it worked out for you)

https://dpaste.dzfl.pl/1f5578364b6d


The point is that if you the people that know a little more have 
to spell everything out for the people who don't then it slows 
everyone down. It is up to the noobs to play catch up, not up to 
the "pros"(not that I would call myself a pro) to slow down.

Not everything is meant for noobs either, this question wasn't 
for noobs and was for people who knew what I was talking about 
and knew of a good solution. One person provided it out of about 
4-5. It should have been one response, his, and that is all. 
Maybe a few others could talk about specifics if interested but 
there should be no expectations on my part to waste any time on 
irrelevant things that do not progress the original topic. I 
asked a very specific question that had a very specific answer. 
Not really much room for other things... but you can see how it 
turns in to a whole shit storm by someone that didn't understand, 
gave a solution that wasn't really good, I told them, then they 
got upset and attacked me for this and that rather than just 
leave it be or try to satisfy my constraints. Sure, I could have 
been more clear, but it doesn't matter how clear someone is there 
will always be problems so there is a balance.

Do you want proof why? I will give it too since I feel like a 
giving mood:

1. I cannot predict when I write a post what the responses will 
be. No one can. I can only state a problem and hope for the best. 
If I had to contemplate every possible scenario and satisfy 
everyone needs I'd waste far more time than I have.

2. People then come in, read the question, try to figure out what 
it means... usually reading more or less in to it than is meant(a 
general problem of communication), and give a reply. It is their 
job to take the information and try to be exacting as possible, 
not mine for trying to be as general as possible. This is a 
standard thing in the universe. Things must flow naturally in a 
certain direction.

What you get is that some people want things to flow the wrong 
way because they don't get it. It's like covariance and 
contravariance. Containment(of types, sets, whatever) only works 
one way.

What this means is that it is impossible for me to provide all 
the details of all the possible humans and all their possible 
responses to my post in a post. First of all, there is a limit to 
the post size. Second, I only want to spend so much time on such 
a question.

Now, once I make the post then things are constrained. I stated 
specific things and now the replies builds off that. This is 
standard communications on anything. It makes no sense for them 
to reply about arbitrary non-related stuff. This is like trying 
to stick an arbitrary type T in to a type S. It doesn't work in 
general because their has to be a relation of information for 
things to make sense in the world(there is the flow of direction).

Conversations are really no different in abstraction that 
programming. Just as bugs can be introduced in programming they 
happen in conversations. The problem is there are a lot of people 
who have bad conversational logic.

You may think I'm adding a bunch of nonsense but everything I'm 
talking about is built off your statements, You supplied me with 
a type S and I created far more complex type T than you probably 
anticipated, but at the heart of T is S(T, a generalization of S. 
My response a generalization of yours).

So, any ways, probably more than you wanted but you see how 
complex things can get, and this is why I don't bother to spoon 
feed anyone. It can turn in to a rats nest very quickly and most 
people don't care about or can't understand the true complexities.












More information about the Digitalmars-d mailing list