The reason why not all arrays can be iterators is that in general arrays can not be 'compressed' like that. A linear range can be compressed to: a start value, an increment, and a length, making it incredibly lightweight. Doing this for sin() is not that easy. Doing it for rand() is simply Impossible.
On Wednesday, October 21, 2015 at 9:38:07 PM UTC+2, Gabriel Gellner wrote: > > I have no issue with the LinSpace object, I simply do not see why it is > the special case for this kind of object (I imagine the choice was made > since it was seen to be used mainly for looping vs being used for array > creation like similar functions logspace, zeros, ones, etc). If the > iterator version is so good I don't see why all Vectors are not returned as > this type for all the reasons you mention. In the current state where only > linspace returns this kind of special polymorphic type it simply breaks any > feeling of consistency in the language. I so something like x = zeros(10) > and I get an array great. the next line I do y = linspace(0, 5, 10) I get a > new fangled iterator object. They work the same but how do I get an > iterator version of zeros? etc. It is a pedantic point but so is special > casing this super common function to mean something that is not consistent > with all other languages that use it. Which would be fine if when I did > something like sin(linspace(0, 5, 100)) I got back an iterator but I don't. > This abstraction is not percolated thru other functions, further giving the > feeling of a needless special case in the language writ large. They simply > get converted to concrete types for many common functions, when if this is > done will vary from function to function, with little semantic reasoning. > My feeling is that if what people say is true than why is the default > numeric array not have the iterator semantics. As it is linspace is made > special for no reason other than it is assumed it will be used for looping. > > People want to argue that it is more elegant and takes advantage of what > makes Julia powerful, which I get, but then why not go all in on this? > Mathematica does this. Everything is basically a List which nice behavior > for vectors matrices etc. I have no issue with this kind of elegance, but > it is rough when the abstraction is inconsistent (the type is not truly > perserved in most functions). As people have mentioned clearly logspace > should be a special object ... but when does this stop? I dislike that this > feels so arbitrary ... and as a result it is jarring when it turns up. The > fact that it is polymorphic is only one kind of consistency. >
