Ontology of Postfix Notation, Method Chaining, and Unix Pipe
i just took 30 min walk and thought about this problem i had in mind vaguely for years. And, i have obtained clarity. I want to type it out here quickly as a record.
you know, how unix pipe can be considered as a postfix notation. For example,
a | b | c.
[see Unix Pipe as Functional Language]
now, Wolfram Language has a postfix operator. That is double slashes,
a // b // c is equivalent to
c[b[a]], or to normal programing language notation of
[see Concepts and Confusions of Prefix, Infix, Postfix and Lisp Notations]
[see OOP Dot Notation, Dot Before Data or After?]
they are all postfix notation of some sort, but exactly what's the aspect, context, nuances? That is, i want to know the ontology.
[see What's Ontology of Programing Language?]
so, walking and talking to myself, now i obtained clarity.
basically, the central thing we are interested is applying function sequentially, and a notation for it that's linear without nesting.
why do we want this? because:
- a linear notation is convenient to write. With nested notation such as
(c (b (a))), you have to go to beginning and end back and forth for each new function.
- a linear notation is easy to read. With nested notation you have to dig into the inner most term first. Gets complex when function names themselves are nested expressions.
now, what's the deal with these terminologies: “postfix notation”, “unix pipe”, “method chaining”? in what way, aspect, or context, are they same or different?
now, the different terminologies emphasize different aspects or context. For example, “postfix notation” emphasize math background. Unix never called their pipe as “chaining function” or postfix notation, but again, it's just because the background and perspective are different. Unix shell called it pipe because the focus is on passing data around, as water flows thru a pipe. Similarly, math postfix notation isn't called piping, nor called method chaining. In math, which began as writting symbols on paper, with concepts of functions and operators, thus postfix notation.
one may still feel that we are forcing onto disparate things.
To unify them, we can define a operator as postfix operator. The essence is that, it is left-side associative. That is,
a + b + c
(a + b) + c
a + (b + c).
(when we have
a . b
where the dot is a
written in function form it would be
and the semantic of the function is to take its second arg as function and apply it to the first arg, that is
So, in Wolfram Language, the
// is a postfix operator.
In unix shell, the
| is a operator, and indeed it satisfies our postfix definition
be a operator, and it also satisfies our postfix definition.
ontolog! clarity obtained!
a . b, the
a may just be a namespace, not object nor data. e.g.