Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica scoping / contexts / variable localization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105110] Re: Mathematica scoping / contexts / variable localization
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Sat, 21 Nov 2009 03:34:21 -0500 (EST)
  • References: <32142906.1258547432910.JavaMail.root@n11> <he36g8$efk$1@smc.vnet.net>

hi David;

"David Park" <djmpark at comcast.net> wrote in message 
news:he36g8$efk$1 at smc.vnet.net...

>
> Clear[a, b]
>
> ClearAll[f]
> f[a_, b_][x_] := Exp[-a x] Sin[b x]
>
> Plot[f[.5, 3][x], {x, 0, 6}]
>

How about also using the above, but also use /. to assign values to 
parameters.

Plot[f[a, b][x] /. {a -> .5, b -> 3}, {x, 0, 6}]

You are right, I am finding that if one is very aware and disciplined during 
programming Mathematica then can side step many common problems, because in 
Mathematica it is more easy to fall into subtle problems for new users than 
in other programming languages. If one is slightly sleepy while programming 
in Mathematica, then many strange problem will show up later on.

I also wish that Mathematica error handling can be improved in the sense 
that when some error shows up in some long running code, that at least it 
would tell me on which _line_ the error happened.  not just some error 
message telling me that I can do this or that.

It seems that, when this happens, I spend more time trying to figure where 
the error is coming from because the error message never tells me where this 
error is, even though it must have known. It does not even tell me which 
function it was in.

If there was an easy to use debugger, I could run the code inside it, 
telling it to stop when an error or warning occurs, and this way  I know 
exactly where the error was. But there is no such thing in Mathematica. 
(Please do not tell me to use this so called debugger in Mathematica 7, 
under Evaluation, I tried, and have no idea how it is supposed to work).

I hope this error handling improves in next version of Mathematica, and 
please make the debugger like a _normal_ and standard debugger is supposed 
to be.

May be what we also need is like what David had here, a set of articles that 
talks just about good programming styles for Mathematica, or good "patterns" 
to follow, targeted to users like most of us, who are not expert Mathematica 
programmers. I think this will be very useful.

thanks,
--Nasser 



  • Prev by Date: Re: More Efficient Method
  • Next by Date: Re: More Efficient Method
  • Previous by thread: Re: Re: Mathematica scoping / contexts / variable
  • Next by thread: Re: Mathematica scoping / contexts / variable localization