Skip to content

Commit

Permalink
Add ∅ (empty set) as synonym for Set{Any}({})
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahao committed Apr 19, 2014
1 parent fae924a commit 67ce8b5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export
WeakRef,
Woodbury,
Zip,
∅,

# Ccall types
Cchar,
Expand Down
1 change: 1 addition & 0 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Set{T}
Set(itr) = union!(new(Dict{T,Nothing}()), itr)
end
Set() = Set{Any}()
= Set()
Set(itr) = Set{eltype(itr)}(itr)

show(io::IO, s::Set) = (show(io, typeof(s)); show_comma_array(io, s,"({","})"))
Expand Down

6 comments on commit 67ce8b5

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a bad idea since this is just one instance of an empty set and it is mutable. Someone is going to do is this:

whosits =for thing in whatsits
    isfrobnish(thing) && push!(whosits, thing)
end

Now ∅ isn't empty. What you really want here is for ∅ to be syntax for Set() but I'm not sure that's worth it.

@jiahao
Copy link
Member Author

@jiahao jiahao commented on 67ce8b5 Apr 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That example reads to me like 'start with the empty set and add stuff to it', which seems fine to me.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if there's only a single piece of code that ever wants to use the empty set. This is shared global mutable state, it's no good.

@jiahao
Copy link
Member Author

@jiahao jiahao commented on 67ce8b5 Apr 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point.

@kmsquire
Copy link
Member

@kmsquire kmsquire commented on 67ce8b5 Apr 19, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmsquire
Copy link
Member

@kmsquire kmsquire commented on 67ce8b5 Apr 19, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.