FAQ  •  Register  •  Login

End if

<<

Darkstar

Posts: 81

Joined: Tue Mar 29, 2011 1:05 am

Post Fri Apr 12, 2013 4:22 pm

End if

Is there a way so you can write:

IF a = b THEN PRINT "A and B are equal";

Instead of:
IF a = b THEN PRINT "A and B are equal";: END IF

To keep compatibillty with the original ZX BASIC?

Then you will not have to change all of those IF/THEN lines in old sorce code, and also perhaps some kind of swithc or a #pragma directive so
you will not have to rewrite draw and plot commands while also keeping the new way of using those commands and then without the directive
of course.

The original BASIC version would also not allow to PLOT or DRAW on the bottom two lines.
Example:
PLOT x+100,y-100 ' original BASIC version
PLOT x+100,96-y ' zxb version

This would greatly simplify things and keep bugs to the minimum.

READ/RESTORE/DATA is not that important compared to the other stuff.
<<

Darkstar

Posts: 81

Joined: Tue Mar 29, 2011 1:05 am

Post Fri Apr 12, 2013 4:34 pm

Re: End if

Like

#Pragma Compat

that works with the --sinclair option or any "optional" machine for that matter.

Then READ/RESTORE/DATA would only be allowed in that mode.

Kind of like -lang qb in FreeBasic.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Apr 12, 2013 6:55 pm

Re: End if

This topic has been debated before. Unfortunately, no.
Doing that is very ambiguous. Eg.

  Code:
IF A = B THEN PRINT "1st"
PRINT A
PRINT B
IF B = C THEN PRINT "2nd"
PRINT C
END IF

Which IF is closed by END IF? The 1st or the 2nd one?
There is a rule (when this is hardly implemented) which states it must be the 2nd if.

I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).
<<

Darkstar

Posts: 81

Joined: Tue Mar 29, 2011 1:05 am

Post Fri Apr 12, 2013 8:46 pm

Re: End if

boriel wrote:I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).


Yes, I agree. All things considered then this is the ONLY viable solution in my view.

Also, it might also be sensible to enable Single Line IFs in Compat only mode along with the old versions of PLOT/DRAW and the READ/RESTORE/DATA
commands.

Or do seperate directives like: #Pragma CompatPrimitives and #Pragma CompatSingleIFs and #Pragma CompatDATALists.
Then the user can control what to rewrite and whatnot, and the CompatPrimitives (PLOT etc) is then coupled with the --sinclair option.
Then you can turn it all on at once by using #Pragma CompatOriginalBASIC and that makes four #Pragma(s) in total. No need to specify
"CompatOriginalZXBASIC" because that is specified implicitly with the --sinclair option.

Of course, in SingleIFs mode with END IF disabled then the current format is disabled but that is OK because I suspect that the orginal BASIC dialog
in the other machines do not support it.
<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Wed May 14, 2014 9:18 pm

Re: End if

Darkstar wrote:
boriel wrote:I've been seriously thinking in this, and the only solution I've come up with is that implementing "Single line" IFs will be exclusive (that is, when enable, END IF will be disabled).


Yes, I agree. All things considered then this is the ONLY viable solution in my view.


I think there's another solution: SAM Coupé's SAM BASIC and MasterBASIC, written by Andy Wright. already solved the same problem: An IF without a THEN or with no command after its THEN would be multiline and would need an END IF. In ZX BASIC, this behaviour would be optional, as you said.

  Code:
#pragma sinclair_basic_compat ' ...or whatever name

IF a=1 THEN PRINT "This is old code pasted from Sinclair BASIC"

if b=2
  print "This is modern code"
end if

if b=3 then
  print "this is modern code too"
end if

IF PI THEN BEEP 1,2:PRINT "MORE OLD CODE"



What do you think? Would it be feasible?
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu May 15, 2014 9:32 am

Re: End if

Yes. ;-)
This is exactly what I was thinking! and believe it could be done. :)
An IF followed by a THEN in the same line will be a single line IF, so all old BASIC listings will be more compatible.

What do the others think?
<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Thu May 15, 2014 11:56 am

Re: End if

boriel wrote:An IF followed by a THEN in the same line will be a single line IF


An IF followed by a THEN and at least one command, all in the same (logical) line. Otherwise compatibility with current code would be broken, and both kinds of IF could not be mixed unless you switch on and off the option flag.

  Code:
' Example of old and new IF structures in the same source,
' all of them with THEN.
#pragma short_if=TRUE ' ...or whatever name
IF PI THEN PRINT "PURE SINCLAIR BASIC IF":BORDER 1:PAPER 0:CLS
IF PI THEN
  PRINT "MULTILINE IF":BEEP 3,3
END IF
if pi _
    then _
    print "This is a single-line IF from old sinclair code...":_
    border 2: _
    print "Sure!"
if pi then
    print "This is modern multiline IF"
    border 1
    print "Sure!"
end if
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Nov 22, 2017 11:24 pm

Re: End if

Well, after *SEVEN* years :oops: (sorry), what I though impossible became possible :!:

I finally achieved it. ZX Basic now allows omitting the trailing END IF for single line IF THEN sentences (like Sinclair BASIC). Moreover, it allows also ELSE in the same line. This can lead to really strange (but valid) code:
  Code:
10 IF a < b THEN LET a = a + 1: IF a < c THEN a = a + c: ELSE a = a - 1: LET c = c - 1: ELSE b = b + c

is now *VALID* and it's equivalent to:
  Code:
IF a < b THEN
   LET a = a + 1
   IF a < c THEN
       a = a + c
   ELSE
       a = a - 1
       LET c = c - 1
   END IF
ELSE
   b = b + c
END IF

The 2nd way, despite being longer, can be more readable. It's up to you

The END IF for a single-line if is now optional (so you current code is still compatible):
  Code:
10 REM lines 20 and 30 are equivalent
20 IF a < b THEN a = a + 1
30 IF a < b THEN a = a + 1: END IF
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Dec 11, 2017 2:19 pm

Re: End if

Oh wow.

What are we going to talk about in the support and bug report forums now though?
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Dec 11, 2017 7:47 pm

Re: End if

:mrgreen: :mrgreen: Haha

Well, this will be in 1.8 (about to be released).
The optimizer -O3 now has even more optimizations (really tested) and the compiler is a bit faster.
Also the plugin for VSCode is under development to enable syntax checking (syntax highlight already done). This plugin is not mine (I just made a small contribution).
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Tue Dec 12, 2017 1:37 pm

Re: End if

boriel wrote::mrgreen: :mrgreen: Haha

Well, this will be in 1.8 (about to be released).
The optimizer -O3 now has even more optimizations (really tested) and the compiler is a bit faster.
Also the plugin for VSCode is under development to enable syntax checking (syntax highlight already done). This plugin is not mine (I just made a small contribution).



You know I'm going to benchmark it... :D
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Tue Dec 12, 2017 1:50 pm

Re: End if

Also: vscode??

Visual studio? Or some other text editor?


Need to get one for sublime ;)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Dec 12, 2017 2:52 pm

Re: End if

The LSP (Language Server Protocol) is supported by VSCode, Sublime and many others.
BTW VSCode (Visual Studio Code) is open source (yes, the Visual Studio Editor) and multi-platform (Linux / Win / Mac).
Give it a try :roll:

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 0 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO