Timeline for How to Set parts of indexed lists?
Current License: CC BY-SA 3.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 20, 2013 at 3:45 | comment | added | Mr.Wizard | @Murta Okay. You are aware that you could create a new context to keep Global` clean? It's more involved and I didn't see the need but I can show you how if you like. | |
| Feb 20, 2013 at 3:38 | comment | added | Murta | No.. it's not visual. It's more about pollute my Global context. But now I understand better your code, and see that when I clear Symb@indx, x dies together. Symb@indx works just like a pointer. Cool!.. tks for tks patience. | |
| Feb 20, 2013 at 3:29 | comment | added | Mr.Wizard | @Murta I believe the slow-down is because of the complete re-assignment as I observed. Is your dislike of x$??? merely visual? Because that could be concealed. | |
| Feb 20, 2013 at 3:08 | comment | added | Murta | Seems strange that x jump in the code. Save everything in a seems to be more natural. But maybe it's just something new that I have not yet used. About my code, I like that we can define a = list directly, but it's very slow in your test (more than 10x). | |
| Feb 20, 2013 at 2:58 | comment | added | Mr.Wizard | @Murta at first glance it appears you are reassigning the entire definition (array) for each set. I'm still trying to understand your objection to my method so that I might address it. | |
| Feb 20, 2013 at 2:43 | comment | added | Murta | I tried an answer. I just don't know why my time performance is so bad. Some clue? | |
| Feb 20, 2013 at 0:15 | comment | added | Mr.Wizard | @Murta well yes, there is going to be a proxy symbol. What is your issue with that? It could be moved to a private context if for some reason Global` is bad. If you need to make use of DownValues an additional definition could be made to translate as needed. If you are specific I will try to address the problem. | |
| Feb 19, 2013 at 23:43 | comment | added | Murta | @Mr.Wizard Hi. I just don't like one point in your solution. We get a unwanted global variable. If we make DownValues@a we get something like {HoldPattern[a[x]] :> x$1280} instead of {HoldPattern[a[x]] :> {1, 7, 3}}. @Leonid solution has the same side effect, if I may call it that. | |
| Jun 23, 2012 at 19:51 | comment | added | Leonid Shifrin | I actually started feeling the power of Mathematica as a gluing medium (as compared to Mathematica the language) relativey recently. The problem is that cross-language development has higher entry barrier than the same languages taken separately, since one has to also deal with the impedance mismatch between the langauges. I think we currently just miss the tools to make it easier. As to the second option, it is probably safe enough, but you just never know. And also, it can make Part slower if you have a large number of symbols (but that has to be tested). | |
| Jun 23, 2012 at 17:37 | comment | added | Mr.Wizard | @Leonid by the way, what is your take on the safety of the second option I present? It seems to me that overloading Part with a specific pattern is unlikely to cause problems. Do you agree? | |
| Jun 23, 2012 at 17:32 | comment | added | Mr.Wizard | @Leonid those are very valid points. I am biased because I tried to learn C many years ago and it only gave me headaches; then I discovered Mathematica and the joy of doing with one line of code what was taking dozens and I never looked back. Your Java Reloader makes using code copy and paste easy so it's hard to argue against building a Java library, though if I never learn Java I'll end up with "cargo cult programming." I am (largely thanks to you) slowly coming to see the value of using Mathematica as a framework for multiple languages. | |
| Jun 23, 2012 at 12:31 | comment | added | Leonid Shifrin | ... data structures and efficient general programming. These gaps can often be alleviated by using other languages (e.g. Java, but not only). I can foresee the proliferation of tools similar to my Java reloader, connecting Mathematica to other languages, so I value M mostly as a very interactive medium and development laboratory, a tool to create prototypes. Once I see that something is slow, I will localize the problem and use Java or C or some other language. We spend gigantic efforts on optimization while the code can often be written straightforwardly in other langs and save us time. | |
| Jun 23, 2012 at 12:26 | comment | added | Leonid Shifrin | As to performance, I became much more pragmatic about it recently, as I see more and more that the requirement to always stay within Mathematica is artificial. My current thinking is that Mathematica has several layers where it shines, such as 1. High-level (possibly rule-based) - very easy to put new ideas to code 2. Number crunching and other tasks where one can use Compile 3. Data manipulation, where one can use vectorized operations to make it reasonably fast (of course, I only talk about core proramming). But it also has gaps, in particular in the realm of mutable efficient ... | |
| Jun 23, 2012 at 12:08 | comment | added | Leonid Shifrin | There is no question that by using a special syntax you can gain performance, I realized that from the start. The complexities of my solution are due to my attempt to keep the syntax as close to the original as possible. Performance is a valid concern, but not the one raised in the question, so I did not consider it a primary concern as long as the slowdown is not too dramatic (e.g. full order of magnitude or more). Anyway, nice code, and +1. | |
| Jun 23, 2012 at 10:27 | history | edited | Mr.Wizard | CC BY-SA 3.0 | added 1 characters in body; added 2 characters in body; edited body |
| Jun 23, 2012 at 10:19 | history | answered | Mr.Wizard | CC BY-SA 3.0 |