Ph0enixKM / Amber

💎 Amber the programming language compiled to bash
https://amber-lang.com
GNU General Public License v3.0
3.51k stars 67 forks source link

[Suggestion] constant declaration #233

Open CymDeveloppement opened 1 week ago

CymDeveloppement commented 1 week ago

I work on a colored text function but color code in bash is not explicit

fun text(message: Text, color: Num, style: Num) {
    unsafe $echo -e "\e[{style as Text};{color as Text}m{message}\e[0m"$
}

text("test", 32, 3)

this output italic green text. i think is more comprehensive if we can write :

text("test", _bash_foreground_green_, _bash_italic_)

maybe in future external lib can declare constant

b1ek commented 1 week ago

im confused. is this about creating a const keyword or about helping with your code?

CymDeveloppement commented 1 week ago

Sorry is about creating a const keyword, my code work fine

Ph0enixKM commented 2 days ago

@CymDeveloppement so you propose to introduce constants. I don't see any reason not to do add it to Amber. Not that much important for now though. I'll mark it as a Stable Release issue.

b1ek commented 1 day ago

this should be implemented as the let keyword, but locks the future variable changes

b1ek commented 1 day ago

i would propose this being implemented as a function that is called each time the value is retrieved - it ensures runtime safety as well as compile checks

const FIVE = 5
const_FIVE() {
    return 5
}
CymDeveloppement commented 1 day ago

it depend if it must be accessible from bash, If no, compiler can just replace all occurence of five constant by 5

but in bash function is not a constant, this script :

function test__0_v0 {
    echo "OK"
};
test__0_v0 ;
__AMBER_FUN_test0_v0__6=${__AMBER_FUN_test0_v0};
echo ${__AMBER_FUN_test0_v0__6} > /dev/null 2>&1

function test__0_v0 {
    echo "OK2"
};
test__0_v0 ;

output :

OK
OK2

in bash constant can be declared with readonly five=5