-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allow ? in identifiers #1910
Comments
As a Schemer I'm certainly sympathetic to this, but renaming all the predicates would break a lot of code, and we would have to require whitespace to use the ? operator, or get rid of it. |
@StefanKarpinski seemed alright with requiring whitespace. Since the I agree that a lot of code would break, but the fixes only require basic string replacements. |
I am not too excited about this one. |
We have decided to not allow this one. The convention will be to use |
I like the idea of P.S.: How |
Could you provide the rationale? |
|
I noticed recently that Although you can't type it into a REPL anymore, you can easily write ? = ? == ? ? :? : :(? ? ? : ?) do. You can get quite far with writing valid code with function ?(x::Real)
0≤x≤1 || (y=floor(x); return ?(x-y)+y) #Range reduction
(x==0 || x==1) && return x #Base cases
p=floor(Integer, x)
q=1
r=p+1
s=1
d=1.0
y=float(p)
(x<y || (p<0) $ (r≤0)) && return x
while true
d /=2
(y+d==y) && break #Reached maximum possible precision
m=p+r
((m<0) $ (p<0)) && break #Overflow
n=q+s
(n<0) && break #Overflow
x<(m/n) ? (r=m; s=n) : (y+=d; p=m; q=n)
end
return y+d
end
using Base.Test
@test_approx_eq ?((√(3)-1)/2) 2/7 |
One place that gets used right now is for fake-ternary syntax in the OS-testing macros:
|
I think those should go away. '@osx' should so what '@osx_only' does currently. |
Maybe. They are kind of messy, but it's convenient to have a boolean-like version of those. People seem to like using them more than |
How are they better than something like an On Mon, Feb 23, 2015 at 10:26 AM, Tony Kelman notifications@github.com
|
They would probably be better as functions. |
@tkelman I hate those macros. They should definitely go away. They appear to parse as ternary operators, but they don't and are instead crazy brittle for parsing. |
Maybe now is the time to deprecate them (or get rid of them entirely)? |
They can't be functions, because sometimes you need to make sure an expression never appears in the AST on an operating system (e.g. because it's a ccall or cglobal). How about something like:
|
@StefanKarpinski I know you do. If we're going to get rid of them, the sooner the better, because people who don't know any better about how they're implemented will keep using them otherwise. Preferably with a deprecation, or handling in Compat.jl. |
I like @Keno's suggestion. |
deprecation: Compat.jl: |
As a generalisation of @Keno's suggestion, there's a handy macro called @cond if WINDOWS
println("windows")
elseif UNIX
println("unix")
else
println("What are you??")
end will compile to a single What's also nice about this is it trivially generalises to, for example, OS versions, as well as Julia versions: @cond VERSION > v"0.4-" ? Dict(1=>2) : [1=>2]
@cond windows_version() < (1,2) ? .... I can also see the argument for giving users less of a swiss army knife, though – something like |
No, I like the general version. It would be nice if we could write it as |
This will allow us to have functions like
contains?
andempty?
.The text was updated successfully, but these errors were encountered: