News for hackers. Stuff that matters.
Re:Elvish – An experimental Unix shell in Go by e12e on Sunday July 27, 2014 @03:32AM (#8092217)
This is equivalent to the following bash incantation?:

    cat <<eof\
     | while read a;do if [[ $a -gt 2 ]];then echo $a;fi; done \
     |while read b;do echo $((b*2));done
    1
    2
    3
    4
    5
    eof
(Better expressed with seq):

    seq 5 \
    | while read a;do if [[ $a -gt 2 ]];then echo $a;fi; done \
    | while read b;do echo $((b*2));done
But we can do (a little) better:

    # Ok, this is a bit odd, the filter is actually inverse...
    filter()
    {
        while read it
        do
          #NOT SAFE!!
          if eval ${*}
          then
            echo "${it}"
          fi
        done
    }

    map()
    {
        while read it
        do
          #NOT SAFE!!
          eval ${*}
          echo "${it}"
        done
    }

    #Valid bash:
    seq 5 \
    | filter test '$it' -gt 2 \
    | map 'it=$((it*2))'
Sorry, didn't mean to turn this into stack overflow, the "simple" syntax just tickled me...

There are no comments on this comment yet.