Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] constant declaration #233

Open
CymDeveloppement opened this issue Jun 21, 2024 · 9 comments · May be fixed by #423
Open

[Suggestion] constant declaration #233

CymDeveloppement opened this issue Jun 21, 2024 · 9 comments · May be fixed by #423
Assignees
Labels

Comments

@CymDeveloppement
Copy link
Member

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
Copy link
Member

b1ek commented Jun 21, 2024

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

@CymDeveloppement
Copy link
Member Author

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

@Ph0enixKM
Copy link
Member

Ph0enixKM commented Jun 27, 2024

@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 Ph0enixKM added this to the Stable release milestone Jun 27, 2024
@b1ek b1ek added enhancement New feature or request feature proposal labels Jun 28, 2024
@b1ek
Copy link
Member

b1ek commented Jun 28, 2024

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

@b1ek
Copy link
Member

b1ek commented Jun 28, 2024

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
Copy link
Member Author

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

@Ph0enixKM
Copy link
Member

Ph0enixKM commented Jul 1, 2024

My proposition:

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

@CymDeveloppement
Copy link
Member Author

i think maintain maximum of compatibility with sh is good

@Mte90 Mte90 added the syntax label Jul 19, 2024
@Mte90
Copy link
Member

Mte90 commented Jul 31, 2024

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

@b1ek b1ek self-assigned this Aug 25, 2024
@Mte90 Mte90 linked a pull request Aug 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants