[PATCH] revset: add experimental set subscript operator
Yuya Nishihara
yuya at tcha.org
Fri Jul 7 12:11:50 EDT 2017
On Fri, 7 Jul 2017 08:26:53 -0700, Jun Wu wrote:
> Excerpts from Yuya Nishihara's message of 2017-07-07 21:25:17 +0900:
> > On Thu, 06 Jul 2017 19:04:48 -0700, Sean Farley wrote:
> > > Jun Wu <quark at fb.com> writes:
> > > > Could it be foo[+4][1] meaning what you want? An explicit "+" means
> > > > it's an offset, the "1" without a "+" means it's a normal index.
> > >
> > > Hmmm, I'll have to mull on that. My gut feeling is that it might be too
> > > magical. Though, we're severely limited on characters so it might be the
> > > least-worst option.
> >
> > It's confusing. You might think foo[-1] will return the last element in
> > foo.
> >
> > If we don't want to use {} but also want to reserve [] for future use,
> > we'll need a completely different operator, e.g. foo[[4]], foo~[4]
> > foo#[4].
>
> Think it a bit more, they look similar: given some order information (a
> list, changelog DAG, or obsolete graph), do indexing, or slicing.
Just a nitpick. They are quite different operations if we take the #op
as an order specifier.
x[y] (indexing) selects the y-th element from x (inside x)
x{y} goes to the y-th elements from x (outside x)
But, ...
> It seems the missing bit here is to specify which "order" to use. Suppose
> the operator is "[]", that "order" information may be provided inside the
> operator ("[1o]", "[-2g]", like what mpm said), or at the operator itself
> (use different operators), or outside the operator.
>
> Inside operator may create some syntax inconsistent with other languages.
> Different operators may exhaust our operators.
>
> I'm currently leaning towards "outside the operator". That could make "[]"
> closer to existing language. It also looks flexible and clean. For example,
> use "#ordertype", like:
>
> x#changelog[3]: x~-3 (approximately)
> x#changelog[-3]: x~3 (approximately)
> x#changelog[0:3]: x + x~-1 + x~-2 + x~-3
> x#changelog[1:]: descendants(x) - x
>
> x#changeloglinear[-3]: x~3 (only consider p1 to make history linear)
> x#changeloglinear[:0]: _firstancestors(x)
>
> x#obsolete[1]: successors(x)
> x#obsolete[1:]: allsuccessors(x) - x
> x#obsolete[:]: allprecursors(x) + allsuccessors(x)
>
> x#plainlist[1]: pick the second element in the list
> x#plainlist[-1]: pick the last element in the list
> x#plainlist[1:3]: pick a slice in the list
>
> We can specify a default order, like "#changelog" or "#plainlist".
We could read 'x#op' as 'x->op()' in C++, so 'x#changelog' could be considered
'ancestors(x) + descendants(x)' operation with depth index.
Perhaps, a drawback of this idea is that the syntax is verbose, and parsing
will be a bit complex.
More information about the Mercurial-devel
mailing list