-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New library features for strings and ranges #610
Conversation
With this commit, now you can do this: s = "swap me" indx = [4,3,6] s[indx]
This commit adds a deep-copy operation for range objects. If this is not desired, feel free to ignore.
I believe ranges are intended to be immutable. |
I wondered about that. Presumably, the second patch isn't useful then. However, the first seems to be. Do I need to do something to extract the 5fefef8 patch, or can you cherry pick? |
Cherry picked 327c39c. |
It seems that the following works if you include my range patch, and doesn't if you don't: Is there a better way to do this? Statements like [100:300,70:400] expand into one long list. I guess the alternative is |
Ah, it's the old shallow-vs-deep copying problem. Range is actually a kind of AbstractArray, since you often want it to work like a vector. Therefore without your patch, the following unintentionally happens:
I'll take a look, and it might be better to just make array copying shallow by default. We could also add
to fix this. |
On a related note, I'll ask whether there's any chance that range expansion, as in [3:5], could be viewed as a convenience-motivated potential "wart" on the language. Let's suppose we want to create a function with this syntax: Let's consider how to initialize a: Let's try {}: julia> typeof(a) So {} is not very useful (?) unless convert(Array{Range1{Int},1},a) works. How about ()? julia> typeof(a) I don't think this is directly useful? (I'd love to be wrong.) julia> [a...] julia> convert(Array{Range1{Int32},1},a) julia> function tuple2array(a) julia> tuple2array(a) julia> map(x->x,a) The following works, but it's uncomfortably long: julia> a1 = myrange(3,5) julia> a2 = myrange(6,8) julia> a3 = myrange(15,20) julia> aall = [a1,a2,a3] julia> b = map(x->x.min:x.max,aall) How about a vector of pairs? Since this gets converted to a matrix, I'm not sure how to use this via map (one wants a "map over columns"). This works: julia> for i = 1:length(a) julia> av In my view, using convert on {} is the best of these; currently it doesn't work, but could be made to do so. But my concern is that [3:5] -> [3,4,5] is the real root of the problem. I recognize that there are surely many more people who want a convenient syntax for range expansion than people who are interested in arrays of range objects, but the fact that their natural syntaxes collide seems like an issue worth raising. Would it be worth forcing people to use an "expand" function explicitly? |
The thing is that Short answer is that The Somebody did write "map over columns", I believe it's called |
Very informative! Thanks! |
These commits support more generic indexing on ASCIIStrings and deep-copy on range types. I'm not certain the last one is really desired, but I'm sure you'll decide.