Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test plan for slicing/Range feature #23789

Closed
2 tasks
jcouv opened this issue Dec 14, 2017 · 5 comments
Closed
2 tasks

Test plan for slicing/Range feature #23789

jcouv opened this issue Dec 14, 2017 · 5 comments
Assignees
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Dec 14, 2017

This is a placeholder to track test ideas and open issues.

We should be able to finalize Range API by end of Jan (including review with LDM), so the implementation can be completed in Feb.

Various aspects of proposal:

  • Specific vs. generic types: It may be possible to do a generic Range and still implement some enumerables on it (via extensions), but we’re strongly leaning towards specific types (either 1 or 2). Range would be int. LongRange would be long.
  • End included vs. excluded: In foreach (var i in 1..10) it makes sense for 10 to be excluded. In 5.in(1..10) it makes some sense for 10 to be included. Overall, we’re leaning towards excluding the End.
  • Start+End vs. Start+Length: Strong preference for start+end to conform to language syntax and other languages.
  • Upwards-only vs upwards+downwards

Test ideas:

  • foreach (var i in 10..0) // decreasing
  • The ForEachToFor refactoring should recognize range syntax

Various links:

@jcouv jcouv added this to the 15.7 milestone Dec 14, 2017
@YohDeadfall
Copy link

I've found that the generic type can not be used for enumerating such things like DateTime because the distance is measured by TimeSpan and not by DateTime.

So if there are specific types should the range type for int be called IntRange? Because for math computations probably will be DoubleRange, for DateTime - DateTimeRange, and so on.

@jcouv jcouv added the Feature - Range Range label Dec 15, 2017
@AdamSpeight2008
Copy link
Contributor

Please make Range to be (Inclusive, Inclusive), as to me is indicative of a starting point and an end point.
eg Starting Line and Finishing Line or Frequency Range: 88 MHz To 108MHz
To me, a Span is indicative of a starting point and length covered.
eg Frequency Span: +/-20MHz @ 90MHz

Making it exclusive also means the full range of values isn't available especially the .MinValue and .MaxValue, making it inclusive doesn't.
The enumerator for inclusive is relatively simple to write, including the support for step values. Thus giving an alternate to for loops.

If you want syntax support for Span, use a different symbol .

'  RANGE
syntax RangeExpression ::=
   ( lower : ExpressionSyntax ) [To] ( upper : ExpressionSyntax ) ?( step : StepExpression);
syntax  StepExpression ::= [Step] ( expr : Express );
' SPAN
syntax Span    ::= ( field start) ( field length);
syntax Span<T> <: Span ::= ( field source );
syntax Span<T,S> <: Span<T> ::= ( field Step );

example

' span = index :: length
span s = 0 :: 10;
span<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[s]; 'eg ABCDEFGHIJ 
Dim r = 0 To 9 Step 3 ' eg 0 3 6 9

@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented Dec 15, 2017

Alternatively name it Mem<T> or Slice<T> for slicing section of memory or collection.

@BreyerW
Copy link

BreyerW commented Dec 17, 2017

Couldn't be possible to provide generic range and specialized one for Time-related stuff which would be silently switched by compiler if possible when compiler see Time-related class? As was mentioned, Range seems to be very useful in many scenarios not only strictly numerical, like char. I'm a bit concerned that current solution may lead to peculiar "code explosion" and/or very slow adoption for other useful patterns.

If that not possible, at least consider adding those two ranges (int, long) AND pattern reconizable by compiler like struct based Enumerable. This way at least, we programmers will have control over how much ranges there will be and you will never have to bother with considering yet another use case (char? DateTime? float? Cartesian? - although this one can be expressed as two ranges but imagine more than 2 dimensions and this quickly become quite unwieldy, custom, in-house classes? etc.) for Range pattern in future.

BTW for Cartesian or any space, really, be it 3D or nD i imagine something like

struct ThreeDimensionalRange{

... //here all necessary fields

public ThreeDimensionalRange(float X, float Y, float Z)

//here method that conform to pattern

}

... //somewhere later we spawn points in 3D space as vector3 s

bool isInBVHNode=vector in ThreeDimensionalRange(-10,-10,-10)..ThreeDimensionalRange(10,10,10); // BVH is one of the many ways to space partitioning, useful in games and some simulators

This is just clarification what i had in mind when mentioned Cartesian use case, not very enticing but different than the already mentioned and imagine how much separate range checks you would have to write for, let say, 12 dimensional space.

@jcouv jcouv modified the milestones: 15.7, 16.0 Mar 15, 2018
@jcouv
Copy link
Member Author

jcouv commented Mar 15, 2018

Closing in favor of #23205

@jcouv jcouv closed this as completed Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants