[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-20 Thread gentlebeldin
So if I have an array of Bool, isprime (obtained by sieving, e.g.) of length n, [1:n][isprime] will give the same result as primes(n)? That's nice to know, though I'd call the syntax... interesting. :D Concerning the original problem: When we use do notation, an additional line x,y=p won't cost

Re: [julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-19 Thread Leah Hanson
You could also split that into multiple lines if readability is your goal: ~~~ sum(map(first,filter(x-x[1]!=x[2] x[2]=n d[x[2]]==x[1],enumerate(d ~~~ becomes: ~~~ filtered = filter(enumerate(d)) do x x[1]!=x[2] x[2]=n d[x[2]]==x[1] #expand to readability as desired end final =

[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-19 Thread Matt Bauman
There's also an open issue about splitting or splatting of tuples within function arguments that's very relevant here: Allow tuple destructuring in formal arguments, https://github.com/JuliaLang/julia/issues/6614 It's a common use case that I run into often, especially with enumerate and

[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-19 Thread Keith Campbell
You could also use a list comprehension without enumerate: d=[6,5,4,3,2,1,0] n=4 sum(d[ Bool[i=n d[i]!=i d[d[i]]==i for i in 1:length(d)] ] ) 18 Coming from numpy, I find this syntax intuitive, aside from the requirement to explicitly set the comprehension type to Bool. On Thursday, June

[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-19 Thread Peter Simon
Nice! Just a note that the Bool[...] annotation is only required when evaluating this in the REPL. Within a function definition the type of the comprehension is correctly inferred. On Thursday, June 19, 2014 9:25:40 AM UTC-7, Keith Campbell wrote: You could also use a list comprehension

[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-18 Thread Peter Simon
How about pairs = [e for e in enumerate(sqr)] filter(p - +(p...)%4 != 0, pairs) ? --Peter On Wednesday, June 18, 2014 3:34:24 PM UTC-7, gentlebeldin wrote: When you come across Julia, and know (a bit of) Haskell, comparisons are inevitable. Haskell has only functions with one argument,

[julia-users] Re: uncurried functions are ok... if you know what you are doing

2014-06-18 Thread Joey Huchette
See here (https://github.com/JuliaLang/julia/issues/554) for discussion on currying in Julia. On Wednesday, June 18, 2014 6:01:38 PM UTC-5, Peter Simon wrote: How about pairs = [e for e in enumerate(sqr)] filter(p - +(p...)%4 != 0, pairs) ? --Peter On Wednesday, June 18, 2014 3:34:24