Re:Elvish – An experimental Unix shell in Go
by zokier on Saturday July 26, 2014 @05:11PM
(#8090812)
It would be nice if
could be written just as
[ Parent
| on HN ]
can you express that grammar in ebnf? I think the parser would need to be at least ll(C) where C is bigger than 1.
Would the presence of $_ denote a lambda? how would nested lambda's work?
Why not:
put 1 2 3 4 5 | filter -> > $1 2 | map -> * 2 $1
I think that would be easier to parse, and not much typing overhead, also $_ is a weird thing.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...Some languages have a sort-of default variable name for cases like this, namely "it":
> put 1 2 3 4 5 | filter > $it 2 | map * 2 $it
As zokier was presumably pointing out, other languages have a different sort-of-default variable name, namely `$_` (http://c2.com/cgi/wiki?DollarUnderscore). :-)