Hacker News new | ask | show | jobs
by hurpaDurpa 2906 days 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.
3 comments

Do you really want to give Larry Wall any more ideas‽
I can't seem to find the ‽ key on my keyboard.
APL would like to have a word: https://en.wikipedia.org/wiki/APL_(codepage)
On Linux with the Compose key enabled, it's Compose, !, ?.

https://en.wikipedia.org/wiki/Compose_key

Well, 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.

most 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.
You can't‽ But it's right there‽
With ligatures you can just use ?! and make it look that way.
Racket 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`
alternatively:

  // Would run console.error with the Error object
  (alert(x) ?: console.error);
You 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

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.

This 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#Conditi...