[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: why doesnt a[1] = 1 work?
- From: "Markus Heukelom" <Markus.Heukelom@...>
- Date: Wed, 23 May 2007 17:07:25 +0200
> And then assign it to "f(x)"? That is your proposed
> semantics, is it not? It not only creates a table, but assign
> it to the "variable" being indexed.
>
Well yes and no, what I think I meant was that a[i]=x is syntactic sugar for
a={}; a[i]=[x], iff value a is not of type table... But indeed I confused
values and vars a bit, thanks for pointing that out.
The main reason I started this question is that when programming, you see a
as a variable, allthough it is just value placeholder. You read "a[1]" as
get index 1 of variable a and not as get the value in a and then index the
result at index 1, which is quite different.
Because lua is loosy typed you also expect that it adapts the variables you
use when needed:
a = 1 -- lua makes a a number
a = "1" -- lua makes a a string
a[1] = 1 -- lua makes a a table... whoops no it errors!
a = {}; a[1]=1 -- aah....
>From the variable perspective weird but from value perspective perfectively
understandable, and I can see the advantages of the latter approach.
Anyway I understand the language quite somewhat better now :D
Markus
PS. Note for f(x)[i]=[x] and this syntactic sugar:
As f(x) is a value and not a placeholder for a value this syntactic shortcut
can ignore f(x), just creating the anonymouse table {i=x}.