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

make Char not an Integer? #5844

Closed
malmaud opened this issue Feb 18, 2014 · 11 comments
Closed

make Char not an Integer? #5844

malmaud opened this issue Feb 18, 2014 · 11 comments
Labels
breaking This change will break code needs decision A decision on this change is needed
Milestone

Comments

@malmaud
Copy link
Contributor

malmaud commented Feb 18, 2014

Right now, bool("0") causes ERROR: no method bool(ASCIIString). It might make sense to define it as bool(x::String) = bool(int(x)).

Also, bool('0') somewhat surprisingly returns true, because it's dispatching to bool(::Number). It probably makes more sense to either have that return false or raise an error.

@JeffBezanson
Copy link
Sponsor Member

We like to avoid equating strings and numbers.

We could make conversion to Bool stricter and only accept arguments equal to 0 or 1. It also seems like x!=0 is clearer than bool(x) in many cases.

Generally it would be nice to make Char less of a numeric type. Adding an Ordinal abstract type has been raised in the past.

@quinnj
Copy link
Member

quinnj commented Jun 6, 2014

I think we should just define:

bool(x::Char) = throw(ArgumentError("can't convert Char to Bool"))

@StefanKarpinski
Copy link
Sponsor Member

I think we should just delete the bool function entirely.

@JeffBezanson
Copy link
Sponsor Member

However there is still convert(Bool, '0').

@quinnj
Copy link
Member

quinnj commented Jun 6, 2014

Yeah, probably better to get rid of bool and convert(Bool,x).

@JeffBezanson
Copy link
Sponsor Member

Well, the bool(), int() etc. functions are sketchy, but it seems weird to disallow conversion to Bool.

@quinnj
Copy link
Member

quinnj commented Jun 6, 2014

Actually, this is probably another case where the coerce() could come in handy. convert could throw or be no method while current behavior would be in coerce().

@JeffBezanson
Copy link
Sponsor Member

If we change our integer conversions to check for overflow, then converting to Bool would only allow arguments equal to 0 or 1.

@JeffBezanson JeffBezanson changed the title Define bool(::String) and bool(::Char) more carefully? make Char not an Integer? Aug 8, 2014
@JeffBezanson JeffBezanson added this to the 0.4 milestone Aug 8, 2014
@simonster
Copy link
Member

Is it intended that Bool conversions are still unchecked?

@JeffBezanson
Copy link
Sponsor Member

For now yes, but I'm not totally sure what to do about it. Being non-zero is well established to correspond to trueness. However I'm not sure what the use cases are for conversion to Bool. It seems you'd always be better off writing x != 0 if that's what you want.

@jakebolewski
Copy link
Member

Closed by #8816.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

6 participants