[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [bug?] = doesn't work properly
- From: Martin <eden_martin_fuhrspam@...>
- Date: Sun, 30 Apr 2017 22:46:46 -0700
On 04/30/2017 09:04 AM, Soni L. wrote:
> The fix is to allow an = to be used as `return` in the parser, if it's
> the first statement in a function. This'll be a huge improvement for Lua
> data files:
>
> = {
> nick = "Soni|Bot",
> network = "irc.freenode.net",
> port = 6667,
> }
>
> while also fixing the bug in the interpreter.
>
> Side effects include `local function swap(a,b) = b,a end`,
> `s:gsub("[A-Z]", function(k) = tostring(k:byte()) end)`, etc. But I
> think those are nice.
Code will become more obscure from this change. I prefer stable habits
like "use `return` anytime you wish to leave current scope and return
values". But this may be done, yes.
--
I'd wish another feature: treat statements as expressions.
(Because sometimes I'm tired from building logic bottom-up when I see a
way to describe it top-down.)
Then some code like this will become valid:
local result =
do
local s = 'some text'
return s
end .. '!'
print(result)
Today you can implement this behavior as anonymous function call:
local result =
(
function()
local s = 'some text'
return s
end
)() .. '!'
print(result)
which looks less nice.
--
> $ lua
> Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
>> =1
> 1
>> =1
> stdin:1: unexpected symbol near '='
It's strange for me why "=1" is valid in interpreter. I consider this as
a glitch and tend to ignore this feature.
-- Martin