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

Declare a variable with type #4

Open
gogotanaka opened this issue Dec 3, 2014 · 4 comments
Open

Declare a variable with type #4

gogotanaka opened this issue Dec 3, 2014 · 4 comments

Comments

@gogotanaka
Copy link
Contributor

int i = 1
String str = "abc"
@gogotanaka
Copy link
Contributor Author

How do we freeze variable itself or check type at every reassigning?

@chancancode
Copy link
Contributor

The declaration should be trivial, we probably don't even need local_variable for that, just make def int check it's argument. As for tracking the variable, at first look it seems impossible.. Without doing source inspection, I can't even think of a way to infer the name of the instance variable from def int

But checking at declare time is probably good enough.

Can you do String str; in Java? I know you can do public String str; in a class to declare members without assigning a value, so you can probably do that in local scope too?

@gogotanaka
Copy link
Contributor Author

@chancancode Thank for adding me to the repo! I'm honored.

I agree with you. It may be impossible or need dirty hack.
Anyway I start to implement defining method with checking it's argument. After that, I think about declare a variable.

Can you do String str; in Java? I know you can do public String str; in a class to declare members without assigning a value, so you can probably do that in local scope too?

oh, you'er totally right. sorry it's my mistake ; (

@chancancode
Copy link
Contributor

Sorry if it wasn't clear (I was typing on my phone), the last point was more of a question. I just checked and answered my own question, you can indeed do all of these in Java:

String a = "abc";
String b;
int c = 1;
int d;

I suppose String b and int d would just be no-ops in the gem, but it would be quite tricky to get that work unless you method_missing everything and return :variable_declaration or something like that...

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

2 participants