Some interesting notes about VBScript, bundled with examples.
Speaking of VBScript, notice that Beyond JS has a new version, with lazy lists and such.
In any serious language, the statements:
(define (foo) (display "foo") (newline) #t)
(define (bar) (display "bar") (newline) #f)
(and (bar) (foo))
will result in only "bar" being printed (and #f being returned), and
(or (foo) (bar))
will result in only "foo" being printed, as the boolean false that bar returns makes further execution useless (as does the boolean true that foo returns for the or statement).
Not so in VBScript.
in a series of statements in the form
s1 and s2 and s3
or
s1 or s2 or s3
VBscript evaluates all of these statemens, and then decides whether they are true or false. How very efficient (not to mention functions with side effects, as I have used in the examples above)!
BUT the logic clause doesn't even have to have (much of) a side effect for VBScript to get annoying.
You can't do this in VBScript because both sides are evaluated:
if (not cint(x)) or (cint(x) = 0) then Some default case where we treat x as 0 else X is a number, do something end if
You can rewrite the code in any number of ways, but that sort of thing still gets me because I'm more used to C programming.
BTW being a co-author of Beyond JS, I really would like you guys to check it out. Sjoerd and I have been working hard in our spare time to create a library that merges both OO and Functional programming. At the very least, you should find interesting ideas and cool JavaScript code. Any feedback would be most welcome.
If the logical operators are handled as regular functions (overloading), this means you can not ensure short circut evaluation.
I prefer the approach of having special operators for short circut evaluation. BTW, Ada has them to: "and them" / "or else". Now you should use these when you depend on short circut semantics, or else..
I was talking with some friends of mine in the C++ course (which I skipped) and they were doing a section on operator overloading for classes.
The assignment was to make a Boolean class and overload the appropriate operators so that it behaved as you would expect.
Ugh! When you overload the logic operators in C++ it turns off short-circuit.