1. 13
    1. 4

      I realize this is separate from the intent of the post, but the ruby one can be written even more briefly using numbered parameters:

      Old:
      { |e| e < 0 }
      
      New:
      { _1 < 0 }
      

      Ruby’s a very block/proc/lambda-oriented language so it’s no surprise they’ve got ways to write very succinct lambdas.

      1. 3

        More characters, but &:negative? is also possible (assuming this will be called with filter/reject)

        1. [Comment removed by author]

        2. 2

          Here are two ways to do it in Factor:

          [ 0 < ]
          
          [| x | 0 x > ]
          
          1. 2

            In Next Generation Shell there are few options:

            X < 0
            { A < 0 }
            F(x) x < 0
            

            The first one, X < 0, is a method call, so method(1, 2, X, 3, Y) also works. It’s same as F(x,y) method(1, 2, x, 3, y)

            Second one, { A < 0 }, is equivalent to F(A=null, B=null, C=null) ...,

            1. 2

              I’m particularly curious on any other examples people can think of, where the language supports captures. Carbon hasn’t yet specified its lambda syntax but is likely to go in that direction. cppfront uses a postfix $ for capture which is probably the most confusing part of the syntax to me, and I wish had a more in-depth tutorial explanation for the intended semantics. Otherwise there aren’t many languages with manual memory management and closures that would potentially want specified captures. Jakt doesn’t have full closures yet. FreePascal apparently now does but I don’t see documentation for this and the issue sadly isn’t linked to the merged commit.

              1. 2

                Jai does (or at least did at one point). I think Jai is still in closed beta and it’s been a couple years since I paid attention, so this info may be outdated. But as described in this link it sounds like a really nice progressive design covering a spectrum from block to function:

                https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md

              2. 2

                I don’t know Haskell, so this is an honest question. Why does the Haskell example not have any spaces while all the other examples do? The Haskell code is provided as 4 bytes:

                (<0)
                

                But should it not be written as 5 bytes with a space like so?

                (< 0)
                

                Or is this syntax error? I mean if all the other examples are going to have a space after the comparison operator/function, shouldn’t we have it for the Haskell code too?

                1. 3

                  FWIW these days almost all Haskel formatters prefer a space in between.

                  1. 2

                    I had the same question, though looking at the ones I know about, I acknowledge that they would all be idiomatically written using the spaces. I view the list as less about, “What’s the minimum possible?” and more “What does the most common usage look like?”

                    1. 2

                      No, (< 0) will be accepted fine. Perhaps there is a tiny argument to be made that Haskellers almost always write that expression without the space, but I agree that if you’re using the number of bytes as a comparison metric then this treatment is not fair.

                    2. 1

                      This is actually useful to me because someday I want to figure out a nice shortcut syntax for lambda’s in Garnet. I vaguely dislike the Rust/Ruby |x| x < 0 and have used the || for other things by now, and the rather brute-force fn(x: I32) Bool = x < 0 end I have currently is fine on its own but not especially pleasant to combine with other expressions. Having someone just sit down and make a list is really quite convenient.

                      Can you believe I’m leaning towards Haskell’s \e -> e < 0?

                      1. 1

                        Not sure if this counts as a “lambda” in K. I think they call it an implicit “bind”: (0>)

                        The regular lambda is 1 more char: {x<0}