Yet another way to invoke functions without parentheses

(blog.ikaes.de)

145 points | by aragonite 3 days ago ago

38 comments

  • hans_castorp 3 hours ago

    This reminds me of "Creators admit Unix, C hoax" (e.g. https://www.gnu.org/fun/jokes/unix-hoax.html)

    > We stopped when we got a clean compile on the following syntax:

        for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);
    • nathell 2 hours ago

      How Perl was created:

      ‘Larry, throw the cat at the keyboard!’

      MEEEOW!

      ‘What did it type?’

      ‘&}Ak'>v=4%Qe}9;’

      ‘OK, so let’s make this a syntax for hello world.’

      • saghm 2 hours ago
      • bjoli an hour ago

        There was a hilarious video in The early days of YouTube when someone tried to write Perl using vistas voice recognition.

        I haven't seen it in many many years, but at the time it struck my giggle button every time.

      • nullsanity an hour ago

        I did genuinely try to run this since, well, it could be true, I don't know Perl.

        Bareword found where operator expected (Missing operator before "Ak"?) at -e line 1, near "&}Ak" Bad name after Ak' at -e line 1.

  • amelius an hour ago

    I want to put the called function after the arguments:

        (((x)f)g)h
    
    So I can see exactly the order in which things happen, from left to right. As opposed to:

        f(g(h(x)))
    
    where I have to read backwards.
    • adverbly 8 minutes ago

      That actually makes so much sense...

      When you're calling a function, you're putting some things into the function... You have to get the things first before you can put them in...

      Why didn't it evolve like that in the first place? Is it a byproduct of mathematical notation? If so, I wonder why mathematical notation evolved that way in the first place...

    • ktpsns 41 minutes ago

      Mathematica has a crazy amount of syntax abbreviations (https://reference.wolfram.com/language/guide/Syntax.html). Of course your whish is fulfilled there: x // f called the postfix operator.

    • Rohansi 26 minutes ago

      The function reference is actually evaluated first so your preferred order is actually backwards! Consider this:

        foo.bar(x)
      
      The `foo.bar` field has to be retrieved before the function can be called. It does not evaluate `x` first. That is observable with JS proxies, or you can test with code like this:

        foo()(bar())
    • danlitt an hour ago

      Do you mean (((x)h)g)f ?

      since the order in which things happen is "h first, then g, then f"

    • nine_k 16 minutes ago

      Did you even have an RPN-based calculator at school?

      As to more serious programming languages, Erlang, F#, Haskell have forms of a "pipe" operator, roughly

        [1 2 3] |> sum |> print
      
      For it to work properly, functions should be either functions of one argument, or support currying.

      But the original algebra functions, as introduced by Leibniz in 17th century, were, of course, pure functions, more like properties than procedures. So cos(x), aka cos x, is just a formalized shorthand for "cosine of x", so it preserved the order of words typical for Germanic and Romance languages. Maybe if functions were introduced by the Japanese, we would have the reverse order, kind of x の cos.

    • account42 31 minutes ago

      This is why some languages have the | pipe syntax for chaining operations.

    • raverbashing 17 minutes ago

      And that's why "purely procedural" languages don't make much sense to me

      It's more natural to write

          x.h().g().f()
    • layer8 35 minutes ago

      If `f` is an expression, that would require it to be evaluated last as well.

  • nathell 3 hours ago

    I love this. This is a fun hack, but the article also hearkens back to pre-LLM days when people were still interested in _code_.

    • bunderbunder an hour ago

      I wonder if there was a period in the 90s where the chess community was more interested in talking about IBM’s stock price than in actually playing chess.

    • stymaar 2 hours ago

      I'm definitely gonna use that for April 1st though, just adding this as instruction in Claude.md

      That will also serves as a litmus test to check how many of my coworkers are reading the code they push.

    • stigok 2 hours ago

      Programmers are still interested in code

      • cm2187 2 hours ago

        Weekend hobby!

        • mystifyingpoi 2 hours ago

          Now there is Monday again, no more coding, back to babysitting agents.

    • idkfoekfkdcjjs 34 minutes ago

      Ah yeah, here we go…

      “Back in my days…”

      “No true Scotsman…”

      “I remember when…”

      “Kids these days…”

      Gotta love this self-aggrandising humble-brag nonsensical stuff.

  • pards 3 hours ago

    Off topic: This website looks like a ransom note

    • eviks 2 hours ago

      Maybe it is, just requires a different parser

  • TheSilva 3 hours ago

      Object.prototype.message='alert\x281337\x29';Array.prototype.toString=Error.prototype.toString;Error.prepareStackTrace = Function;const x = new Error;x.valueOf=x.stack;+x;
    
    Well, that's a mouthful! So many years and JavaScript still can do the most amazing, weird, awesome, scary, obscure, and sexy things in the world of coding.
    • fg137 2 hours ago

      The prototype thing is quite unique among mainstream languages. It is kind of simple in principle and works well for what it intends to do, but god it causes so much confusion and is frequently a source of CVEs. valueOf combined with implicit conversion is a nightmare for production code.

    • customguy 2 hours ago

      Yesterday I was re-using some shaders I had written a long time ago, and here's what I used to do multiline strings before the glorious backtick arrived on the scene...

          (function () {/*
            my awesome shader code
          */}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]
      
      ... I can't call it sexy, but I also can't deny I felt a mixture of fear and arousal when I saw that.
      • h43z an hour ago

        Pretty interesting that you can carry comments over.

            (x=>/*this is a comment*/1) + 1
            "x=>/*this is a comment*/11"
        
        I wonder if anything cool can be done with it today. It's probably useless.
      • annex-winged-cr an hour ago

        TIL about [^], never seen that before. Apparently, it works like a dot but it also matches newlines.

        • gmac an hour ago

          Oh, me too. I’ve previously used [\s\S] for that.

  • CrendKing 2 hours ago

    Not gonna work on Firefox, since according to the doc, Error.prepareStackTrace is an optional API and only implemented by V8.

    • fg137 2 hours ago

      > optional API and only implemented by V8

      aka "Chrome implemented this and wanted everyone else to do so as well"

  • semiquaver 3 hours ago

    JavaScript is so cursed.

    • user____name 2 hours ago

      If I were to write a book on programming in JS, it would be a black cover with the JS Holy Trinity equality diagram in red, to emphasize its Satanic nature.

      • toolslive 20 minutes ago

        Satanic? never assume malice where incompetence suffices

  • aktenlage 3 hours ago

    What's the purpose of the +x at the end?

    • undecidabot 3 hours ago

      The unary plus implicitly converts an expression to a number, which calls `valueOf` for non-primitive values.

    • emaro 3 hours ago

      I think to implicitly trigger the valueOf function.