jamiebuilds / ghost-lang

:ghost: A friendly little language for you and me.
302 stars 10 forks source link

Open ranges #21

Closed aleclarson closed 5 years ago

aleclarson commented 5 years ago

Thoughts?

let gtZero = 0..
let ltZero = ..0
let gteZero = 0...
let lteZero = ...0
aleclarson commented 5 years ago

If ranges were enclosed in square brackets, we could do:

# Open ranges
let gtZero = [ >0 ]
let ltZero = [ <0 ]
let gteZero = [ >=0 ]
let lteZero = [ <=0 ]

# Closed ranges
let a = [ 0..1 ]
let b = [ 0...1 ]
let c = [ >0 <1 ]
jamiebuilds commented 5 years ago

I would use:

0...Math.Infinity
-Math.Infinity...0
aleclarson commented 5 years ago

Compare how the two look in an array slice:

let a = [ 1, 2, 3 ]
let b = a[ 1..a.length ]
let c = a[ 1... ]