Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

It has to be '?.(...)' not '?(...)', because '?(...)' is already part of valid syntax. For example "this.myOptionalfunction?('hello'):('goodbye')".


sort by: page size:

yes, the correct syntax would be: ./ not /.

No, it doesn't. Using a '?' will cause a syntax error.

That's not at all valid syntax, this does not work.

Nice! Pretty interesting syntax. Not sure about / for comments or the function argument syntax but you have a solid point about not using " or ' for strings!

LOL you're right! I just pasted the template here, but my defaults are equivalent to plain old `?`. I don't use the match if `?` would work.

You could use ` backticks instead and use both " and ' in strings without worry

Why can't you (or node?) use the \\?\ syntax?

There are functions starting with < and > so that's no good. And / and \ are already used elsewhere.

That's an expression, not a code block. I would not want to replace that with anything.

I think saying 'written in X' != 'has API wrappers for X' .

I started using ? as the leader (I don't do reverse searches). The other options (, \) always get in the way while programming. I might try the backtick, but it means that programming in languages that use backticks (Rust, I think) would be a pain.

How about "?????/??"?

That's awful. Can you have "<=" = "=" and "<=" = "?" but "=" ? "?"?

Not quite. This works:

     (?:(?!>).)*>?
But that is a very long winded way of writing:

     [^>]*?>
which is long way of writing:

     [^>]*>

`...` is the standard.

Don't make language features that use three-dot-ellipsis as a keyword. Just like don't make a language where "Hello world" is a special string with special significance, or where variables named foo, bar, baz, quux, or i have special meaning.

I mean, it's nobody's fault but your own if you make a language feature that breaks industry conventions.


Using 'is' and 'as' in this way is in line with C#.

You want the "?" operator.

> ?

which language does this?


To slightly elaborate on yccs27's good answer, at the moment, you can use ? for both Option<T> and Result<T, E>, but you can only use them in functions that return the same type, that is

  fn can_use_question_mark_on_option() -> Option<i32> {

  fn can_use_question_mark_on_result() -> Result<i32, ()> {
if you have them mixed in the body, they won't work directly. What you should/can do there depends on specifics. For example, if you have a function that returns Option and you have a Result inside, and you want any E to turn into None, you can add .ok() before the ? and then it still looks nice. (The compiler will even suggest this one!)
next

Legal | privacy