[tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module
Vladimir Davydov
vdavydov.dev at gmail.com
Thu Apr 4 17:42:03 MSK 2019
On Thu, Apr 04, 2019 at 03:00:40PM +0300, Alexander Turenko wrote:
> > > > > Also, returning 1, 0, -1 to Lua looks uncommon. May be, we'd better
> > > > > introduce 'equal', 'greater', 'less', etc helpers returning bool?
> > > >
> > > > A function for table.sort(table, func) returns boolean, so it make
> > > > sense. I'm a bit afraid that we'll need to make two calls: say, :less()
> > > > and :equal() to determine an order of tuples strictly. But I cannot
> > > > provide a case where it can be necessary. Are you know one?
> > >
> > > No, I don't write much code in Lua.
> > >
> > > However, if we decided to switch to bool return parameter, I'd implement
> > > all possible combinations, i.e. eq, ge, le, gt, lt.
> >
> > I mean are there cases when we need to check, say t1 < t2 and if it is
> > false then check whether t1 == t2 or t1 > t2? In other words, cases when
> > we need to distinguish all three possible situations. Some algorithms?
> >
> > I looked throught [1] and it seems it does not contain any reason why
> > <=> operator was added to C++20 except ones related to comparison
> > operations autogeneration.
> >
> > We can just add :cmp() in addition to all other variants, what do you
> > think?
> >
> > We can also do the trick: return {eq = <boolean>} from :le() / :ge()
> > instead of true, but this way looks weird.
> >
> > [1]: http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0515r0.pdf
>
> One example that looks valid: search in a binary search tree, where
> non-leaf nodes hold elements.
Okay, I see, it means that someone might actually need cmp(), not
eq/le/etc, in which case adding all those methods returning bool doesn't
look like a good idea. I tend to think that the API proposed originally
was okay, after all. Let's send an RFC to dev@ and see what others
think.
More information about the Tarantool-patches
mailing list