FOR lists

Here you can suggest additions and modifications to BB4W or BBCSDL
User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

FOR lists

Post by hellomike » Thu 07 Nov 2019, 09:18

Hi,

Would something like the following be hard to implement in BBCSDL?

Code: Select all

      FOR I% OF 3, 22, -9
      NEXT
      FOR Day$ OF "Mon", "Fri", "Sun"
      NEXT
Just wondering as it would be so powerful to an already extremely powerful programming language.

Thanks.

Mike

RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: FOR lists

Post by RichardRussell » Thu 07 Nov 2019, 13:39

hellomike wrote:
Thu 07 Nov 2019, 09:18
Would something like the following be hard to implement in BBCSDL?
I agree it would be a nice extension to the language. My main concern, from an implementation viewpoint, is the impact on the performance of NEXT. Since it would now have two distinct meanings, which would have to be tested every time around the loop (that being the nature of interpreters), there would unavoidably be a hit on the speed of ordinary FOR...NEXT loops and that would be a high price to pay.

The closest you can get using 'standard' BBC BASIC is iterating through an array:

Code: Select all

      DIM Day$(2)
      Day$() = "Mon", "Fri", "Sun"
      FOR I% = 0 TO DIM(Day$(),1)
        Day$ = Day$(I%)
      NEXT
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

Re: FOR lists

Post by hellomike » Thu 07 Nov 2019, 19:29

Thanks for the fast reply Richard.

Ah, yes I understand. Each NEXT could be part of the an old-fashion FOR TO STEP or a FOR OF but has to test that each time.

No worries. It is by no means an omission! I just thought lets mention it.

Regards,

Mike

RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: FOR lists

Post by RichardRussell » Fri 08 Nov 2019, 09:50

hellomike wrote:
Thu 07 Nov 2019, 19:29
No worries. It is by no means an omission! I just thought lets mention it.
I'm not ruling it out, it's a case of making a judgement about the relative pros and cons. Is it a sufficiently valuable feature that a slight performance hit to the existing FOR...NEXT functionality is acceptable? Probably the only way to make a rational decision would be for me to implement it experimentally (perhaps only partially, say only for numeric variables and only for the C implementation of the interpreter) and do the measurements.

But that would necessarily be quite a lot of work, especially given my declining ability to code competently, so before deciding whether to go down that route I'd like to get the views of other members. Do you think this would be a useful language extension?
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

p_m21987
Posts: 144
Joined: Mon 02 Apr 2018, 21:51

Re: FOR lists

Post by p_m21987 » Fri 08 Nov 2019, 10:37

If you can find a way to add this feature without impacting the speed of the usual for/next loops, you should add the feature.

User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

Re: FOR lists

Post by hellomike » Fri 08 Nov 2019, 14:51

Richard, I would say that you only consider working on it if:
  • there aren't more important/rewarding things on your to do list
  • you have the time for it
  • you feel it as a challenge AND most important...
  • you have fun in implementing new functionality like that
Regards,

Mike

Edja
Posts: 21
Joined: Tue 03 Apr 2018, 12:07

Re: FOR lists

Post by Edja » Fri 08 Nov 2019, 15:20

Richard,

Iterating through an array closely fits the functionality.
With that alternative in mind, I see little value in implementing this as part of the language.

Regards,
Edja

RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: FOR lists

Post by RichardRussell » Fri 08 Nov 2019, 16:54

p_m21987 wrote:
Fri 08 Nov 2019, 10:37
If you can find a way to add this feature without impacting the speed of the usual for/next loops, you should add the feature.
Some impact would be inevitable (there's nowhere in the existing code path that the two meanings of NEXT can be distinguished without additional execution time) but it might be quite small; as I said, it would need to be measured. The impact might be greater with the assembler implementation (used in the 32-bit x86 editions) than with the C implementation (used for the 64-bit and ARM editions). It should always be borne in mind that any changes to the BBCSDL specification need to be implemented twice!
hellomike wrote:
Fri 08 Nov 2019, 14:51
I would say that you only consider working on it if:
  • there aren't more important/rewarding things on your to do list
  • you have the time for it
  • you feel it as a challenge AND most important...
  • you have fun in implementing new functionality like that
I wonder why you suggested it in the first place if you now want to erect such a difficult-to-surmount barrier to its implementation! :?
Edja wrote:
Fri 08 Nov 2019, 15:20
I see little value in implementing this as part of the language.
Noted. As you may have seen, I raised the issue at StarDot (where there is probably a deeper BBC BASIC knowledge base than here) and the reactions so far have been universally positive. The author of Matrix Brandy has already expressed an interest in implementing it in that dialect of BBC BASIC, and history suggests that he may not take very long!

So the cat is well and truly out of the bag. Whether I commit to implementing it in BBCSDL or not, there may well be a version of BBC BASIC with that functionality quite soon, and that may force my hand.
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

KenDown
Posts: 91
Joined: Wed 04 Apr 2018, 06:36

Re: FOR lists

Post by KenDown » Sat 09 Nov 2019, 01:14

I must admit that I would not be in favour of the new syntax. FOR...NEXT is simple to understand, fast to execute and pretty well fool-proof. I really can't see the point of specifying in advance the values you require.

FOR I% OF 3,7,-9

What happens when I%=3? Does it automatically set I% to 7 and then -9 (so a loop that repeats three times) or does it only progress to the next value if something inside the loop sets I% to 7 and thus could have a potential infinite number of repeats? It seems to me that the FOR loop would no longer be simple to understand or foolproof, whichever is the correct understanding, and if it slows it down, even by a fraction, it would be a bad thing.

Perhaps someone could explain to this bear of very little brain what the advantages of the new syntax are?

User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

Re: FOR lists

Post by hellomike » Sat 09 Nov 2019, 09:21

Actually it is quite common functionality in modern program languages.
E.g., for Python https://www.w3schools.com/python/python_for_loops.asp

But people please see my suggestion only for what it is, a suggestion! hence it is in the "Suggestion Box".

Regards,

Mike

Post Reply