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

the .. operator #2614

Closed
vtjnash opened this issue Mar 19, 2013 · 9 comments
Closed

the .. operator #2614

vtjnash opened this issue Mar 19, 2013 · 9 comments
Labels
speculative Whether the change will be implemented is speculative

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 19, 2013

is the behavior of the .. variable intentional?

I found this because I wanted to see whether I could propose that x..y(...) could be syntax for y(x, args...) or possibly instead syntax that x..y == Intrinsics.getfield(x,y) and x.y == Base.getdot(x,y)

julia> x..y = y:-1:x
# methods for generic function ..
..(x,y) at none:1

julia> 1..7
7:-1:1

julia> .... = 1
1

julia> ....
1

julia> x....y = x+y
ERROR: syntax: malformed function argument (call * .... y)

julia> x.....y = x+y
ERROR: syntax: malformed function argument (. .... 'y)

julia> x......y = x+y
ERROR: syntax: malformed function argument (call * x ....)

julia> x.......y = x+y
ERROR: syntax: extra token after end of expression
@JeffBezanson
Copy link
Sponsor Member

I don't know, what should it do?

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Mar 19, 2013

Syntax error? .. and .... aren't exactly in the common list of valid variable names, although they seem great for obfuscating code contests

Or reserve them for something useful, such as my other two proposals (making x..y(args...) OO syntax for y(x, args...), or making x..y == Intrinsics.getfield(x,y) and x.y == Base.getdot(x,y) which is overloadable and defaults to Intrinsics.getfield)

@ViralBShah
Copy link
Member

The contest we should have is how many colons and dots you can have in one julia expression.

@JeffBezanson
Copy link
Sponsor Member

Since .. is a sideways colon, it ought to be the second most popular symbol.

@JeffBezanson
Copy link
Sponsor Member

Also .... is not that strange a variable name. In lisp, the empty string can be a variable name :)

@StefanKarpinski
Copy link
Sponsor Member

Lisp is so cool

@JeffBezanson
Copy link
Sponsor Member

I added a syntax error for 4 or more dots.
Although everybody wants a.b syntax for various things, I think a..b is actually worthless. Might as well have it available as an operator in case some use arises, but I don't think anybody would be happy with x..f(y) for method calls.

@cdsousa
Copy link
Contributor

cdsousa commented Feb 12, 2014

How about using a..b as a shortcut to a[:b]? I have the feeling the dictionary-like types with symbols as keys are being used a lot (I'm thinking in DataFrames and PyCall). This is not as powerful as an overloadable dot operator, but maybe it is much simpler/faster to implement...

@StefanKarpinski
Copy link
Sponsor Member

Clever idea, but overloading the dot operator is going to happen, so it becomes a bit of a waste of syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

5 participants