Yuescript: Can YUE support empty block and some logical falsity?
Can YUE support empty block and some logical falsity?
- I hope Yue can support empty block code act as place holder for TODO and comments. Maybe we can use keyword ‘pass’ like python for this task. EX:
if os == 'win'
print 'great'
else if os == 'mac'
pass
else
-- TODO: implement
pass
- I have some personal problem with lua ‘FALSITY’. Well… when work with some other languages and yue/lua at same time, I have a tenacity to make this error: “nil and false are the only false values”. It would nice if lua behave with 0 and “” like other languages. I known I can write a function or macro to achieve this. But this make code inconvenience and look ugly. Can Yue introduce a real ‘FALSITY’ logical operator do the dirty stuff. EX:
if !val
print 'FALSE'
if !!val
print 'TRUE'
==> Lua
if not val or val == 0 or val == "" then
print 'FALSE'
end
-- if val and val ~= 0 and val ~= "" then
-- or
if not (not val or val == 0 or val == "") then
print 'TRUE'
end
- Support nullish coalescing operator like other modern languages. Maybe we can use ‘??’ op like javascript, C#. EX:
valA = nullValue ?? "default for A"
valB ??= "default for B"
==> Lua
local valA
if nullValue ~= nil then
valA = "default for A"
end
local valB
if valB ~= nil then
valB = "default for B"
end
Thanks and regards!
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 21 (8 by maintainers)
Commits related to this issue
- partially fix issue #69, fix a few case the generated code leaks some temp variables. — committed to pigpigyyy/Yuescript by pigpigyyy 3 years ago
- try to fix issue #69 with new macro functions. add builtin macro $MODULE and $LINE. — committed to pigpigyyy/Yuescript by pigpigyyy 3 years ago
- fix an indent issue. add more macro specs. fixing issue #69. — committed to pigpigyyy/Yuescript by pigpigyyy 3 years ago
It won’t be hard to get all the functions implemented. Just wanted to show that anyone can extend this language at will without even touching the source code.
You need to add a nil at the end of the code. Or the
<- $skipmacro will be treated as the last expression to be implicitly returned. So this example should be:Wouldn’t it be much easier to read if you just had a
passinstruction?