Hello,

In Julia 0.4 the "int(foo)" syntax was deprecated:

julia> int(3.2)
WARNING: int(x::AbstractFloat) is deprecated, use round(Int,x) instead.
...
3

I am happy with `round(Int,x)` but recently I noticed that Python 
consistently uses the name of the a type as the name of the function to 
convert values into that type. Compare:

Python:

list("hello") # Creates a `list` type.
str(10) # Creates a `str` type.
int(3.2) # Creates an `int` type.
set("hello") # Creates a `set` type.


Julia:

collect("hello") # Creates an Array
string(10) # Creates an ASCIIString
round(Int,3.2) # Creates an Int
Set("hello") # Creates a Set.

I think the Python guys are onto something. It is easy to remember that the 
name of the function is the name of the type. Do you think there is any 
merit in Julia copying that idea? In Julia the equivalent might be 
something like this:

Array("hello")
String(10)
Int(3.2)
Set("hello")

Currently only the last one works. The others give errors, and String is in 
fact deprecated. We could try the lower case versions:

array("hello")
string(10)
int(3.2)
set("hello")

Now string(10) works, but int(3.2) is deprecated. The others don't exist 
but could exist:

set(x) = Set(x)
array(x) = collect(x)

I think it would be nice for Julia add this extra bit of consistency in the 
language. What do you think?

Cheers,
Daniel.

Reply via email to