FOR lists

Here you can suggest additions and modifications to BB4W or BBCSDL
RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: FOR lists

Post by RichardRussell » Sat 09 Nov 2019, 13:54

KenDown wrote:
Sat 09 Nov 2019, 01:14
FOR...NEXT is simple to understand, fast to execute and pretty well fool-proof.
Yes, and so it will remain! I've already said that a significant slowing down would not be acceptable.
Does it automatically set I% to 7 and then -9 (so a loop that repeats three times)
Yes, the loop iterates three times with I% set to 3, 7 and -9 respectively.
It seems to me that the FOR loop would no longer be simple to understand or foolproof
Nobody is going to force you to use the new syntax!

I find your reaction surprising. I would not have expected an optional language extension to be so controversial, unless it impacts negatively on compatibility with, or performance of, existing programs. Would you at least accept it being implemented experimentally to allow the impact to be assessed quantitatively?
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, 18:10

Yes, of course I would accept any modification that you make to BB4W, on the simple grounds that you know far more about programming than I ever will and if, in your wisdom, you decide that a new feature is desirable, then it probably is. I wonder, however, if there might be some virtue in using a different code word, thus allowing FOR...NEXT to retain its advantages such as simplicity and speed, but making the new facility available for those who want it. Something like

LOOP I% = 7, 3, -9

ENDLOOP

(LOOP is just a word I dreamed up on the spur of the moment. There is probably something much more apposite!)

Mind you, it seems to me - and remember, I am no expert - that inside the loop (however it is named) there would have to be a number of IF or CASE...WHEN statements to determine what happens for the different values of I%, which means that the functionality of the proposed new routine can be easily implemented without any new keywords.

I%=7
REPEAT
CASEI%OF
WHEN7:blahblahblah:I%=3
WHEN3:blahblahblah:I%=-9
WHEN-9:blahblahblah
ENDCASE
UNTILI%=-9

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

Re: FOR lists

Post by RichardRussell » Sat 09 Nov 2019, 20:52

KenDown wrote:
Sat 09 Nov 2019, 18:10
you know far more about programming than I ever will
If that was ever true (and I doubt it) it isn't now; my 'cognitive decline' is robbing me of much that I once knew. I recently wrote some code to align a (global) integer array at a dword (multiple-of-4) address. It worked but it was a kludge and really ugly. A couple of nights ago at about 4 a.m. it came to me that LOCAL arrays are automatically aligned!! All I needed to do was make it a local array. How could I have forgotten that? :oops:
I wonder, however, if there might be some virtue in using a different code word, thus allowing FOR...NEXT to retain its advantages such as simplicity and speed, but making the new facility available for those who want it.
The trouble with that suggestion is the (potential) impact on compatibility with existing programs. With a language as established and stable as BBC BASIC the one overarching consideration that determines whether I am prepared to consider a modification is whether it might break a program that currently works. Adding a new keyword always can: all it takes is for a program to use the new keyword as a variable name and it will now be tokenised and the program won't run any more.
the functionality of the proposed new routine can be easily implemented without any new keywords.
I said that in my initial reply, where I listed a code snippet that reproduces the functionality of the requested extension. But several BBC BASIC features don't fundamentally add any new functionality, they just make a program more elegant and/or easier to understand. For example the CASE statement was added (by Acorn) despite it being possible to do exactly the same thing using IF.
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 » Sun 10 Nov 2019, 03:24

You may feel annoyed at having forgotten that a LOCAL array was word-aligned, but I think that just makes my point: you forgot it, but I never knew it!

I appreciate your point about the possibility of a new keyword being used in an old program as a variable name. I suppose that one method of dealing with that would be to make the new keyword "artificially different"; for example, although it is conceivable that someone might use loop% as a variable name, DLOOP or LOOPD is much less likely.

CASE...WHEN isn't exactly the same as a series of IF statements. As I'm sure you realise, evaluation of the WHEN statements ceases when one is found to be true, whereas a list of IF statements will continue to be evaluated to the end of the list. I don't know whether any programmers used case% or when$ as variable names, but the risk must have been worth it!

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

Re: FOR lists

Post by hellomike » Sun 10 Nov 2019, 11:11

That reminds me of the keyword OPENUP that Acorn failed to document in the 1983 BBC MODEL B USER GUIDE. Damn did I search for how to update an existing file using only OPENIN and OPENOUT!

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

Re: FOR lists

Post by RichardRussell » Sun 10 Nov 2019, 11:13

KenDown wrote:
Sun 10 Nov 2019, 03:24
it is conceivable that someone might use loop% as a variable name, DLOOP or LOOPD is much less likely.
That involves getting inside the head of the programmer. You say that DLOOP is an unlikely variable name, but in a program which has a number of similar and related loops, that are each relevant to a particular letter of the alphabet, you might have variables ALOOP, BLOOP, CLOOP, DLOOP etc. Now your 'unlikely' variable name has suddenly become quite likely!
CASE...WHEN isn't exactly the same as a series of IF statements. As I'm sure you realise, evaluation of the WHEN statements ceases when one is found to be true, whereas a list of IF statements will continue to be evaluated to the end of the list.
I don't agree with that at all. Compare the following three code snippets:

Using CASE:

Code: Select all

      CASE var OF
        WHEN 1: PROC1
        WHEN 2: PROC2
        WHEN 3: PROC3
      ENDCASE
Using IF (option 1):

Code: Select all

      IF var = 1 THEN
        PROC1
      ELSE
        IF var = 2 THEN
          PROC2
        ELSE
          IF var = 3 THEN
            PROC3
          ENDIF
        ENDIF
      ENDIF
Using IF (option 2, BB4W/BBCSDL extension):

Code: Select all

      IF var = 1 THEN
        PROC1
      ELSE IF var = 2 THEN ;
        PROC2
      ELSE IF var = 3 THEN ;
        PROC3
      ENDIF
In all three cases evaluation of the conditional expressions ceases as soon as one is found to be TRUE. I don't see how they are different, other than CASE providing a clearer and more elegant syntax.

You said in an earlier reply that "you know far more about programming than I ever will" yet your use of the phrase "As I'm sure you realise" suggests that you are confident that you know better than me on this occasion! :roll:
I don't know whether any programmers used case% or when$ as variable names, but the risk must have been worth it!
Those keywords (along with several others) were introduced in around 1984. Yes there was a real risk, but I don't think you can reasonably equate a change made 35 years ago with a proposed change now! BBC BASIC is a great deal more mature and stable than it was then, and the total number of programs liable to fail is much larger.
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.

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

Re: FOR lists

Post by RichardRussell » Sun 10 Nov 2019, 11:31

hellomike wrote:
Sun 10 Nov 2019, 11:11
That reminds me of the keyword OPENUP that Acorn failed to document in the 1983 BBC MODEL B USER GUIDE.
I can't remember the exact circumstances but is it possible that, rather than "failing" to document it, the User Guide had not been reprinted since the version supplied with early models of BBC Micro (in which neither OPENUP nor OSCLI keywords existed)?
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 » Sun 10 Nov 2019, 12:19

Dear me no! "As I am sure you realise" implies an acknowledgement that it is common knowledge between us.

Probably too late to implement it, but one solution to the problem of programs failing would be to have a BB4W version number in the program. If it was compiled with 6.12 then LOOP or NEXT could be interpreted in one way, if with v. 7.20 then those words could be interpreted in another way.

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

Re: FOR lists

Post by KenDown » Sun 10 Nov 2019, 12:24

Oh gosh! I've once or twice considered learning Python - my grandsons have dabbled in it at school - but that example has put me right off! Far far far too complicated!

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

Re: FOR lists

Post by hellomike » Sun 10 Nov 2019, 12:29

Indeed, also OSCLI isn't mentioned in that guide so you are probably correct Richard about the reason for this.

Post Reply