Hacker News new | ask | show | jobs
by nmz 33 days ago
> Const keyword: changing const from `local a <const> = 42` to `const a = 42` is far better syntax. The bracketed syntax was never a good idea.

The bracketed syntax is an okay idea especially for <close>, adding close as a keyword would be a disaster given how common the word is. If anything, local should have been tossed away as a keyword and the bracketed syntax adopted completely

    v <local const close>, v2 = io.open'file', false
    g <global const> = 5

5.5 introduced global which makes better use of attributes as well. of course, I don't deny how great it would be to not type <> or local const since const would already imply a local

> string interpolation

Hisham already made this nice module https://github.com/hishamhm/f-strings Which I don't dare use, even if you don't have string interpolation. Of course, I don't care because I just have a table.format(tbl, "tbl.key is %{key}"), is it a little tedious? sure, but its just a gsub call.

> short form function syntax

I disagree with this, I've always wanted it and roll my eyes as I write/create a function, especially when you like to use lots of them like

    str:gsub('%d+', (s){ tonumber(s)+1 })
> Named varargs: It may be nice, but there is no real reason to add this. If you wanted a name for your varargs you could do `local name = ...` or just use the `args` variable already available in every function.

You've made a mistake there

    local name = ...
is

    local name = ({...})[1]

In order to actually do this you need to

   local name = table.pack(...)
If you will use a vararg, you will always have to do this, so why not just let it be handled in the parameter definition? its costless. AND lua5.5 already introduced this so it seems they liked it.

Quite frankly I would like the capability of treating ... as just an array like ...[1] but I haven't looked at the parser to see if its feasible or not.

> Switch/Match/Select Statements: An optimized if/else block works just as well and another expansion of a small language.

I don't disagree, but big table of functions is so ugly, switch statements would be nice

1 comments

- Agreed on the bracketed attributes, the close attribute is very useful and devs would reach for the brackets more if they were like as you suggest. - short form fns: you and another commenter have given me good examples. I’m still not sure they are worth the complexity but I understand the use better now. - varargs true! Conceded!

Thanks for the comment! It’s helpful.