-
Notifications
You must be signed in to change notification settings - Fork 29
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
Alternative to specify open/closed endpoints #39
Comments
|
Right... I was thinking that you technically may need something like I guess it was my feeling that such an interface might be simpler for users and simpler in implementation - it's just the composition of a small number of very simple concepts, rather than having a variety of different interval types and a larger set of interval-reflection functions, etc. |
The simplest implementation is always the one that’s already been done... I can see some benefits of your suggestion, but implementation wise it would require having 3 templates variables: the left endpoint type, the right endpoint type, and the domain type. This might turn into a headache. If it’s the user facing syntax that’s wanted, that’s easy to add: ..(a::Exclude, b::Exclude) = OpenInterval(a,b) |
PS I’d prefer a swift like syntax |
I'm not currently convinced you need a domain type. You can simply trust
Right, that's true!
Something like this would be pretty sweet. Alternatively, a unary op for "infinitesimally smaller than" could do a similar thing and be visually similar, I guess. |
In SingularIntegralEquations.jl I use the following struct Exclude{S,T}
x::T
end
Exclude{S}(x::T) where {S,T} = Exclude{S,T}(x)
const ⁺ = Exclude{true}(true)
const ⁻ = Exclude{false}(true)
*(a::Number, b::Exclude{S}) where S = Exclude{S}(a*b.x) |
Here's a Haskell package that puts the open- / closed-ness into the bounds. It also has syntactical sugar for creating intervals similar to that suggested above: |
How about using macro?
|
Existing syntax that could easily be used: julia> a .. <(b)
julia> a .. ≤(b)
julia> >(a) .. <(b) Looks quite nice for the right endpoint, the left one could've been better... |
From @MasonProtter on slack: julia> using IntervalSets
julia> macro range_str(s)
for (reg, f) ∈ [r"^\[.*\)$" => Interval{:closed, :open},
r"^\(.*\)$" => Interval{:open, :open},
r"^\(.*\]$" => Interval{:open, :closed},
r"^\[.*\]$" => Interval{:closed, :closed}]
m = match(reg, s)
if !isnothing(m)
args = Meta.parse(s[nextind(s, 1):prevind(s, lastindex(s))])
return :($f($(esc(args))...))
end
end
error("unrecognized expresson $s")
end;
julia> let a = 2
range"[1,a)"
end
1 .. 2 (closed-open) I think |
In AcceleratedArrays.jl I've been playing with "search intervals" for querying data, for example finding all the dates within a given range with the help of a sort-based acceleration index.
To accommodate open and closed intervals, I've been toying with the idea of syntax that looks like
a..exclude(b)
, which would be closed on the lower bound and open on the upper bound.exclude(b)
creates anExclude
object which slightly redefinesisequal
andisless
. See this file, particularly near the bottom.Basically, I wonder if we've got our bananas turned inside out and whether it would be simpler/more composible to make this a property of the elements (endpoints) of the interval rather than of the interval itself?
The text was updated successfully, but these errors were encountered: