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

Bounds / Limits Literal #80

Open
AdamSpeight2008 opened this issue May 26, 2017 · 5 comments
Open

Bounds / Limits Literal #80

AdamSpeight2008 opened this issue May 26, 2017 · 5 comments
Labels

Comments

@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented May 26, 2017

Bound / Limits Literals

These allow the user to express a couple of values that are to be treated as a bounds or limits.
They can also express the (in/ex) clusivity of the each of those bounds or limits

Examples

 ~[[1 To 10]] ' 1 <= x <= 10    eg 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
 ~[[1 To 10)] ' 1 <= x <  10    eg 1, 2, 3, 4, 5, 6, 7, 8, 9
 ~[(1 To 10]] ' 1 <  x <= 10    eg 2, 3, 4, 5, 6, 7, 8, 9, 10
 ~[(1 To 10)] ' 1 <  x <  10    eg 2, 3, 4, 5, 6, 7, 8, 9

 ~[[1 To 10 Step 2]] ' 1 <= x <= 10    eg 1, 3, 5, 7, 9
 ~[[1 To 10 Step 2)] ' 1 <= x <  10    eg 1, 3, 5, 7, 9
 ~[(1 To 10 Step 2]] ' 1 <  x <= 10    eg 2, 4, 6, 8, 10
 ~[(1 To 10 Step 2)] ' 1 <  x <  10    eg 2, 4, 6, 8
  • It supports only two comparision operators equal to and not equal to.
  • x = bounds equates to is x within the bounds?
  • x <> bounds equates to is x not within the bounds?
  • Implicitly convertable to an IEnumerable(Of T) IReadOnlyCollection(Of T)

Grammar [WIP]

          tilde ::= '~'
       range_op ::= 'To'
   range_values ::= expr ws+ range_op ws+ expr range_step?
     range_step ::= ws+ "Step" ws+ expr 
      range_box ::= '[' ws* clusivity_lower ws* range_values ws* clusivity_upper  ws* ']'
inclusive_lower ::= '['
exclusive_lower ::= '('
clusivity_lower ::= ( inclusive_lower | exclusive_lower )
inclusive_upper ::= ']'
exclusive_upper ::= ')'
clusivity_upper ::= ( inclusive_upper | exclusive_upper )
literal ::= ( tilde range_box )
@Bill-McC
Copy link

comments:
Really not VB'ish looking.
~ reminds me of not for some reason , or approximates
having to differentiate between ( and a [ to check for odd vs even --> aghh!!!

questions:
Is this for integer types only ?
Is this for comparison operations only as in For loops and If statements, or is it for assignment as well ?

@AdamSpeight2008
Copy link
Contributor Author

An alternative is to use the range clause syntax eg `0 To 10' (restricting both bounds to inclusive)
Example

If x Is 1 To 10 Then Return "Valid" Else Return "Invalid" 

@rskar-git
Copy link

Maybe instead we can invent a Case function, somewhat like we have an If function:

If Case(x, 1 To 10) Then Return "Valid" Else Return "Invalid"

Anything that is fair game in the Case statement of a Select Case can be used:

If Case(x, Is > 0) Then Return "Valid" Else Return "Invalid"

Multiple conditions may be applicable:

If Case(x, 1 To 3, 99) Then Return "Valid" Else Return "Invalid"

(Above succeeds if between 1 and 3, or is equal to 99. As in, (x >= 1 AndAlso x <= 3) OrElse (x = 99).)

Perhaps two forms of Case? Single condition returns Boolean, multi condition returns Integer corresponding to the first succeeding condition (zero meaning no success)? E.g.:

If Case(x, 1 To 3, 99) > 0 Then Return "Valid" Else Return "Invalid"

Or instead, leave Case as a Boolean thing, and introduce Select function as the Integer thing? E.g.:

If Case(x, 1 To 3, 99) Then Return "Valid" Else Return "Invalid"
If Select(x, 1 To 3, 99) > 0 Then Return "Valid" Else Return "Invalid"

@AdamSpeight2008
Copy link
Contributor Author

@rskar-git See newer proposal #160

@rskar-git
Copy link

@AdamSpeight2008 Thanks! (for proposal #160)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants