lua-users home
lua-l archive

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


On 2 Jan 2002, Pixel wrote:

> Philippe Lhoste <PhiLho@gmx.net> writes:
> 
> [...]
> 
> > - I am not sure of what is a "sequence", but if it is an instruction
> > separator, end-of-line is a sequence in Lua, ie. ';' is optional.
> 
> do you mean ";" is optional at end-of-line?

";" is completely optional; the end of statements in the Lua grammar
is unambiguous without it.  Newline has no special meaning.  You can
write

  print("foo"); print("bar");

or

  print("foo") print("bar")


> > - dictionary constructor: { a=b, c=d }
> > dictionary access: a[e]
> > 
> > I don't know if the changes come from lhf (if this is the case, I accept
> > them ;-), but I wrote { a="b", c="d" } and a["e"], because the above syntax
> > works only if b, d and e are variables with non-nil values. And in this case,
> > a[e] isn't the same thing than a.e
> 
> i don't think such a differentiation goes along with the goal of
> syntax-across-languages.

Actually, this was a mistake in my submission too.

Given keys k1 and k2, and values v1 and v2, the general lua dictionary
constructor is:

  {[k1]=v1, [k2]=v2}

To retrieve the value associated with key k1:

  a[k1]

So if k1 and k2 are the strings "foo" and "bar", this is written:

  {["foo"]=v1, ["bar"]=v2}

and 

  a["foo"]

Across languages that I use, it seems that the majority of dictionary
constructors, and most dictionary accessors, are through constant
strings.  Lua's shorthand for the above is:

  {foo=v1, bar=v2}

and
 
  a.foo

which are friendlier to type and read.  So I misunderstood what your
form was asking for when I said Lua's dictionary constructor was
merely {a=b, c=d}.

That's the trickiest problem I saw in our Lua submissions; you'll have
to decide how you want to present it.  I will try to patch up my
remaining bugs against the current CVS when I get home.

Jay