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

[Feature] Declaring empty variables #420

Open
DJMoffinz opened this issue Aug 23, 2024 · 5 comments · May be fixed by #432
Open

[Feature] Declaring empty variables #420

DJMoffinz opened this issue Aug 23, 2024 · 5 comments · May be fixed by #432
Assignees
Labels
enhancement New feature or request

Comments

@DJMoffinz
Copy link

Is your feature request related to a problem? Please describe.

In bash, it is possible to declare an empty variable, like so:

#!/usr/bin/env bash

declare foo
foo="bar"
echo "$foo"

Outputs:

bar

However, this functionality is not present in Amber:

main {
     let foo
     foo = "bar"
     echo foo
}

Outputs:

 ERROR  Expected '=' after variable name 'foo'
at empty.ab:3:6

2|      let foo
3|      foo = "bar"
4|      echo foo

Describe the solution you’d like

Simply, compile let foo to declare foo.

Additionally, declare is useful for enforcing variable type, as demonstrated in this stackexchange answer. This could be written in Amber as let foo = Text.

Describe alternatives you’ve considered

I suppose writing let foo = "" would suffice, but my proposed solution implements more bash functionality and allows for cleaner Amber code.

@DJMoffinz DJMoffinz added the enhancement New feature or request label Aug 23, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Amber Project Aug 23, 2024
@Ph0enixKM
Copy link
Member

How about:

let foo: Text
// And also
let foo: Text = "Some value"

@DJMoffinz
Copy link
Author

DJMoffinz commented Aug 23, 2024

That looks even better
Although, I realised after opening this issue that declare really only has type enforcing for integers and arrays lol
The other flags are for really specific stuff

@b1ek
Copy link
Member

b1ek commented Aug 24, 2024

it should also throw a compile error if the user tries to read from it before it was assigned

@b1ek b1ek self-assigned this Aug 26, 2024
@b1ek b1ek linked a pull request Aug 31, 2024 that will close this issue
@Ph0enixKM
Copy link
Member

I don't think this issue brings in any useful value. What would be the biggest benefit of the ability to declare a variable without it's default value? I think that this feature makes sense only when we introduce more advanced data types. If you agree I'll close this issue for now. It can be always reopened

@b1ek
Copy link
Member

b1ek commented Dec 22, 2024

@DJMoffinz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants