|
Post by Brandon Parker on Jan 15, 2022 17:59:05 GMT -5
Here is a simple example for the Rosetta Code task titled Two identical strings. Rosetta Code - Halt and catch fireHere is the code: . This is just one possibility; it throws a syntax error. One could also introduce a non-printable character into the IDE to make it appear as if nothing was there. The "Filter Bad Characters" would have to be turned off in Preferences for the non-printable character trick to work. {:0) Brandon Parker
|
|
|
Post by tsh73 on Jan 16, 2022 13:28:24 GMT -5
Hello Brandon I believe you read it wrong Task says
so it should not syntax error.
Probably referring to negative item of array will do like
print ERROR.this.stops.with.error(-1)
it is syntactically correct it breaks it even could be error handled and message could be extracted (from made up array name)
Result with error caught and message extracted
1 2 3 4 5 6 7 Error just happened 9 Subscript out of range: -1, ERROR.this.stops.with.error() Message is .this.stops.with.error()
(uncomment 1-st line to catch this error)
'on error goto [handler]
for i = 1 to 10 print i if i =7 then 'line that breaks program print ERROR.this.stops.with.error(-1) 'Runtime error: Subscript out of range: 11, ERROR.this.stops.with.error() end if next print "program is over" end
[handler] print "Error just happened" print , Err, Err$ 'is it our kind of induced error? if Err=9 and instr(Err$,"ERROR.")<>0 then print "Message is" print ,mid$(Err$, instr(Err$, ".")) end if
|
|
|
Post by Brandon Parker on Jan 16, 2022 14:36:39 GMT -5
I suppose it does say that it needs to be syntactically correct...
In that case, I submit this new version...
Print 0/0
{:0)
Brandon Parker
|
|
|
Post by Carl Gundel on Jan 17, 2022 6:52:09 GMT -5
I suppose it does say that it needs to be syntactically correct... In that case, I submit this new version... Print 0/0 {:0) Brandon Parker How about this? goto 0 I guess the use of division by zero is more reliable because someone might actually use a 0 line number. On the other hand the entry in Rosetta code says the program should be as short as possible, so on those grounds it wins out over print 0/0. If there are no DATA statements in the program you can also use this: read a
|
|
|
Post by tsh73 on Jan 17, 2022 8:23:17 GMT -5
Oh. It really smells Spectrum BASIC.
10 INK NOT PI: PAPER NOT PI: BORDER NOT PI:RANDOMIZE USR 0
On my machine it works OK without /0, but with 0/0 it kills BASIC (JB2) timer 0,0 wait 0 print 0/0
|
|
|
Post by Brandon Parker on Jan 17, 2022 15:03:43 GMT -5
I guess the use of division by zero is more reliable because someone might actually use a 0 line number. On the other hand the entry in Rosetta code says the program should be as short as possible, so on those grounds it wins out over print 0/0. Well, maybe I can just one-up that... Here is my new "shortest possible"...I think... Somehow, this does not raise a syntax error, but it causes a Runtime Error... Let {:0) Brandon Parker
|
|
|
Post by klewlis on Jan 17, 2022 20:33:59 GMT -5
I thought it said the fewest lines possible, so anything that can crash it in one line?
a=b/0
|
|
|
Post by Carl Gundel on Jan 18, 2022 7:43:02 GMT -5
I thought it said the fewest lines possible, so anything that can crash it in one line? a=b/0 Shortest divide by zero solution, except that you only need one variable. i.e. a=1/0
|
|
|
Post by Carl Gundel on Jan 18, 2022 7:45:51 GMT -5
Well, maybe I can just one-up that... Here is my new "shortest possible"...I think... Somehow, this does not raise a syntax error, but it causes a Runtime Error... Let Really? Doesn't make it through the compile for me.
|
|
|
Post by Brandon Parker on Jan 18, 2022 18:22:41 GMT -5
Really? Doesn't make it through the compile for me. I would say that it fits the bill because a syntax error should be caught and shown in the status bar at the bottom of the IDE. And, it generates a Runtime Error during the compilation process for me. To me, that looks like we made it to the point where the Runtime Engine fires up... Maybe it's stretching it because it doesn't make it to the Debugger, but I am going to stick with my statement above... {:0) Brandon Parker
|
|