News for hackers. Stuff that matters.
Re:Functional programming in sh by ralph on Thursday May 24, 2012 @04:49AM (#4017458)
The shell gives this kind of behaviour already through pipes and commands like awk, sed, and dc. More natural translations of the calculations given might be

    $ seq 100 | awk '{s += $0} END {print s}'
    5050
    $ seq 20 | awk -v s=1 '{s *= $0} END {print s}'
    2432902008176640000
    $ seq 5 | awk -v s=1 '{s *= $0} END {print s}'
    120
    $ seq 3 |
    > awk -v s=1 '{s *= $0} END {print s}' |
    > xargs seq |
    > awk '{s += $0} END {print s}' |
    > md5sum
    fe9d26c3e620eeb69bd166c8be89fb8f  -
    $ seq 400 500 | awk '{s += $0} END {print s}'
    45450
    $

There are no comments on this comment yet.