Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In concatenative languages with an implicit stack (Factor) that expression would read:

    iter [ alive? ] filter [ id>> ] map collect
The beauty of this is that everything can be evaluated strictly left-to-right. Every single symbol. "Pipelines" in other languages are never fully left-to-right evaluated. For example, ".filter(|w| w.alive)" in the author's example requires one to switch from postfix to infix evaluation to evaluate the filter application.

The major advantage is that handling multiple streams is natural. Suppose you want to compute the dot product of two files where each line contains a float:

    fileA fileB [ lines [ str>float ] map ] bi@ [ mul ] 2map 0 [ + ] reduce


Thank you!

Because I love to practice and demonstrate Factor, this is working code for that example:

  "f1.txt" "f2.txt" [ utf8 file-lines [ string>number ] map ] bi@ vdot




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: