leekscript icon indicating copy to clipboard operation
leekscript copied to clipboard

Interval

Open Hazurl opened this issue 2 years ago • 2 comments

An Interval represents a continuous range of numbers between two bounds. Both endpoints are contained in the interval. Moreover, the interval can be unbounded; but this iteration won't allow to construct open intervals.

  • [x] Syntax [expr .. expr] to construct a closed interval #13
  • [x] Typing: the interval is not templated #15
  • [x] Implements the operator in as value in the interval which verifies that the value is in the interval (1*) #14
  • [x] Implements the getters intervalUpperBound, intervalLowerBound, and intervalIsEmpty (2*) #20
  • [x] Implements bool(interval) as not intervalIsEmpty(interval) #20
  • [x] Implements the method intervalToArray(interval, step), which constructs an array containing all values in the interval separated by step. This argument can be negative, constructing the values from the end. This returns null and displays an error for an opened interval. #17
  • [x] Implements intervalIsBounded #23
  • [x] Implements the constructor Interval(real from, real to) (2*) #23
  • [x] Syntax [.. expr], [expr..], and [..] for unbounded interval. Infinities can also be used. #23
  • [x] Implements intervalMidpoint. For empty or unbounded intervals, it returns null. #26
  • [x] Implements the method intervalIntersection which returns the interval to which all values lie in both intervals. #26
  • [x] Implements the method intervalCombine which returns the minimum interval containing both intervals. (3*) #26
  • [x] Implements intervalIsLeftBounded and intervalIsRightBounded #26
  • [x] Implements slices interval[start:end:stride] which is equivalent to intervalToArray(interval, stride)[start:end] #26
  • [ ] ~~Implements the arithmetic operators (+, -, *, /) for interval: [1..2] + 5 === [6..7] (the operation is applied on both endpoints).~~

1*: The in operator can be extended to arrays and maps. For maps, the value is checked against keys. 2*: An open interval returns +/-infinity as lower/upper bounds. Infinities can also be used in the constructor. 3*: Union is a term more often used, but it's not defined for disconnected intervals. intervalCombine will be a generalization to all pairs of intervals. If a user wants the strict union, they can verify first that the intersection is non-empty.

Hazurl avatar Jul 30 '23 15:07 Hazurl

Arithmetic operators are a bit complicated to implements + it's not an important feature => removed

Hazurl avatar Aug 05 '23 18:08 Hazurl

  • [ ] Interval operator[] var i = [100..200] i[50] // 150
  • [ ] [1.0..2.0] issue with lexer
  • [ ] Add an error on var i = [0.."salut"]
  • [x] Opened intervals ]x..y[
  • [x] Empty interval [..]
  • [ ] Empty collection ?

5pilow avatar Sep 04 '23 09:09 5pilow