• Subject: Re: why doesnt a[1] = 1 work?
• From: David Kastrup <dak@...>
• Date: Wed, 23 May 2007 17:19:09 +0200

```"Markus Heukelom" <Markus.Heukelom@enterprisedynamics.com> writes:

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

This is _not_ an analog.  The analog would be
a = {[1]=1}
which works.

a[1] = 1 _uses_ a as a table.

--
David Kastrup

```