Skip to content

Declare a variable with type #4

Open

Description

@gogotanaka
int i = 1
String str = "abc"

Activity

  1. gogotanaka commented on Dec 3, 2014

    @gogotanaka
    ContributorAuthor

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

  2. chancancode commented on Dec 3, 2014

    @chancancode
    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?

  3. gogotanaka commented on Dec 3, 2014

    @gogotanaka
    ContributorAuthor

    @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 ; (

  4. chancancode commented on Dec 3, 2014

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions