Reading a bit about Joy, I was wondering if there wasn’t an algorithm to switch from classical notation and style to concatenative and stack-based style.

Of course, for simple mathematical expressions without variables, for example, you just have to convert the expression into the inverted Polish form:

`f = 3 + 5 * (7 - 1) / 2 → f = 3 5 7 1 - * 2 / + `

But what if our function has variables? It’s easy to find ourselves the expected result when the expression is simple, like here for example:

`square(x) = x * x → square = dup * `

But for a more complex function, it becomes almost impossible to reason :

`-- This is a Haskell code qsort [] = [] qsort (x:xs) = qsort ys ++ x : qsort zs where (ys, zs) = partition (< x) xs → qsort = [small] [] [uncons [>] split] [enconcat] binrec `

(According to Wikipedia, in the page linked above.)

So, is there any way to make a computer do this kind of conversion? (Also, should the order of the arguments in a function be reversed?)

I haven’t found any algorithm on the Internet that meets these expectations. It seems to me however to have searched well. I also imagine that a conversion like the quick sort function, as shown above, would probably be more complicated to generate, but I mean: the logic behind must be the same as a more simple expression.

My goal would simply be educational, I would be interested in seeing these conversions.