lua-users home
lua-l archive

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


2014-11-21 21:37 GMT+02:00  <tonyp@acm.org>:
> Well, # is the length operator and it’s meant to return the length of
> whatever follows, provided what follows has a concept of length/size (e.g.,
> table, string), so one -- I being that one, I guess :) -- would expect if a
> number follows it would return its length (of its common printable
> representation), rather than give error.  In other words, I would expect to
> #number to be equivalent to #(#number..’’)

Nothing stops you from saying

> debug.setmetatable(1,{__len=function(n) return #tostring(n) end})
> #math.pi
15

> (Another thing that I would expect is the IN operator to work like in Python
> when used with strings.  But that’s another discussion...)

`in` is not an operator any more than `end` is. It is a token in the syntax
of the generic `for`.