lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 10 September 2013 04:42, Seppl Vorderhörer <> wrote:
"for" is used in Lua in two forms:
    for var=start,end,inc do something

... which is pretty close to a native language: run through all values from start to end.

Build me a sentence in English—one that sounds natural and not stilted—that uses "for" and means what that line of code means.
Same applies to
    for a,b in pairs(c) do something

Ditto for this.

See, for both of the above examples (notice how I used "for" here and how it does not really resemble "for" in Lua in any but the most superficial of ways?) my own wording in English would be:

  1. Begin at start, skipping by inc, and do something until you're at the end.  The word "for" isn't even in this sentence.
  2. For each pair in c, do something.

The second is closer to the code version, but the first has no relationship whatsoever.  Nobody (outside of perhaps a CS major too steeped in his area of study to be able to communicate effectively) would ever, in English, use "for" the way it's used in the first form.

The same applies to "while" or "do": "While something is the case do something else" is a nice construct even containing both keywords and at least from my point of view they are not used too far from their meaning in English.

Again, give me that example sentence.  I see a lot of hand-waving over how it's "close to the English meaning" but actual examples are suspiciously absent.  My own guess as to why is that at some level it's pretty obvious how stilted language will become if we try and build a non-contrived sentence that follows code syntax.
I even dare to say that the creators of programming languages usually choose keywords to have meanings that to some extent coincide with or come close to their meanings in natural languages.

Actually most of these constructs derive from the maths, not from natural language.
Also "or" has a meaning in Lua, that comes somewhat close to the meaning of "or" in natural languages: Something is either this or that (or both).

Would you like coffee or tea?  (Hint: if you answer "yes" or "true" in English you'll have people hitting you.)

"Or", in particular, bears only passing resemblance to its use in natural language.  It does, however, perfectly fit boolean algebras.  What a coincidence.
On top of that even "and" has a meaning in Lua which is the same as in English in a specific context. Something is true, if it's both a and b. The only (in my opinion) weird thing is to use "and" as a selector to convert "a and b" into the result "false" or "b" depending on "a".

I ate cake and ice cream.  In 99.44% of natural language uses "and" and "or" (see what I did there?) are not related to truth values at all.  These variants come, again, from the maths, not from natural language.
"Perhaps people don't believe this, but throughout all of the discussions of entering China our focus has really been what's best for the Chinese people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.