Re: how eval works?



Steven Lord wrote:

"abir basak" <abirbasak@xxxxxxxxx> wrote in message
news:ef3b5eb.20@xxxxxxxxxxxxxxxxxxxxxxxxxx
It looks to me Matlab is slightly confusing when it parses the code
beforehand (I think generated p file?) , and when it do at the time
of execution. Also it confusing when it compiles the code & when not
( I have heard Matlab doesn't JIT accelerate code if it exceeds a
certain line of code). Any way to know both status?
Moreover I still dont get, in function when it parses, why it dont
substitute the content of eval, evalf or such functions directly into
the code? In that case there won't be any confusion.


function y = foo(x)
s = input('Type the variable name now: ', 's');
eval(sprintf('%s = %d', s, x))
y = eval(s);


It's impossible to know at parse time the variable name the user will enter
when the function executes, and therefore you can't just replace the EVAL
with the corresponding code. You can also run into this situation if you
"poof" variables into a function workspace using LOAD -- should we
therefore, during parsing, load every MAT-file that you try to load in your
code to see if you have a variable in there? Note that this also runs into
the situation where you may not know what MAT-file is going to be loaded --
it's just as easy to prompt the user for a filename as it is to prompt for a
variable name.

I think, there is a difference in the example what I had given & yours.
Input is not a function/subroutine in that sense, it is interrupt/ISR.
Thus, it cas of input, you dont really know the variable name in
advance, but still you can issue an warning while you are actually
evaluating it, which can be catched by the program. On the other hand,
when you are loading a file etc, wich does not get anything from user,
can be safely evaluated.
(I even expect matlab pre schedules the file load as IO is slow, and
commit the variables at the workspace in actual place. Thus, you can
always fore-see the future name conflict.)
abir
The way I look at it:

1) You shouldn't use EVAL unless you absolutely, positively can't do what
you want without it or unless you know exactly what you're doing.

Yes, I agree with you at this point that eval (or any reflection)
should not be used untill you come to a point where you know the
information not available to the developer, rather available to the
user, and should not be used in processing loop. I used eval to load
something only,not to process something.

2) If you try hard enough, it's possible to write really ugly and really
dangerous code. It's easier to do so with EVAL.

Definitely. The problem with matlab, is that if you follow good
programming, it will run slower, while a low level (I dont say poor in
that sense), It will run faster, on contrary to other HLL's. (Most time
I use an array of pointers & another set of array of values rather than
array of struct to store the information, which is simplier); and
allocate all these array's manually at a chunk. I gain both in memory
& speed drastically) But the point is, how much one can go in low
level, while you are doing a big enough project?
*snip*

--
Steve Lord
slord@xxxxxxxxxxxxx

.



Relevant Pages

  • Re: UPA board blog -- new post about observers for league play
    ... its just that i dont really trust it for one. ... is a little confusing  to me. ... i think you got me confused with jim parenella there. ... crying in ultimate in my world. ...
    (rec.sport.disc)
  • Re: Question on water pressure on dam
    ... Dont forget I proved your a dumbass and a fool. ... I can make anyone the owner of any ship on the planet thats for sale. ... I understand all the math. ... I can load 3000 tons of ship off the bottom ad load it in a a few ...
    (sci.physics)
  • Re: websites that use to work dont work anymore
    ... Both of those sites have huge banner images which are first to load. ... >>> websites that use to work dont work anymore,some sites that use to work ... >>> work anymore for some reason, i noe theres alot of other people lyk ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: overload operator<<
    ... Your reaction about confusing symbols is understandable I think, ... I dont understand is the hidden agressive part. ... I am still new to .net and had not yet worked with the Encoding ... >you're reading a multi-byte character and only get the start of it. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Utility to optimize RAM, virtual memory and monitor applications u
    ... they the system coonfiguration utility will load up. ... you dont really need them all you have to do is click on ... and then uncheck the load startyo ITEMS and click on ok then your winodws ... will ask you to restart, and after that you will see a message saying you ...
    (microsoft.public.windowsxp.general)