[julia-users] Using generators

2016-10-02 Thread cormullion
Aren't generators to do with when the results are produced (on demand), rather 
than how they're specified?

[julia-users] Using generators

2016-10-02 Thread harven
I see that julia v0.5 has now generators. That looks promising but the 
example given in the docs is not really interesting,

  sum(1/n^2 for n = 1:1000)

since we have been able to write from start the shorter  and I think as 
efficient

  sum(n->1/n^2, 1:1000)

My question is, where may/should I use generators?
 It seems that I can't always use them when an array is expected, e.g. 

julia> reverse([i+1 for i in 'a':'c'])
3-element Array{Char,1}:
 'd'
 'c'
 'b'

julia> reverse(i+1 for i in 'a':'c')
ERROR: MethodError: no method matching
reverse(::Base.Generator{StepRange{Char,Int64},##422#423})
Closest candidates are:
  reverse(!Matched::BitArray{1}) at bitarray.jl:1416
  reverse(!Matched::String) at strings/string.jl:209
  reverse(!Matched::LegacyStrings.ASCIIString) at 
/home/harven/.julia/v0.5/LegacyStrings/src/ascii.jl:90