Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Suggestion] constant declaration

Open CymDeveloppement opened this issue 1 year ago • 9 comments

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

CymDeveloppement avatar Jun 21 '24 08:06 CymDeveloppement

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

b1ek avatar Jun 21 '24 08:06 b1ek

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

CymDeveloppement avatar Jun 21 '24 08:06 CymDeveloppement

@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.

Ph0enixKM avatar Jun 27 '24 08:06 Ph0enixKM

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

b1ek avatar Jun 28 '24 11:06 b1ek

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
}

b1ek avatar Jun 28 '24 11:06 b1ek

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

CymDeveloppement avatar Jun 28 '24 12:06 CymDeveloppement

My proposition:

  • target is bash: use readonly syntax
  • target is sh: replace all occurrences with the constant

Ph0enixKM avatar Jul 01 '24 12:07 Ph0enixKM

i think maintain maximum of compatibility with sh is good

CymDeveloppement avatar Jul 01 '24 12:07 CymDeveloppement

Now we have @CymDeveloppement functions like shell_set can be a solution for this task?

Mte90 avatar Jul 31 '24 08:07 Mte90