lua-users home
lua-l archive

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


On Monday, January 29, 2018, 8:23:53 AM GMT, steve donovan <steve.j.donovan@gmail.com> wrote:
> On Sun, Jan 28, 2018 at 11:24 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> > 2. In a for statement, allow extra conditons before the 'do'.
> > 2a.
> >
> > for _,item in ipairs(list) if type(item)=='table' do
> > ...
> > end
> I do like this sugar! One less block level, and it's a common pattern.
> Been spending a lot of time using Rust, and the
> for x in list.iter().filter(|x| some_condition(x)) {
> ...
> }
> pattern is great. Naturally, this pattern is possible in Lua (although
> closures are a bit more verbose) but Rust can make this as fast as
> hand-rolled ifs.

Well if we had filters I would want maps and all the rest too!  I've got a
library for doing things like this already though, I don't think syntax is a
good way to go here.  Note that it's not syntax in Rust either.


> some standard for type annotation

I think this is the only thing I really want as a syntax addition.  But I
wouldn't be sure how to make it work when e.g. I have some table which I'm
treating as an object of a specific type.  Maybe a __type metafield can
give a string name for its type.

But then, I can probably write an assert_type(...) function which inspects
that metafield and just do this as a library too. :-)

--
GK