[Feature] Loop used with range should compile to for loop
Hi, I read your documentation and noticed that one of Amber's features is adding Shebang at the top of the compiled file.
However, in my case, it does not work.
My .ab file:
let target = "my friend"
let message = "Hello, {target}! Want some Shawarma?"
let repeated_times = 3
loop i in 0..repeated_times {
echo message
}
and my .sh file generated by amber input.ab output.sh
__0_target="my friend";
__1_message="Hello, ${__0_target}! Want some Shawarma?";
__2_repeated_times=3;
for i in $(seq 0 $(echo ${__2_repeated_times} '-' 1 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//'))
do
echo "${__1_message}"
done
Notice that there is no shebang at the top.
Is this a bug, or did I miss some information here?
Also, I think the syntax for the for-loop is not optimized, since it relies on the external command (bc). Why don't you use something like:
for ((i=0; i<repeated_times; i++)); do
...
@daoanhthanh this is fixed in https://github.com/Ph0enixKM/Amber/pull/107. Stay tuned. The optimisation features will come soon. I'll rename this issue title to be focused on the for-loop optimisation.
even tho this is fixed since #146, i still made #469 which will fix the for loop being weird