|
Post by Pjot on Feb 5, 2011 13:45:08 GMT 1
Folks, Now BaCon has genuine BASIC comparison syntax for both numbers and strings, in addition to the existing ways of comparison. It will be available from build 21. Number comparison current way: a = 10 IF a EQ 10 THEN PRINT "Success" IF a NE 10 THEN PRINT "Failed"
Number comparison new way: a = 10 IF a = 10 THEN PRINT "Success" IF a != 10 THEN PRINT "Failed"
String comparison current way: a$ = "Hello" b$ = "World" IF EQUAL(a$, b$) THEN PRINT "Success" IF NOT(EQUAL(a$, b$)) THEN PRINT "Failed"
String comparison new way: a$ = "Hello" b$ = "World" IF a$ = b$ THEN PRINT "Success" IF a$ != b$ THEN PRINT "Failed"
Of course this syntax also works for REPEAT/UNTIL and WHILE/WEND and handles combinations with AND and OR. And as usual OPTION COMPARE determines case sensitive comparison in case of strings. Regards Peter
|
|
ffweb
New Member
Posts: 20
|
Post by ffweb on Feb 7, 2011 14:42:25 GMT 1
Very nice!
|
|
|
Post by Pjot on Feb 8, 2011 15:16:46 GMT 1
Thanks, and with this new feature I have discovered an illegal IF construct in the HUG include file - shame on me! It is corrected in version 0.31. Regards Peter
|
|
|
Post by barryk on Mar 10, 2011 15:01:08 GMT 1
Um, I think that this is a reasonable request....
I like using EQ, NE, GT, LT, GE, LE rather than =, !=, >, <, >=, <=.
I tested, for numbers you can now use either, but not so for strings.
as strings now allow the normal comparison operators, is there any particular reason why not the comparison letters alternative could also be allowed?
For example:
IF str1$ EQ str2$ THEN
Regards, Barry Kauler
|
|
|
Post by Pjot on Mar 10, 2011 19:34:36 GMT 1
You have been programming with BASH too much The idea of BaCon was inspired by the good old Commodore VIC-20/C64 BASIC. In those BASIC's one uses the plain '=><' symbols for comparison, both for numbers and strings. However, as BaCon passes equations and expressions directly to the C compiler, it had to use some kind of alias for the '==' and '!=' constructs. As a workaround these aliases became the 'EQ', 'NE', 'IS' and 'ISNOT' keywords, but these are very unlike real BASIC. I have received many critical comments from BASIC users in the past about these. But while insight and knowledge on text parsing progresses, I was able to get around this limitation and setup more BASIC like comparison syntax. Therefore, I would say that 'NE', 'EQ', 'ISNOT' and 'IS' are strongly discouraged and obsolete by now. But they will remain in BaCon for backwards comptibility (I don't want to break Holy Rule no1 of breaking the API). Regards Peter
|
|
aurel
Junior Member
SolarMM
Posts: 61
|
Post by aurel on Apr 28, 2011 20:38:15 GMT 1
Hi... I almost forget for this place... And i must say that i really like clean & clear syntax of BaCon
|
|