moonscript
moonscript copied to clipboard
Overwriting _
{a,b,_} = {1,2,3}
1
2
compiles to
local a, b, _
do
local _obj_0 = {
1,
2,
3
}
a, b, _ = _obj_0[1], _obj_0[2], _obj_0[3]
end
_ = 1
return 2
_: f*ck, I got overwritten!
Is this because you've like to actually use the _ variable? MoonScript typically treats it as a placeholder, but it's an unwritten rule that you should avoid reading from it.
I prefer to use _ as a placeholder.
I just want to say that if _ can be overwritten, moonscript might not have a safe scoping system.
Some people prefer to use _ for utilities like this one: https://github.com/Yonaba/Moses
I can think of 3 solutions.
- Change
_into a long name like_moonscript_<checksum> - Ban the usage of writing a single value on one line
- Ignore these lines (like comments)
I think MoonScript should use its own variable name as a placeholder instead of _ to get around this potentially causing problems.
I would tend to disagree with the need for the change, but if a newbie is coming along who doesn't understand the tradition to use _ only as a placeholder, this makes it even harder for them to get into programming, which is hard enough as it is. :P
If that's of anything interest, a similar discussion was had in a CoffeeScript fork with a feature similar to moon's with:
https://github.com/satyr/coco/issues/181 https://github.com/satyr/coco/issues/90