

Functional programming, APL and UNIX pipes - philh
http://porg.es/blog/functional-programming-apl-and-unix-pipes

======
jacquesm
I noticed the parallel between pipes and functions only a few weeks ago and it
struck me that if you re-write lisp expressions left to right instead of
'inside out' I can suddenly understand much better what is going on.

so if I look at f(b(c(d(e))))) it is the same as 'cat e | d | c | b | f'

Where 'e' is the initial input data and the other letters are the functions
transforming e in successive steps to the desired output.

The analogy probably breaks down pretty quickly, but for simple examples it
seems to hold.

Is there a programming language that works in this left-to-right pipelined
fashion?

~~~
dkersten
Yes, concatenative languages. Check out Factor[1] or Forth[2], for example.

[1] <http://www.factorcode.org/>

[2] <http://thinking-forth.sourceforge.net/>

~~~
jacquesm
Funny you should mention forth, I never even thought of forth that way (I did
some forth long ago), but I can see the parallel, with the stack being the
'intermediate' that gets passed from function to function.

Never heard of 'factor' yet, I'll have a look at it.

Thanks!

~~~
dkersten
Factor is interesting, because it tries to be Lisp in concatentive form.
Because of this, it has a lot of interesting and powerful abstractions that
make you rely on the order of the stack a lot lot less (as they like to say
_idiomatic factor doesnt use the stack_ and _Factor has more in common with
Lisp than with Forth_ ). Its well worth a try, though its got a pretty steep
learning curve.

~~~
gruseom
What's Factor's approach to macros?

~~~
Avshalom
EDIT: whether anything I say below is actually true, making new syntax is
totally supported in Factor both in the language and in the community.

[http://factor-language.blogspot.com/2009/09/survey-of-
domain...](http://factor-language.blogspot.com/2009/09/survey-of-domain-
specific-languages-in.html)

pretty much the same as lisp's. MACRO: defines a lisp style macro,
[http://docs.factorcode.org/content/word-
MACRO__colon__%2Cmac...](http://docs.factorcode.org/content/word-
MACRO__colon__%2Cmacros.html) (MACRO:: defines a macro with local variables)

SYNTAX: defines a 'parsing word' [http://docs.factorcode.org/content/article-
parsing-words.htm...](http://docs.factorcode.org/content/article-parsing-
words.html) which I think is basically the same as a lisp Reader Macro

Though you don't seem to need macros very often because you tend to pass
things around as lambdas, cond for instance is implemented as a normal
function.

~~~
dkersten
One commonly used parsing word is INFIX: which, as you would expect from the
name, allows you to write equations in infix notation rather than the default
postfix. Macros work exactly like someone familiar with lisp would expect them
to.

