Why is a trailing comma in a cell array valid Matlab syntax?

后端 未结 3 572
囚心锁ツ
囚心锁ツ 2021-02-05 09:36

I was surprised today to discover that

A = {1,2,3}

and

B = {1,2,3,}

are both valid syntax in MATLAB. I would

3条回答
  •  执笔经年
    2021-02-05 10:33

    It's convenient to allow trailing punctuation in languages if ever the code is going to be generated from other code.

    For example, Lua allows trailing commas, so it's easy to generate Lua code.

    You don't have to have a special case in the generating code to omit the final comma, you can just print ITEM-THEN-COMMA for each and every item.

提交回复
热议问题