Timeline for How to pass a symbol name to a function with any of the Hold attributes?
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 24, 2012 at 0:29 | comment | added | Oleksandr R. | @Ajasja: yes, there shouldn't be any evaluation leaks as the arguments are passed right through with the symbols dereferenced. The approach is so simple that I'm sure you'll be able to find some corner cases, but for typical usage I think it is robust enough (at least, better than using strings, which was the main point here). | |
| May 23, 2012 at 8:00 | comment | added | Ajasja | Thanks! I actually tried that, but it was giving me a warning that went away upon restarting a fresh kernel. Is it safe to use this with SetDelayed as well? | |
| May 22, 2012 at 22:04 | comment | added | Oleksandr R. | @Ajasja: Yes, just write AppendTo[$dereferencingFunctions, Set] and it works automatically. (This won't work for list assignments, like {q, referenceTo[r], referenceTo["s"]} = {1, 2, 3}, though. Some changes would be needed to support that.) | |
| May 22, 2012 at 12:54 | comment | added | Ajasja | Would it be possible to extend this approach, so that this would work as expected x=5; referenceTo["x"] = 15; x? In other words, so that variables could be set by reference as well? | |
| Mar 7, 2012 at 1:49 | comment | added | István Zachar | While I agree with you that a proper wrapper for referencing would be the best solution, at the moment I still try to solve my issues with structural replacements. Your solution seems robust, but I wouldn't say it is simple. At least not at 2am :) | |
| Mar 7, 2012 at 1:24 | history | edited | Oleksandr R. | CC BY-SA 3.0 | Expanded examples with another use case |
| Mar 7, 2012 at 1:12 | history | answered | Oleksandr R. | CC BY-SA 3.0 |