
Ask HN: Are there any languages where the function comes after the argument? - maest
So a language where function application looks like:<p><pre><code>  arg function
</code></pre>
That way, one can chain data transformations in a fairly natural way:<p><pre><code>  my_data transformation1 transformation2
</code></pre>
I&#x27;m not sure if this is a minor or major change to a language syntax and I&#x27;m curious if anyone&#x27;s ever tried it.<p>I don&#x27;t see any particularly compelling reasons why function application is done as<p><pre><code>  foo(arg)
</code></pre>
in virtually all languages. My guess is that this is inherited from conventions in mathematics.
======
fnordsensei
Lisps are not in this camp by default, but in Clojure it's idiomatic to use
the threading function to achieve a similar effect. For example,

    
    
      (inc (inc (inc 1)))
    

can be written

    
    
      (-> 1 inc inc inc)
    

(`inc` increments a number by one)

There are also several languages that allow method chaining. I.e.,

    
    
      thing.inc().inc().inc()

------
db48x
This is called Reverse Polish Notation. Forth uses it, as do a few other
interesting languages.

------
paulrpotts
Sure - they are called stack-based or concatenative languages (although they
don't actually have to use stacks for implementation):

[https://en.wikipedia.org/wiki/Stack-
oriented_programming](https://en.wikipedia.org/wiki/Stack-
oriented_programming)

The historically interesting/successful ones are mainly Forth and PostScript,
but there are some successors of interest such as Joy.

------
rhizome31
Shell pipes are like this. Elixir took inspiration from it for its |>
operator, although it works only for the first argument. You should check it
out!

------
bjourne
Factor works like that. It's dynamically typed and meta-programmable like Lisp
and uses a global stack like Forth to pass data. By writing everything
"backwards" (x) you get a syntax that is much more regular than what is
possible in languages with Algol-like or even Lisp-like syntax. The language
website is here [https://factorcode.org/](https://factorcode.org/) It has a
lot more code samples.

x - Of course, what is "backwards" and what is "forwards" is up to the reader.
I'd argue that foo(arg) is backwards because we think of the expression as
"arg processed by foo" Since arg comes before foo, it should be placed to the
left of foo in the syntax.

------
0_gravitas
Elixir has the pipe notation, which is somewhat similar

