Hacker News new | ask | show | jobs
by drunken_thor 37 days ago
Some of these things are already implemented in PUC Lua. I don't know why they are diverting from lua spec on other aspects though. Why not work together with the PUC Lua team to add some of these to both lua versions and work on bringing their functionality closer to each other instead of further apart. You might as well just make a new language instead. New features will end up not being used in effort to keep lua scripts portable.

In effort to not pollute the github issue, and hopes that the authors read this thread, I will put some of my thoughts here. There are 3 main strengths of Lua: Embeddable, Fast, and Small(easy to learn). I worry some of these changes divert from the last, expanding the language into a more complicated language.

Here is a list of things already implemented in PUC Lua so can be considered safe to add:

  ● ~ a     Bitwise negate
  ● a & b   Bitwise and
  ● a | b   Bitwise or
  ● a ~ b   Bitwise Xor
  ● a << b  Left-shift
  ● a >> b  Logical right-shift
  ● a // b  Floor divide
  ● break   Break statement
Don't get me wrong, I love some of these quality of life changes like:

  ● 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.
  ● nil-Coalescing and safe navigation are great additions as they are basically macros at the parsing stage.
  ● Compound assignment is also basically a macro at the parsing stage as well. Lua should already have this honestly.
  ● Ternary Operator: I *like* it and it will help the stumbling block of the `a and b or c` common pattern already in use. Though I think (like others have stated) the If/then/else syntax would be more inline with the language, similar to ruby and would enable far more emergent behaviour. However it does establish a new pattern that the last value in a block is a return value similar to ruby so I am conflicted about that.
  ● `continue` it is nicer than a goto and is helpful.
  ● String interpolation: I honestly don't love lua's concat operator `..` so honestly string interpolation would be a nice to have and a feature of many modern languages. However I do worry about it's effect on parsing performance, and complexity of the language.
  ● Underscores in numbers: *shrug*
These are great ideas for the language but I would want all lua versions to support them, not just JIT. These are things that I think are a distraction:

  ● The `and` `&&` and `or` `||`. This just goes in the wrong direction for lua. It is often confusing in ruby (especially because of precedence issues) but also lua is a wordy language. It has `do` `end` blocks instead of brackets. It adds ambiguity for no reason.
  ● Short form function syntax. Lua does not need this and I am not sure anyone asked for this. Why `a = |x| do ... end` is more helpful than just `a = function(x) ... end` is unclear and would love to hear more about why this is being considered.
  ● 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.
  ● Switch/Match/Select Statements: An optimized if/else block works just as well and another expansion of a small language.
3 comments

I asked for short form functions! Neovim has a ton of apis that accept functions as configuration. Having to write `function(x) return x > 3 end` is so much more annoying than `|x| -> x > 3`. I'd prefer just `|x| x > 3` but alas. I agree that a `|x| -> do ... end` lambda variant is redundant to normal anonymous functions though.
> You might as well just make a new language instead.

I agree. I posted this on the GitHub issues but got nothing but downvotes.

> In effort to not pollute the github issue

You should make yourself heard. It's a legitimate concern.

> 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

- 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.