Live data from Hacker News

The Ultimate Conditional Syntax

dl.acm.org

41–49 of 49 posts

Re: The Ultimate Conditional Syntax

#41
post #23
post #21

Earlier quoted context omitted.

Just check out the paper's Motivaton section (2). In ML you can't write something like this: if e is ... Lit(value) and Map.find_opt(value) is Some(result) then Some(result) ... where the `...` may include many cases and may contain other Lit cases, so that you would need to refactor the whole expression. Haskell's pattern guards can do this, but they can't "split" control-flow in the middle of a case, as in: Lit(val…

PS: there's another point being made on Reddit about cond's right-shift problem: https://www.reddit.com/r/ProgrammingLanguages/comments/1g127...

Thank you. I think that I’ll need to read this again with that particular comment in mind, because that makes sense.

The limitations of Elixir syntax means it would need to be something more like:

    ucs do
      expensive() =>
        and cheap1() -> "branch 1",
        and cheap2() -> "branch 2",
      cheap3()       -> "branch 3"
    end
There are other ways around it, but it could be fun to try to build a macro in Elixir for the UCS.

Re: The Ultimate Conditional Syntax

#42

C# pattern matching gets very close. I think C# can do everything except for their last example ("splitting conditional prefixes in arbitrary places"). One of the things I miss when switching to Rust. if foo(args) == 0 then "null" |> abs > 100 then "large" That last syntax took me a while to parse in the paper, but I can imagine numerous places in our everyday code where such syntax would more concisely capture inten…

I'm wondering if you could use Roslyn to implement your snippet's syntax anyway.

Re: The Ultimate Conditional Syntax

#43
post #3

Looks very similar to lambda zero syntax ( https://github.com/clark800/lambda-zero ): def getNaturalName(tag, globals) if globals.lookup("0") is Just(Global(_, _, term)) if term is Numeral(_, type, _) return Just(Name(getTermTag(type))) error showSyntaxError("0 must be a numeral to use numerals", tag) return Void Though this ultimate conditional syntax is more general because lambda zero only allows one destructuring…

Thanks for posting this. Lambda zero looks wonderful. Is there any background information beyond the GitHub repo?

Re: The Ultimate Conditional Syntax

#45

C# pattern matching gets very close. I think C# can do everything except for their last example ("splitting conditional prefixes in arbitrary places"). One of the things I miss when switching to Rust. if foo(args) == 0 then "null" |> abs > 100 then "large" That last syntax took me a while to parse in the paper, but I can imagine numerous places in our everyday code where such syntax would more concisely capture inten…

Genuine question, as I'm not up to date with C#'s recent developments: can C# do this?

    if e is
      ...
      Lit(value)
        and Map.find_opt(value) is Some(result)
        then Some(result)
      ...
where the `...` may include many cases and may contain other Lit cases.

Or this variation:

      ...
      Lit(value)
        and Map.find_opt(value) is Some(result)
        and computation(result) is
          Left(a)  then ...
          Right(b) then ...
      ...

Re: The Ultimate Conditional Syntax

#46
post #38
post #7

Earlier quoted context omitted.

There's such a thing as too high an abstraction. Sometimes 4 different operations really are just 4 different operations and not cases of some mega-construct.

After a few years working in Haskell as a hobby, I came to the conclusion that complicated pattern matching is an antipattern. I didn't think of it this way at the time, but my current belief is that complicated pattern matching is an extremely tight coupling to what is being matched, and that's not a good thing. I'm not convinced super powerful pattern matching is even a good idea. I think a lot of the love people h…

I agree. I'm generally bearish on any language constructs that are difficult to implement. If it's difficult to implement, that probably means there are subtle edge cases that will manifest in confusing behavior at both runtime and compile time.

Re: The Ultimate Conditional Syntax

#47

C# pattern matching gets very close. I think C# can do everything except for their last example ("splitting conditional prefixes in arbitrary places"). One of the things I miss when switching to Rust. if foo(args) == 0 then "null" |> abs > 100 then "large" That last syntax took me a while to parse in the paper, but I can imagine numerous places in our everyday code where such syntax would more concisely capture inten…

Oh but C# can do even those: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Re: The Ultimate Conditional Syntax

#48
post #30

This is the ultimate conditional syntax: if (x === 1) console.log(“it’s 1”) The “if” bothers me though, be nice not to have it.

(x === 1) && console.log("it's 1") Note that you've saved exactly no keystrokes, although this is composable into expressions (if you are using some Javascript-derivative; in ML it would typically already be using the if-form).

or

x === 1 && console.log("it's 1");

Re: The Ultimate Conditional Syntax

#49
post #3

Looks very similar to lambda zero syntax ( https://github.com/clark800/lambda-zero ): def getNaturalName(tag, globals) if globals.lookup("0") is Just(Global(_, _, term)) if term is Numeral(_, type, _) return Just(Name(getTermTag(type))) error showSyntaxError("0 must be a numeral to use numerals", tag) return Void Though this ultimate conditional syntax is more general because lambda zero only allows one destructuring…

Thanks for posting this. Lambda zero looks wonderful. Is there any background information beyond the GitHub repo?

Here's a presentation on it: https://www.slideshare.net/slideshow/embed_code/key/z1PHLexD...

Note: There have been some minor changes to the language since this was made.

Post reply on HN