Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 1
    $\begingroup$ I think as soon as you start thinking about modifying a single element (setParam), your approach looses expressiveness, because within it this operation is not natural. If you go further down that road (I was actually doing this too, for a while), you end up with another emulation of mutable structures, and not the best one, because you are copying stuff (e.g. you have copy - internally - and traverse the entire parameter list to modify a single element - so your assignemnt is strictly speaking not constant time). $\endgroup$ Commented Jan 30, 2012 at 15:50
  • $\begingroup$ @Leonid, well, but these lists tend to be rather small, so performance is not an issue. At least not for the things I was using them for. This does not become slow if we have a large parameter value, only if we have a large number of parameters. It's like Append. $\endgroup$ Commented Jan 30, 2012 at 15:53
  • 4
    $\begingroup$ I don't think it should be called "quick and dirty". I think this is the best solution here. It has an added advantage that you can just add new rules modifying your parameters in a batch, and rule-application mechanism will take care of the rest. You can, if you wish, factor this into a separate function. But what I'd do within this approach, instead, is to define configurations. The key to expressiveness is composition. Here is what I'd do: config[newrules__]@config[rules__] := config[newrules, rules];. It's really that simple, and we can assign these to variables and get ... $\endgroup$ Commented Jan 30, 2012 at 16:37
  • 1
    $\begingroup$ Just one observation (which doesn't seem to have been made above): With the definition of params as list of rules you also can extract (but not set) a specific value using OptionValue[params, par1]. $\endgroup$ Commented May 25, 2012 at 12:54
  • 1
    $\begingroup$ @mcandril: I've just now seen your comment. In case it's still relevant for you: I think simply using //. instead of /. would solve that issue. For example, {a,b} /. { a->1, b->x+a } gives {1, a + x}, but {a,b} //. { a->1, b->x+a } gives {1, 1 + x}. $\endgroup$ Commented Jul 16, 2014 at 11:53