Timeline for Any built-in function to generate successive sublists from a list?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 18, 2012 at 21:25 | comment | added | rcollyer | I think my objection the the MapIndexed form is that you are carrying around a reference to list, mapping over list, yet only using the indices. So, yes, I think f /@ Range@Length@list is cleaner because it requires less work to understand it quickly. While the MapIndexed form is still quick, it takes more time to parse it mentally. | |
| Dec 18, 2012 at 21:24 | comment | added | Leonid Shifrin | @rcollyer I don't consider myself good at them either, just OK. The problem is that Mathematica's execution model often creates rather unnatural preferences for the algorithms implementations. But recursion is very powerful. Actually, I don't know what I would do without it for many problems. It was very important ingredient for RLink, for one thing. | |
| Dec 18, 2012 at 21:19 | comment | added | rcollyer | @LeonidShifrin I need to study up on list manipulation algorithms a bit to consider myself "good" at them. Recursion still drives me a bit nuts. | |
| Dec 18, 2012 at 21:18 | comment | added | rcollyer | It looks like I need one more question for a copper badge, but a gold one would be nice, too. I guess I need to start answering questions more. | |
| Dec 18, 2012 at 21:17 | comment | added | Leonid Shifrin | I think that most of us like list manipulation because M has an outstanding support for them, so that our programming flow can be very smooth. For a number of other things (handling state, implementing data structures with certain characteristics, scaling codebase to larger size, etc), the support is perhaps not so great, so one has to overcome significant mental barriers and these topics are less attractive to most M users. But this is what interests me more at present, since this is what stands in my way. | |
| Dec 18, 2012 at 21:06 | comment | added | Leonid Shifrin | Actually, @rcollyer posted it, so problem solved :). Re: gold badge - I've got one already, on SO :). Seriously, I am much less interested in list manipulations in Mathematica now than I used to be. I found that things that make it hard for me personally to code in M are mostly elsewhere (and it is not always obvious what they are, for a given problem). | |
| Dec 18, 2012 at 21:02 | comment | added | rm -rf♦ | @LeonidShifrin My "interest" is in getting a gold badge some day... hopefully without answering too many low hanging fruit :D (damn you for guilt-tripping me :P). But more seriously, I do like list-manipulation questions that are generic (i.e., not overly data specific)... it provides an excellent opportunity to learn different techniques (some that you might not even expect) | |
| Dec 18, 2012 at 21:01 | comment | added | Leonid Shifrin | @rm-rf Somehow I did not expect so much excitement about this topic, so many answers. I could as well post it indeed. Perhaps I will. But my solution suffers from the same flaw as others. | |
| Dec 18, 2012 at 20:41 | comment | added | rcollyer | FoldList by itself works. | |
| Dec 18, 2012 at 20:39 | comment | added | rm -rf♦ | @LeonidShifrin I thought of something like Flatten /@ Rest@FoldList[List, {}, {a, b, c, d}], but it was similar to your solution above and was hoping you'd post it | |
| Dec 18, 2012 at 20:28 | comment | added | Leonid Shifrin | +1. But the real clean solution here is to use linked lists, since all of the suggested ones have quadratic complexity in the length of the list. | |
| Dec 18, 2012 at 20:20 | comment | added | rm -rf♦ | "Cleaner" is subjective and in this case, I positively dislike having to use Range@Length@foo when I don't have to. Far cleaner to use MapIndexed and ignore #1 | |
| Dec 18, 2012 at 20:10 | comment | added | rcollyer | Why are you using MapIndexed? Why not Subsets[list, #, 1][[1]]& /@ Range[Length@list]? It seems cleaner. | |
| Dec 18, 2012 at 17:54 | history | edited | rm -rf♦ | CC BY-SA 3.0 | added 99 characters in body |
| Dec 18, 2012 at 17:47 | history | answered | rm -rf♦ | CC BY-SA 3.0 |