Mirah Scoping and control structures
If statements don't introduce a new scope, like ruby, but they are a little tricky.
For example, if
b is false in the following, what would
if b a = 1 end puts a
In some dynamic languages,
a would be
undefined, but Mirah can't do that. It's a staticly typed language without an undefined value. Mirah's options are either make
0 (aka default int val) or consider the above a compiler error.
In addition to values, Mirah, as a staticly typed language, must* give
a a type. Ideally, we'd use primitives wherever possible. But, if you have an expression like this, that would force
a to equal
0, which in my opinion is worse than anything.
if b a = 1 else a = 2 end puts a
Super cool would be to figure out that
a can be primitive.
a = 1 begin raise "wut" rescue => a end puts a
Due to types, this should be a compile error. A's assigned
begin raise "wut" rescue b = 1 end puts b
b should be
begin ; rescue => e; end puts e
following Ruby's behavior, this should print
null, but this would introduce interesting behavior in the following.
begin ; rescue Ex1 => e; e.ex1_msg; end begin ; rescue Ex1 => e; e.ex1_msg; end begin ; rescue Ex2 => e; e.ex2_msg; end
e is the same e for each rescue, then the above will be a compile error. :sadface:
And what about
begin # cool stuff that might blow up rescue Ex1 => e # handle Ex1 rescue Ex2 => e # handle Ex2 end
begin # cool stuff that might blow up rescue Ex1 => e # handle Ex1 rescue Ex2 => e # handle Ex2 end puts e
These should be true regardless of whether the block is a macro block or a closure.
Argument variables should only live inside the block.
[1, 2, 3].each do |i| end puts i
compile error on
Argument variables that shadow outer variables, could be a warning, but shouldn't be considered the same variable.
i = "cool beginnings" [1, 2, 3].each do |i| end puts i
Variables that are defined in blocks should not be referenceable outside the block.
[1, 2, 3].each do x = 1 end puts x
compile error on