Possible Duplicate:
How to avoid nested With[]?

I have many situations where I have a constant that is local to a function, with other constants that are computed from it. I see that I can implement this using nested With statements, like

leapSeconds = With[{
   usnoData = 
    Import["http://maia.usno.navy.mil/ser7/tai-utc.dat", "Text", 
     CharacterEncoding -> "UTF8"]},
    lineLength = StringPosition[usnoData, "\n"][[1, 1]],
    lsCount = Length[StringCases[usnoData, "\n"]] + 1},
   DateList[#] & /@ (StringTake[
        usnoData, {2 + #*lineLength, 9 + #*lineLength}] & /@ 
      Range[0, lsCount - 1])]]

but this seems cumbersome. Is there a better way to do this sort of thing (I know that for this example I could dispense with the constants, but assume for the exercise that I do indeed need the constants)? Is nesting With statments a reasonable approach, or something I've just come up with by not understanding Mathematica very well?

  • $\begingroup$ Yes, duplicate question. Though the answers there don't really address the point. $\endgroup$
    – orome
    Dec 4, 2012 at 19:09
  • $\begingroup$ Then I don't see what the question is. My answer is this: yes, this situation is very common in practice, and then I use LetL, described in my answer to that question. The only other option is to separate every single constant's computation into a separate function, and then chain those functions, but often this may not be desirable, both because of extra boilerplate of parameter-passing, and because those new functions may not be general enough to justify their existence. $\endgroup$ Dec 4, 2012 at 19:13
  • $\begingroup$ Yes, sorry, I wasn't clear: closing is fine. $\endgroup$
    – orome
    Dec 4, 2012 at 19:16
  • $\begingroup$ I think this could probably be reformulated in a way which would emphasize that you are looking for alternative solutions. If that's so, it does not have to be closed. $\endgroup$ Dec 4, 2012 at 19:19
  • $\begingroup$ @LeonidShifrin: Actually, it's more the opposite: I'm interested in whether this is what the community commonly does in this such situations. $\endgroup$
    – orome
    Dec 4, 2012 at 19:29


Browse other questions tagged or ask your own question.