[PATCH] revset: add experimental set subscript operator

Jun Wu quark at fb.com
Fri Jul 7 11:26:53 EDT 2017


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.

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".

Note: the names (changeloglinear etc.) here are just examples, not final.


More information about the Mercurial-devel mailing list