Skip to content

Declare variables in higher scope #166

@MichaelRFairhurst

Description

@MichaelRFairhurst

One thing I miss about dynamic programming is the ability to do

 if(...) {
     myvar = tryGettingSomething();
 }

 if(myvar) {...

And I think the static typing requirement of

var Type myvar? = nothing;

before you write your code hurts readability...

Maybe in a static world var declarations could be applied to earlier scopes with ^?

 if ... {
     ^var myvar = tryGettingSomething();
 }

 if myvar exists {...

this also ensures you can get type inference, and it would be neat if it could catch places like this:

 if ... {
     ^var myvar = tryGettingSomething();
 } else {
     ^var myvar = tryGettingSomethingElse();
 }

and automatically know that the variable isn't optional. Current wake strategy would be to do

 var myvar = ({ ->
     if ... {
         return tryGettingSomething();
     } else {
         return tryGettingSomethingElse();
     }
 })();

Have to be careful about closures and this strategy...But also nicely usable.

setCallbackOne({ v ->
    ^var myvar = v;
});

setCallbackTwo({ ->
   if myvar exists {...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions