[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-08 Thread cheng wang
Thank everyone! I am convinced by the trick feed(man, food). Just like: append!(collection, element) vs collection.add(element). append! gives me the feeling that I am controlling the program :) Best, Cheng

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread lewis
Seems a bad idea even as syntactic sugar, except for the case of using PyCall (when the target language is loosely object oriented). If you prefer object oriented dispatch, many languages offer it. With strong typing, optionally as Julia provides, OO dispatch can off make class inheritance ver

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Steven G. Johnson
On Wednesday, October 7, 2015 at 1:26:00 PM UTC-4, cheng wang wrote: > > I don't see why it is bad to support more styles if there is no harm to > the original one. > Because code that mixes multiple styles is harder to read (imagine reading a document that jumps back and forth between different

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
I absolutely like multiple dispatch. Just want to make syntax sugars based on this. On Wednesday, October 7, 2015 at 7:59:22 PM UTC+2, Scott Jones wrote: > > I think the important take away is that Julia's *multiple* dispatch can be > much more powerful than traditional "object oriented" single

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
On Wednesday, October 7, 2015 at 8:10:45 PM UTC+2, Pablo Zubieta wrote: > > As others mentioned, it is better to use multiple dispatch as the Julia > language was developed with it as one of its central features. > Totally agree with this. using verb(object, args) to implement object.verb(args)

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Pablo Zubieta
As others mentioned, it is better to use multiple dispatch as the Julia language was developed with it as one of its central features. You could easily change the name of the function to make it look natural (in the english grammar sense). E.g. you can define feed(Man, food) or feed(Man, with=f

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Maxim Grechkin
> > The only difference between object.verb(args...) and verb(object, args...) > is spelling. Since there is no practical need for the former, you should > just get used to the Julia spelling when writing Julia code. > What about auto-complete? object.verb provides better opportunities to auto

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Scott Jones
I think the important take away is that Julia's *multiple* dispatch can be much more powerful than traditional "object oriented" single dispatch. Once you get your head wrapped around that, I don't think you really would want to go back to the Python/Java/JS/C++ single dispatch way of doing thin

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
On Wednesday, October 7, 2015 at 6:47:40 PM UTC+2, Steven G. Johnson wrote: > > It's a bad idea. You shouldn't try to write C programs that look like > Fortran programs, you shouldn't speak French with English pronunciation, > and you shouldn't try to write Julia programs that look like Pytho

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Eric Forgy
Well said! :D On Thursday, October 8, 2015 at 12:47:40 AM UTC+8, Steven G. Johnson wrote: > > It's a bad idea. You shouldn't try to write C programs that look like > Fortran programs, you shouldn't speak French with English pronunciation, > and you shouldn't try to write Julia programs that lo

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Steven G. Johnson
It's a bad idea. You shouldn't try to write C programs that look like Fortran programs, you shouldn't speak French with English pronunciation, and you shouldn't try to write Julia programs that look like Python programs. Part of programming is learning to adapt to the local style, both the

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Glen O
Perhaps you could include the function amongst the elements of the type? immutable MyArray array::Array fill::Function MyArray(array)=new(array,i->fill!(array,i)) end B=MyArray(zeros(5,2)); B.array 5x2 Array{Float64,2}: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 B.fill(1);

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
Thanks everyone! I also find this helpful: https://github.com/JuliaLang/julia/issues/1974 A very related issue that the authors of Julia discussed. In scala, object.f(args) is implemented as f(object, args). For Julia, maybe this implementation would harm the performance. Anyway, It's fine to use

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
Newbie here too :) For me, the problem is having to write @mymacro everytime I use this style. On Wednesday, October 7, 2015 at 5:44:30 PM UTC+2, Eric Forgy wrote: > > I'm still a Julia newbie, but have been lurking around long enough to know > that a common answer for questions like this is...

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread David Gold
See perhaps https://groups.google.com/forum/?hl=en#!topic/julia-dev/V1HJcHQz4JE On Wednesday, October 7, 2015 at 8:13:33 AM UTC-7, cheng wang wrote: > > Hello everyone, > > In some cases, I would like to make a function belongs to an object. > In classical OO, we do something like object.f(args..

Re: [julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Milan Bouchet-Valat
Le mercredi 07 octobre 2015 à 08:31 -0700, cheng wang a écrit : > Just looks natural in some cases. > > For example: Man.eat(food) looks better than eat(Man, food). > > A similar situation is arithmetic expression. 2 + 3 might look more > natural than (+ 2 3). Looks like you'd rather want to writ

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Eric Forgy
I'm still a Julia newbie, but have been lurking around long enough to know that a common answer for questions like this is... *You can have the behavior you want via a fairly straightforward macro.* In this case, the macro would simply take object.f(args) and replace it with f(object,args), w

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread cheng wang
Just looks natural in some cases. For example: Man.eat(food) looks better than eat(Man, food). A similar situation is arithmetic expression. 2 + 3 might look more natural than (+ 2 3). On Wednesday, October 7, 2015 at 5:23:23 PM UTC+2, Simon Danisch wrote: > > There are a lot of things "one cou

[julia-users] Re: Is there a way to replace f(object, args...) with object.f(args...)?

2015-10-07 Thread Simon Danisch
There are a lot of things "one could do" ;) Can you give some appealing reasons, why someone should invest his/her time into this? Best, Simon Am Mittwoch, 7. Oktober 2015 17:13:33 UTC+2 schrieb cheng wang: > > Hello everyone, > > In some cases, I would like to make a function belongs to an obj