Open avierr opened 5 years ago
Hi @avierr, we should collaborate ;)
There's a couple of things you could do:
function run() {
local -i i=0
local -i z=0
function extractedWhile() {
echo "$i"
i=$(($i + 1))
local -i z="$i"
}
while (($i < 10)); do
extractedWhile
done
echo "z is $z"
}
run
Works as in JavaScript and outputs:
0
1
2
3
4
5
6
7
8
9
z is 0
z
local to a non-conflicting variable consistently within that scope:function run() {
local -i i=0
local -i z=0
local -i _z
while (($i < 10)); do
echo "$i"
i=$(($i + 1))
_z="$i"
done
echo "z is $z"
}
run
Some inspiring reading & tools here:
I have been working on a transpiler myself and came across this repo today. The specification in the README gives me some really good ideas! Thanks!
I am stuck at a point on how to implement variable scopes like:
at the moment, translates to:
Let me know if you have any good idea for implementing scopes. Here is the one that I am working on https://github.com/evnix/BashType (very much a work in progress and the reason for building it exactly the same as yours 😛)