User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 2:25 am

This wasn't the error I was expecting.
Attachments
qbx_onenext.png
qbx_onenext.png (11.46 KiB) Viewed 520 times

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 2:32 am

This works. Go figure.
Attachments
testif.png
testif.png (10.18 KiB) Viewed 515 times

Andyroo
Posts: 3378
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: ScriptBasic

Tue May 14, 2019 2:34 am

Odd error indeed.

I wonder if the BASIC keeps a stack of functions to check for start / ends and has pushed the IF and then the FOR to the stack and as it comes across the ELSE it checks the last entry and coughs as it was not an IF? I could imagine this stack being used for pointers for next instruction locations...
Need Pi spray - these things are breeding in my house...

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 2:50 am

My ScriptBasic example works.
Attachments
QBX_SB_FOR_Out.png
QBX_SB_FOR_Out.png (7.39 KiB) Viewed 505 times
QB_SB_FOR_Code.png
QB_SB_FOR_Code.png (12.48 KiB) Viewed 505 times

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 8:51 am

hippy wrote:
Tue May 14, 2019 12:45 am
That all makes sense if the WEND is told where the WHILE was at run-time, just like FOR-NEXT. But, if the WHILE condition is initially false, which WEND does it choose to go to ?
I would expect it to be implementation dependent. In the case of BBC BASIC it will go to the lexically-nearest WEND (ENDWHILE in BBC syntax) i.e. the first one. My take is that anybody silly enough to use ambiguous code like this does so at his own risk, and with an expectation that even if it works the way he wants on one particular dialect it won't necessarily on others.

I would not even want to guarantee that all versions of BBC BASIC would work the same way when presented with such code. There are at least half-a-dozen BBC BASIC codebases and at least three different authors, and the language specification (such as it exists at all) doesn't specify what should happen in these kinds of circumstances.

hippy
Posts: 5373
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Tue May 14, 2019 12:46 pm

ScriptBasic wrote:
Tue May 14, 2019 2:25 am
This wasn't the error I was expecting.
Andyroo wrote:
Tue May 14, 2019 2:34 am
Odd error indeed.
Seems right by me though it could be better worded.

"ELSE without IF" to me is indicating there is no preceding IF which the ELSE matches with, because the thing it found was a FOR which hadn't been closed with a NEXT.

"Got ELSE when expecting NEXT" would be most accurate and informative but it all comes down to what information the error handler has to work with. From experience I know that it can be hard to produce accurate error messages and, given there ideally won't be any, it's a lot of work which may not be justified. If all one knows when one reaches an ELSE is that's not right, there are only a limited number of errors one can give "Unexpected ELSE" or "ELSE without IF" being the two most obvious. The second arguably slightly more useful.

One thing not stated is whether this is a compilation error or a run-time error. I suspect the former.
ScriptBasic wrote:
Tue May 14, 2019 2:32 am
This works. Go figure.
I can't see any reason why that wouldn't work.

If you mean why does that work when the earlier didn't; that's because a block-structured command hasn't been opened but not closed.

If you try this you'll probably also see the "ELSE without IF" error assuming WHILE is supported -

Code: Select all

IF flag > 0 THEN
  WHILE count = 1
ELSE
  WHILE count = 1
END IF
But this should work, assuming WEND closes a WHILE block -

Code: Select all

IF flag > 0 THEN
  WHILE count = 1
  WEND
ELSE
  WHILE count = 1
  WEND
END IF
Syntactically correct programs don't usually produce syntax errors :mrgreen:

hippy
Posts: 5373
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Tue May 14, 2019 1:38 pm

ScriptBasic wrote:
Tue May 14, 2019 1:40 am
In ScriptBasic every FOR needs it's own NEXT. I will try the single NEXT in QuickBasic and see if it complains. I view QB as the traditional BASIC standard when question of what is standard comes up.
I would expect every block-structured language to complain when blocks are incorrectly nested, when one tries to close an outer block before closing an inner block. That would be a syntax error for a block-structured language.

A block structured language can use all sorts of tricks, like stacks, to implement things by relying on its being block structured and there never being the possibility of any surprises.

A line-by-line compiler / interpreter is however in a different realm. That has to accept anything given to it and then figure out at run-time how things are, its current global state, and will have to avoid using stacks if they will be broken by surprises.

The problems arise when a block-structured language adds GOTO and similar, or a line-by-line compiler / interpreter layers block-structured constructs on top of itself.

There are four options -

1) Ensure the block-structure implementation cannot be broken in any way. For example giving syntax errors on improperly nested blocks and on GOTO to places which would invalidate stacks. Providing EXIT commands which allow exits from loops without using GOTO.

2) Evaluate execution flow at run-time. Which means forgoing compilation checks that any block-structuring of the source code is correct.

3) Create an implementation which is neither one or the other, a mix of both, but which executes anything which does pass syntax check correctly and as expected.

4) Create a less robust implementation which is neither one or the other which allows things through syntax checking which then crash and burn at run-time.

Any block-structured basic without GOTO would be a (1), BBC BASIC seems a (2), VB6 and QB seem to be (3), ScriptBasic is a (4).

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 2:20 pm

ScriptBasic never tried to run the code. It failed in the tokenizing stage and reported the erroronious nesting scheme.

hippy
Posts: 5373
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Tue May 14, 2019 2:36 pm

ScriptBasic wrote:
Tue May 14, 2019 2:20 pm
ScriptBasic never tried to run the code. It failed in the tokenizing stage and reported the erroronious nesting scheme.
I was judging it as a (4) based on the previous "Once you use GOTO to exit a stack controlled structure, jumping back into the 'expired' structure would cause a stack error".

My judgement is that any compiler which allows something which it should know will fail has a poorer implementation than it should be.

I can accept that 'if that's what it does; that's what it does' and that's fine in itself, but it does affect how I view the usefulness of any particular compiler and whether I would use it or recommend it for use by others.

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 3:01 pm

ScriptBasic wrote:
Tue May 14, 2019 2:20 pm
ScriptBasic never tried to run the code. It failed in the tokenizing stage and reported the erroronious nesting scheme.
It's only "erroneous" when looked at from a certain perspective. Suppose that you want to loop through the odd numbers in a range if a flag is set but the even numbers if it's not set; that doesn't seem particularly contrived to me. In that case I would argue that a construction like this is a reasonable way of representing it:

Code: Select all

if flag<>0 then
  for index = 1 to 21 step 2
else
  for index = 0 to 20 step 2
endif
I'm sure you wouldn't complain if it was a compile-time decision taken by a preprocessor (here in a mash-up of C and BASIC):

Code: Select all

#if FLAG<>0
  for index = 1 to 21 step 2
#else
  for index = 0 to 20 step 2
#endif
So why is one acceptable but the other not?

The alternatives are no better from my point of view. One is to use calculated values in the FOR statement:

Code: Select all

for index = flag to flag+20 step 2
which isn't as readable and will misbehave if flag isn't 0 or 1. Or to duplicate the entire loop body:

Code: Select all

if flag<>0 then
  for index = 1 to 21 step 2
    rem body of loop
  next index
else
  for index = 0 to 20 step 2
    rem body of loop again
  next index
endif
which is wasteful and error prone (if one were to edit one loop but not the other). Yes one could hive off the body of the loop into a function but arguably that makes the code less readable in another way.

There's probably no perfect answer to this, but I'm uneasy about ruling out what is arguably the clearest code because it's an "erroneous nesting scheme".

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 3:27 pm

I believe QBX reported the error at runtime and missed the nesting issue in its syntax checking phase in the IDE.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 3:49 pm

I can accept that 'if that's what it does; that's what it does' and that's fine in itself, but it does affect how I view the usefulness of any particular compiler and whether I would use it or recommend it for use by others.
If QB was still the proponent BASIC, your attitude wouldn't buy you a cup of coffee. Like I said earlier, QB is the standard for traditional BASIC. I'm happy SciptBasic plays well with ported QB code.

FreeBasic wouldn't have created a QB compatibility mode if they felt the language was just an obscure derivative of BASIC. PowerBasic on the other hand is the odd, halfbaked and obscure BASIC.
Last edited by ScriptBasic on Tue May 14, 2019 4:09 pm, edited 3 times in total.

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 4:04 pm

ScriptBasic wrote:
Tue May 14, 2019 3:49 pm
QB is the standard for traditional BASIC.
QuickBASIC (1985) didn't exist when BBC BASIC was originally specified and implemented (1981) so it would be difficult to criticise BBC BASIC on the grounds of it not being compatible with QB! :roll:

Heater
Posts: 12739
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue May 14, 2019 4:07 pm

Oh boy, all is not well in BASIC land.

When Dijkstra said "Go To Statement Considered Harmful" I only ever thought about it from the perspective of the user of a language that supported GOTO. How they could get themselves into a horrible, incomprehensible mess by using GOTO. How the availability of GOTO did not encourage people to organize their thoughts nicely.

With this discussion I discover that GOTO is a lot more harmful than I ever imagined. Seems that supporting GOTO in a language is totally confusing to the guys defining/building the language. With the result that various implementations of the same language end up treating GOTO differently.

@RichardRussell
In that case I would argue that a construction like this is a reasonable way of representing it:

Code: Select all

if flag<>0 then
  for index = 1 to 21 step 2
else
  for index = 0 to 20 step 2
endif
I would argue that is completely insane.
I'm sure you wouldn't complain if it was a compile-time decision...So why is one acceptable but the other not?
It's not comparable to a compile time textual substitution by a preprocessor as in C.
In the former case "flag" decides what happens at run time. Could be different every run. In the later case the behavior is frozen in at compile time.

The C preprocessor is an ugly hack anyway.

Heater
Posts: 12739
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue May 14, 2019 4:14 pm

RichardRussell
QuickBASIC (1985) didn't exist when BBC BASIC was originally specified and implemented (1981) so it would be difficult to criticise BBC BASIC on the grounds of it not being compatible with QB!
Yet you commend the new BBC BASIC for compatible with LibertyBasic from 1992?

This BASIC world is very confusing. I feel the need to create HeaterBASIC. To put all this straight...
Last edited by Heater on Tue May 14, 2019 4:15 pm, edited 1 time in total.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 4:14 pm

QuickBASIC (1985) didn't exist when BBC BASIC was originally specified and implemented (1981) so it would be difficult to criticise BBC BASIC on the grounds of it not being compatible with QB! :roll:
No offense but I consider BBC BASIC a retro class offering.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22743
Joined: Sat Jul 30, 2011 7:41 pm

Re: ScriptBasic

Tue May 14, 2019 4:16 pm

I occasionally read this thread to make sure you are all behaving, and this goto stuff/argument in the biggest load of nonsense I've read in ages.

If you want to write crap code, you can do it any language.

So just don't write crap code, irrespective of whether the compiler/interpreter find it valid or not.


Isn't there something more interesting to talk about? I've got some paint drying at home that could do with some commentry.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

ejolson
Posts: 3082
Joined: Tue Mar 18, 2014 11:47 am

Re: ScriptBasic

Tue May 14, 2019 4:23 pm

RichardRussell wrote:
Tue May 14, 2019 3:01 pm
I would argue that a construction like this is a reasonable way of representing it:

Code: Select all

if flag<>0 then
  for index = 1 to 21 step 2
else
  for index = 0 to 20 step 2
endif
I'm sure you wouldn't complain if it was a compile-time decision taken by a preprocessor (here in a mash-up of C and BASIC):

Code: Select all

#if FLAG<>0
  for index = 1 to 21 step 2
#else
  for index = 0 to 20 step 2
#endif
So why is one acceptable but the other not?
It is an interesting question whether the constraints of structured programming can lead to verbose or overly complicated code that could have been expressed more clearly in a different way.

Do closures and functional programming solve this problem in a way that is even better than spaghetti?

The example in this post also depicts a simplification that follows from letting one bit of code write another bit. In that case the idea was to programmatically loop over all outcomes in the probability space of rolling n fair dice where the value of n can vary. Unfortunately the developer of FidoBasic is barking mad.

The difference between using a preprocessor and the Basic example is that in the former the flow of data is only one direction: Computational results produced by running the C code can't change what the preprocessor has already done. When there is a two-way flow of information in which the structure of the code changes as the code runs, this appears to be a type of self-modifying code.

Things are confusing enough if only the type of a variable changes dynamically as a program runs, how much more so if the structure of the loops change. At the same time, the back-propagation algorithms used in deep-learning can also be seen as a way for a neural network to modify itself. Compared to auditing the weights which constitute a program in deep-learning artificial intelligence, understanding traditional self-modifying code and even Basic is trivial.
Last edited by ejolson on Tue May 14, 2019 4:33 pm, edited 3 times in total.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 4:23 pm

I thought the IUP extension would generate some interest but was told I'm wasting my time and all Ui code is now done in a web browser.

I'm not ready for a Chromebook world yet.

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 4:25 pm

Heater wrote:
Tue May 14, 2019 4:14 pm
Yet you commend the new BBC BASIC for compatible with LibertyBasic from 1992?
I think you must have misunderstood something. Liberty BASIC is almost as different from BBC BASIC as it is possible to be and still be called BASIC: Liberty BASIC is a GUI-based event-driven BASIC using Windows controls for its input/output. The two are not at all compatible, and I always advise Liberty BASIC users not to try converting their programs to BBC BASIC because it's difficult.

Are you perhaps confused because 'LB Booster', a near perfect clone of Liberty BASIC that I also market, is coded in BBC BASIC?

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Tue May 14, 2019 4:28 pm

IF / THEN / ELSE isn't a cloaking statement in BASIC.

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 4:39 pm

ScriptBasic wrote:
Tue May 14, 2019 4:14 pm
No offense but I consider BBC BASIC a retro class offering.
I don't know what "retro class offering" means. What description one uses is irrelevant anyway, the important thing is what a language can achieve. BBC BASIC is a highly capable language, as you can see from the example programs I supply with it, from the commercial and other applications that have been programmed using it, and from its large user base. The BBC BASIC of today is very different from the BBC BASIC of 1981, despite retaining a high degree of compatibility with it.

I would suspect there's little overlap between the markets that BBC BASIC and ScriptBasic are aiming at, so I don't see them as competitors or rivals. I wouldn't choose BBC BASIC as a scripting language; it can be coerced into behaving that way but it's a kludge. Equally I don't suppose you would recommend ScriptBasic for a shoot-em-up video game or a real-time video processing application.

Heater
Posts: 12739
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue May 14, 2019 4:40 pm

RichardRussell
Are you perhaps confused because...
I am confused because the BASIC world is confusing.

BASIC is the only language to have multiple entries in the fibo challenge. All incompatible.

Was it not you that said that I was not as in touch with the personal computing world because I had never heard of PowerBASIC, LiberyBASIC, thisBasic, thatBASIC? All kind of things nobody I know has ever heard of. Now "LB Booster"?

Heater
Posts: 12739
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Tue May 14, 2019 4:46 pm

ScriptBasic,
IF / THEN / ELSE isn't a cloaking statement in BASIC.
Luckily it is in KlingonBASIC :)

And in C, C++, Javascript, etc...

User avatar
RichardRussell
Posts: 537
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Tue May 14, 2019 5:00 pm

Heater wrote:
Tue May 14, 2019 4:40 pm
BASIC is the only language to have multiple entries in the fibo challenge. All incompatible.
Yes, because BASIC isn't a language, it's a large group of languages which bear some (but often not much) similarity to the original Dartmouth BASIC. It only becomes a language when you attach a qualifier, like QuickBASIC or ScriptBasic or Visual BASIC or BBC BASIC or Liberty BASIC or PowerBasic or PureBasic or.....

Return to “Other programming languages”