3 ms·
This would really make for a great exception operator, for one-liner exception handling. (alert(null) ‽ console.log(error)); Better than: (x === null ? c
by hurpaDurpa 8y ago
This would really make for a great exception operator, for one-liner exception handling.
(alert(null) ‽ console.log(error));
Better than:
(x === null ? console.log(error) : alert(x));
EDIT: hey downvotes, let's play funny/not funny.
- Jarred 8y agoalternatively: // Would run console.error with the Error object (alert(x) ?: console.error);
- lifthrasiir 8y agoThis is indeed a form supported by GNU C extension [1] (but `?:` is not a single token, so `? :` is permitted). [1] https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditi...
- azernik 8y agoYou may know this, but others may not: this is an actual thing, and is called the Elvis Operator (think the hair). https://en.wikipedia.org/wiki/Elvis_operator https://en.wikipedia.org/wiki/Elvis_operator Shockingly, this is actually accepted by GCC's C dialect! And PHP! By the simple implementation expedient of making the second operand of the ternary operator optional.
- snarfy 8y agoI can't seem to find the ‽ key on my keyboard.
- hurpaDurpa 8y agoWell, obviously, the compiler could also interpret the consecutive use of each of the two distinct characters question mark (?) and exclamation point (!). But it would have to tolerate both options to remain convenient (?! and !? have the same effect). Meanwhile the interrobang (‽) would really be an Easter egg.
- simcop2387 8y agomost languages wouldn't work properly with ?! as that could be already valid (unary ! operator meaning not, and ? being used for the ternay operator). So you can't distinguish between: foo ?!bar : baz and an interrobang like operator. !? on the otherhand is likely to already be invalid and be parseable as an interrobang since it wouldn't already be valid to have a ? immediately following a ! in many languages. Having both work might be nice, but is likely impracticle for backwards compatibility.
- empath75 8y agoWith ligatures you can just use ?! and make it look that way.
- opnitro 8y agoRacket doesn't seem to mind using λ despite it not being on the keyboard. I find it more convenient to remember a hotkey than to type `lambda`
- taneq 8y agoYou can't‽ But it's right there‽
- ars 8y agoAPL would like to have a word: https://en.wikipedia.org/wiki/APL_(codepage) https://en.wikipedia.org/wiki/APL_(codepage)
- Symbiote 8y agoOn Linux with the Compose key enabled, it's Compose, !, ?. https://en.wikipedia.org/wiki/Compose_key https://en.wikipedia.org/wiki/Compose_key
- justinator 8y agoDo you really want to give Larry Wall any more ideas‽