Skip to content

Instantly share code, notes, and snippets.

@jcouv
Last active May 26, 2021 17:01
Show Gist options
  • Save jcouv/fa62923b3ee36de7f8553d2c1c58ec43 to your computer and use it in GitHub Desktop.
Save jcouv/fa62923b3ee36de7f8553d2c1c58ec43 to your computer and use it in GitHub Desktop.
list-patterns.md

For current PR:

  • Should we accept a general pattern following .. in a slice_pattern? Answer: let's say yes for now. Allowing some nested patterns versus allowing all isn't a deep change. We can add that before shipping.
  • We should define the exact binding rules for any of these members and decide if we want to diverge from the range spec. Answer: we should stick to the same behavior as ranges. In short, we bind to indexers if available, otherwise special Slice method.
  • Should extension methods play a role in sliceability? Answer: we may change that later (for slicing and slice pattern, thus transforming an error scenario into a working scenario) but should assume "no" for now (keep the existing rules from ranges).
  • The pattern {..} tests for expr.Length >= 0. Should we omit such test (assuming Length is always non-negative)? Answer: this doesn't need to be spec'ed, it is an implementation detail. We are free to change/optimize what we emit for this case. I'd start without the optimization. We can add if we have time.

For multi-dimensional arrays:

  • should they be in scope at all? [jcouv:] They are not countable/indexable/rangeable by our current definitions..., so I'm leaning towards disallowing.
  • lowering strategy for array is {​​​​​​​{​​​​​​​1}​​​​​​​}​​​​​​​

That's only a question on the lowering strategy. Given array is {{1}} which one of the following is expected:

array.GetLength(0) == 1 && array.GetLength(1) == 1 && array[0, 0] is 1
array.GetLength(0) == 1 && array.GetLength(1) == 1 &&
array.GetLowerBound(0) is var b0 && array.GetLowerBound(1) is var b1 &&
array[b0 + 0, b1 + 0] is 1
  • Should we allow length patterns with md arrays (probably no, unless we want to change the syntax to accept [0,0] etc) => I agree.
  • Should we allow length patterns in nested lists? (probably no, there's no point to give a length when all of them must match) =>
  • Should we allow slice patterns (without subpatterns) in a nested list? (this is possible unless we decide against it)
  • Should we treat {​​​​​​​}​​​​​​​ as an empty list in a nested pattern? (in that case new int[,] {​​​​​​​{​​​​​​​}​​​​​​​,{​​​​​​​}​​​​​​​}​​​​​​​ is {​​​​​​​{​​​​​​​}​​​​​​​,{​​​​​​​}​​​​​​​}​​​​​​​ returns true)

Misc

  • formatting for slice-pattern (..var or .. var?)
  • formatting for length-pattern (is [> 0])
  • formatting for length-pattern on array type (is string[] [> 0])

Opportunistic topics

  • records stack overflow
  • Activator.CreateInstance<T>() where T : struct not invoking the parameterless ctor on .NET Framework
@333fred
Copy link

333fred commented May 26, 2021

Third opportunistic topic:

  • Overloading custom handlers on ref vs value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment