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

Question about variable affectation #7

Open
batiste opened this issue Mar 17, 2016 · 3 comments
Open

Question about variable affectation #7

batiste opened this issue Mar 17, 2016 · 3 comments

Comments

@batiste
Copy link

batiste commented Mar 17, 2016

Hi,

As I new comer here is my first reaction to the syntax:

counter: int = 0;

Oki fair enough. It seems that a colon is used to define new variables... Oki I think I get it.

counter := 0;

Wait a minute, now the colon seems to be part of ":=" pair... What does this mean. It seem colon as a contextual meaning. Is counter: = 0; equivalent? This is confusing.

counter: int;

Yet another syntax to remember.

Do we really need a colon here? Is it to express a new variable declaration or assign a type explicitly? I think the use of it in this first example is confusing... Can't we just remove it entirely?

Just saying that having a confusing syntax as a first example is off putting.

@refi64
Copy link

refi64 commented Mar 17, 2016

The := is just to represent that the type is inferred. Like a: auto = b;.

a: int and a: int = 0 are the same, but the latter initializes it with a default value. Like int a vs int a = 0.

@BSVino
Copy link
Owner

BSVino commented Mar 19, 2016

What Ryan (kirbyfan64) said is true. Here's another attempt at explanation.

The name of the variable always comes first. The colon denotes the type of the variable, and the = denotes an assignment to a value. So, name : type = value;. Sometimes the type can be inferred from the assignment, and in those cases the type is omitted and it looks like name := value;. Like Ryan said, that would be the same as name : auto = value; If you don't want to assign a particular value, you can omit the assignment: name : type;. I think Jai will still initialize it to 0 in that case though, and you have to do something like name : type = ---; to avoid initialization at all.

@TheLoneWolfling
Copy link

The current readme doesn't sell ':=' for me at all.

It seems to map essentially 1:1 with the existing C++ approach.

a := b -> 'auto a = b a : t->t a`

...so what are the advantages?

I like the explicit uninitialized value... but that could be a simple extension to the C++ approach.

It seems to me that this is trying to mimic a more functional style... but that is weird for a language that's supposedly C-style.

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

No branches or pull requests

4 participants