为什么lua阵(表)1而不是0开始? [英] Why do Lua arrays(tables) start at 1 instead of 0?
问题描述
我不明白的Lua这一部分的决定背后的理性。为什么索引从1开始?我已阅读(许多其他一样)这个伟大的纸。在我看来,这是非常愉快的学习和编程语言的一个奇怪的角落。不要误会我的意思,Lua是好了,但必须有一个解释的地方。大部分我发现(在网络上),只是说该指数从1开始的句号。
I don't understand the rational behind the decision of this part of Lua. Why does indexing start at 1? I have read (as many others did) this great paper. It seems to me a strange corner of a language that is very pleasant to learn and program. Don't get me wrong, Lua is just great but there has to be an explanation somewhere. Most of what I found (on the web) is just saying the index starts at 1. Full stop.
这将是非常有趣的阅读是什么,它的设计者说一下这个问题。
It would be very interesting to read what its designers said about the subject.
请注意,我是非常初学者Lua中,我希望我不缺有关表了一些东西明显。
Note that I am "very" beginner in Lua, I hope I am not missing something obvious about tables.
推荐答案
Lua是由溶胶,专为石油工程师在计算机编程没有正式训练的语言后裔。在计算没有受过训练的人认为这是该死的怪异从零开始计数。通过采用基于1的数组和字符串索引,Lua的设计避免混淆他们的第一个客户和赞助商的期望。
Lua is descended from Sol, a language designed for petroleum engineers with no formal training in computer programming. People not trained in computing think it is damned weird to start counting at zero. By adopting 1-based array and string indexing, the Lua designers avoided confounding the expectations of their first clients and sponsors.
虽然我也发现他们在一开始奇怪,我已经学会了爱为基础的0阵列。但我得到确定用Lua的1基于阵列,特别是
使用Lua的通用为
循环和 ipairs
运营商的MDASH; I 通常可以避免担心只是数组索引方式
Although I too found them weird at the beginning, I have learned to love 0-based arrays. But I get by OK with Lua's 1-based arrays, especially by
using Lua's generic for
loop and the ipairs
operator—I can usually avoid worrying about just how arrays are indexed.
这篇关于为什么lua阵(表)1而不是0开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!