Obsecure problem 2

jfondren julian.fondren at gmail.com
Wed Aug 3 21:37:50 UTC 2022

On Wednesday, 3 August 2022 at 19:11:51 UTC, pascal111 wrote:
> On Wednesday, 3 August 2022 at 18:53:35 UTC, jfondren wrote:
>> On Wednesday, 3 August 2022 at 18:33:37 UTC, pascal111 wrote:
>>> I changed it to "x=notfunny(x);" and has the same result.
>> Now you are changing the value of the temporary loop variable 
>> that is still immediately discarded afterwards.
>> You should return a new range that has the values you want, 
>> not try to mutate the range you're given.
> You should provide a code instead of describing my mistakes!!

I agree to the extent that I wanted to do so, and might still 
have if a delivery hadn't interrupted by post. But one way to 
encourage others to put in more effort is put in effort yourself. 
Here you have your first post, where you didn't use 'preview' to 
check that your formatting worked, or review when linked Markdown 
guide to see what the problem was when it didn't work. In that 
post you also didn't describe what the problem was or ask any 
question, or say what you wanted to accomplish. It wasn't until 
your second post that it was even clear to me that you wanted to 
reimplement `map`. I thought the addition was a placeholder. The 
thread title is also a placeholder title for a thread.

In your second and third posts, it didn't come across at all that 
you'd put much thought into your questions before asking them. 
The second post--just look at your code. There's a function call 
and data going nowhere. That should be pretty easy to see. For 
the third post, if you thought that 'foreach' aliased the members 
of a range to the degree that simple assignment would update the 
range, you could test that thought in an instant:

$ rdmd --eval 'auto a = [1, 2, 3]; foreach (n; a) n = 0; 
[1, 2, 3]

It seemed to me that with these quickly asked questions that 
you're treating the thread like an ongoing interpersonal dialogue 
where questions are cheap. That's fine, really. I didn't mind 
that you didn't put in a lot of effort because it also didn't 
require a lot of effort to help you. But if you're going to 
complain about it, at least put the effort into asking for what 
you want at the outset.

The last thing that discouraged me from writing a full example is 
that I wasn't sure that I'd really be helping you. If you're 
trying to do this, don't you have a range tutorial open? That 
should already be pretty well-written already. Now that I've 
helped you with some incidental problems you should get back to 
the tutorial and see where you got things mixed up. My guess was 
that you didn't realize you should be returning a new range, and 
not trying to modify the range you were given.

If you don't have a tutorial open, the first link at 
https://dlang.org/phobos/std_range.html is pretty good: 
http://ddili.org/ders/d.en/ranges.html You won't find the exact 
thing you want to do, but if you put that aside and thoroughly go 
through that chapter, the only way you won't be able to do what 
you want to do is if you get caught up again by some other more 
fundamental issue with D. The worst likely outcome is that you'll 
get something that works but that isn't a great way to do it. You 
should post that code here for feedback.

More information about the Digitalmars-d-learn mailing list