[julia-users] Re: map without creating a new array

2015-06-10 Thread Tom Breloff
I see your point as well. I think both versions have their place... it just comes down to proper naming to reduce confusion. I'll think on method names a little more. On Wednesday, June 10, 2015 at 11:22:26 AM UTC-4, David Gold wrote: > > I see your point. However, my gut is telling me that yo

[julia-users] Re: map without creating a new array

2015-06-10 Thread David Gold
I see your point. However, my gut is telling me that your solution still conflates two separate issues. The first is, What's a good way to mutate an array element by element with a function that takes a scalar input? The second is, how do I "pipe" (is this still the right word?) the result of o

[julia-users] Re: map without creating a new array

2015-06-10 Thread Tom Breloff
I agree... using the pipe operator for this would be confusing at best, and breaking at worst. However it would still be cool to be able to connect multiple functions in one pass. What about: julia> function foreach(A::AbstractArray, f::Function, fs::Function...) for x in A

[julia-users] Re: map without creating a new array

2015-06-10 Thread David Gold
Pipe and map seem like related but orthogonal concepts; I don't know if they ought to be given the same operator. But I may just be looking at things wrongly. I'd sooner see a tricked-out array comprehension syntax. Something like ![ add_one(x) for x in A ] If the target array were ambiguous,

[julia-users] Re: map without creating a new array

2015-06-09 Thread Tom Breloff
Stefan: Yes that's obviously valid. Simon's "foreach" is essentially what I mean. Although overriding the pipe operator would probably break things, I think ideally there would be a built-in solution that looks similar to this: julia> |>(A::AbstractArray, f::Function) = (for x in A; f(x); e

[julia-users] Re: map without creating a new array

2015-06-09 Thread Simon Danisch
I wrote myself a foreach, which I'm using from time to time. foreach(println, array) It's not a big win, but in some cases it feels nicer than a for. Am Dienstag, 9. Juni 2015 21:39:11 UTC+2 schrieb Tom Breloff: > > I'm probably overlooking something simple, but is there a built-in > function to

Re: [julia-users] Re: map without creating a new array

2015-06-09 Thread Stefan Karpinski
Any reason not to just use a for loop for this? "map_without_result(add_one!, A)" is three characters longer than "for x in A; add_one!(x); end" and the semicolons are unnecessary. On Tue, Jun 9, 2015 at 5:06 PM, Tom Breloff wrote: > Ideally I don't have to assume anything about the return value

[julia-users] Re: map without creating a new array

2015-06-09 Thread Tom Breloff
Ideally I don't have to assume anything about the return value (all I care about is the side effect). On Tuesday, June 9, 2015 at 4:58:36 PM UTC-4, Scott T wrote: > > Not sue if this is exactly what you want, but you can achieve this with > `map!` by making `add_one!` return the modified MyType:

[julia-users] Re: map without creating a new array

2015-06-09 Thread Scott T
Not sue if this is exactly what you want, but you can achieve this with `map!` by making `add_one!` return the modified MyType: julia> type MyType; x::Int; end julia> function add_one!(mt::MyType) mt.x += 1 return mt end add_one! (generic function with 1 method) jul