4 ms·
I almost forgot—the IF statement is an expression! You can do the following: A ← IF B = 15 THEN 40 ELSE 99 and A will be 40 if B is 15, otherwise A w
by fortran77 6y ago
I almost forgot—the IF statement is an expression! You can do the following:
A ← IF B = 15 THEN 40 ELSE 99
and A will be 40 if B is 15, otherwise A will be 99. There aren't many languages I've used that have allowed this
I need to introduce this man to the wonderful world of Haskell, Erlang, and other Functional Programming Languages.
- kgwxd 6y agoClojure: (def a (if (= b 15) 40 99)) Also: (def a (cond (= b 15) 40 (= b 20) 50 :else 99))
- KSS42 6y agoVerilog has a conditional operator ?: condition ? value_if_true : value_if_false It is used quite extensively in ASIC design.
- bluedino 6y agoAs does C, Ruby...
- jaymzcampbell 6y agoPython also lets you do this, definitley a nice bit of sugar ``` In [2]: b = 15; In [3]: a = 40 if b == 15 else 99; In [4]: a; Out[4]: 40; ```
- mattw2121 6y agoand PHP ``` $a = $b == 15 ? 40 : 99; ```
- Mountain_Skies 6y agoWhy is this desirable? It saves maybe half a dozen keystrokes in exchange for less readable and thus less maintainable code.
- jandrese 6y agoOn the 2600 if it saved you a byte or two it was a big win. Remember your program had to fit in 64 bytes of memory. Not kilobytes, single bytes. And your numbers are BCD encoded, so they're extra inefficient.
- Technically 6y agoIf expressing a conditional costs you more than 1/64 of your storage I'd say the storage is pretty useless for storing code.
- jandrese 6y agoNobody has ever accused Atari Basic of being good.
- sedatk 6y agoThat's very confusing as other BASIC dialects had used the same syntax in lieu of GOTO. `IF B = 15 THEN 40 ELSE 99` would be equivalent to `IF B = 15 THEN GOTO 40 ELSE GOTO 99`.
- 0x7755XP 6y agoIt's identical to the ternary operator (for most c like programming languages)
- bitwize 6y agoTo say nothing of Lisp. Or C with its ?: operator.
- Technically 6y agoWhat language does not have a form of a conditional expression?
- dragonwriter 6y agoIs there a popular language today that doesn't have conditional expressions?
- reaperducer 6y agoI'm not sure it's fair to compare a language from 1979 to one from "today." Especially one that fit an entire IDE into 4,096 bytes.
- dragonwriter 6y ago> I'm not sure it's fair to compare a language from 1979 to one from "today." Especially one that fit an entire IDE into 4,096 bytes. I think it is fair to treat a “not many languages I've used...” comment about a language feature from a 2015 review in the context of current (or, at least, available in 2015) languages, even if the review is of a 1979 product.