QBJS v0.6.0 Release - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: QBJS, BAM, and Other BASICs (https://staging.qb64phoenix.com/forumdisplay.php?fid=50) +--- Thread: QBJS v0.6.0 Release (/showthread.php?tid=1069) |
RE: QBJS v0.6.0 Release - vince - 11-10-2022 I see it translates to a short-circuiting OR instead of a bitwise OR:
Code: (Select All) await QB.sub_Print([ 10 || 20]); temp fix: Code: (Select All) print 10 or 20 RE: QBJS v0.6.0 Release - mnrvovrfc - 11-10-2022 (11-10-2022, 01:46 PM)a740g Wrote: I have discovered that the following snippet in QBJS outputs different results compared to QB64-PE.This is always going to be a pain in BASIC only because "OR" the conditional operator was never distinguished cleanly from "OR" the logical operator. For example in C you know it's "||" for the former and a single pipe for the latter. It's distinguishable in Purebasic with the word for conditional and the symbol for logical. But for QB64(PE) and whatever made like M$'s brand of BASIC, and other such dialects, we'll have to deal with the interpreter trying to figure out what is conditional and what is logical, without it needing to be in an "IF" statement. Attempts were made, I'm sure to try to force the conditional thing only in "IF" but many programmers resisted, so it is the way it is. Anyway the solution should be use "&" for "AND" and "|" for "OR", in an example such as this one, and leave the words for conditional comparison. But it won't be done because "I can't run it in QBasic now and what am I going to do?" Another thing is that arithmetic and logic don't interlock that well because the former tends to assume base-10 while the latter is base-2, and we're trying to write everything in base-10. I ninja'ed @vince who provided a good solution. Good to know QBJS is flexible enough! EDIT: Used incorrect terms, "logical" should be "bitwise", and "conditional" might be the same as "logical" but otherwise everything here is correct. RE: QBJS v0.6.0 Release - dbox - 11-10-2022 (11-10-2022, 01:46 PM)a740g Wrote: @dbox I use QBJS to try out ideas and code that I end up using elsewhere. It is an excellent resource for me that way. Thank you. Yes, this is something I've gone back and forth on. QBasic really only has bitwise operators, where Javascript has both bitwise and logical operators. So, at present the only true bitwise operator in QBJS is XOR. All other operators are being converted to their logical equivalents in JS. I like being able to take advantage of shortcut evaluation in conditional statements, but it does present a compatibility challenge. RE: QBJS v0.6.0 Release - a740g - 11-10-2022 (11-10-2022, 03:46 PM)dbox Wrote: Yes, this is something I've gone back and forth on. QBasic really only has bitwise operators, where Javascript has both bitwise and logical operators. So, at present the only true bitwise operator in QBJS is XOR. All other operators are being converted to their logical equivalents in JS. I like being able to take advantage of shortcut evaluation in conditional statements, but it does present a compatibility challenge. Correct. We are also thinking about Boolean short-circuiting versions of AND and OR. See Boolean short-circuiting versions of ANDand OR· Issue #211 · QB64-Phoenix-Edition/QB64pe (github.com) I think you should keep the legacy functionality for AND and OR and use something else for Boolean short-circuiting versions of AND and OR (like AndAlso and OrElse). Would be nice to see this implemented in QBJS. RE: QBJS v0.6.0 Release - dbox - 11-10-2022 (11-10-2022, 04:30 PM)a740g Wrote: Correct. We are also thinking about Boolean short-circuiting versions of AND and OR. See Boolean short-circuiting versions ofANDandOR· Issue #211 · QB64-Phoenix-Edition/QB64pe (github.com) I'll definitely look into this further. The other wrinkle that makes it interesting to support is the fact that we are essentially mapping a strongly typed language onto a weakly typed one, because of this sometimes the results of bitwise operations can be... unexpected. Interesting that you are looking at adding logical operators for QB64. This is something that bit me several times a few years back when I was getting back into QB until I remembered there was no short-circuiting. Is this planned for inclusion in the next QBPE release or still in the review phase? RE: QBJS v0.6.0 Release - a740g - 11-10-2022 (11-10-2022, 06:24 PM)dbox Wrote: Interesting that you are looking at adding logical operators for QB64. This is something that bit me several times a few years back when I was getting back into QB until I remembered there was no short-circuiting. Is this planned for inclusion in the next QBPE release or still in the review phase? Review phase. We have a pile of issues to work out on the PE GitHub and some of those need to be addressed first. RE: QBJS v0.6.0 Release - CharlieJV - 11-10-2022 (11-10-2022, 01:46 PM)a740g Wrote: @dbox I use QBJS to try out ideas and code that I end up using elsewhere. It is an excellent resource for me that way. Thank you. I'm pretty sure that you'll find QBJS more compatible with QB64PE 99.9% of the time, but for the occasional oddball things that BAM can handle: BAM: RE: QBJS v0.6.0 Release - Pete - 11-10-2022 Nice to know BAM has both "OR"s in the water. Pete RE: QBJS v0.6.0 Release - Kernelpanic - 11-10-2022 A logical AND, OR and NOT would be useful. -- Regarding the binary system: does anyone know why the following program returns (Not 10) And (Not 20) a result of -31? Code: (Select All) 'Beispiel logische Operatoren, QuickBasic 4, Seite 3.10 RE: QBJS v0.6.0 Release - vince - 11-10-2022 Code: (Select All) $if Javascript then please review Steve's useful tutorial on bitwise operations https://staging.qb64phoenix.com/showthread.php?tid=305 |