4 ms·
Shell is so much not functional. Most shells don't even have proper functions. And while pipes resemble function composition to some extent, you have side-effec
by oweiler 9y ago
Shell is so much not functional. Most shells don't even have proper functions. And while pipes resemble function composition to some extent, you have side-effects and mutations everywhere.
- chatmasta 9y agoAgreed. Hence why I said “loosely functional” (you could say the same about JS). For both languages you can write code as functional or non functional as you want. Input/output redirection (pipes), IMO, could qualify as functional programming just as JS promise chaining could.
- chubot 9y agoIf you think of stdin and stdout as your function inputs and outputs, then shell becomes very functional: Pipelines Support Vectorized, Point-Free, and Imperative Style http://www.oilshell.org/blog/2017/01/15.html http://www.oilshell.org/blog/2017/01/15.html In a sense, a shell can only return an exit code. But it's better to think of that as an error handling mechanism rather than the return value, much like in C. In C, it's idiomatic for functions to return values with "out params" (i.e. a dynamically allocated a string). Just like you can write C code that composes, you can also write shell code that composes. And in many ways it composes better than code in other languages.