Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Sat, 13 Dec 2008 16:16:02 +0000 (UTC)
Organization: NTNU
Lines: 22
Message-ID: <gi0n41$ap4$1@fred.mathworks.com>
References: <ghrlim$oqo$1@fred.mathworks.com> <ghv5ut$fj7$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1229184962 11044 172.30.248.37 (13 Dec 2008 16:16:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 13 Dec 2008 16:16:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 651407
Xref: news.mathworks.com comp.soft-sys.matlab:506745

"us " <us@neurol.unizh.ch> wrote in message <ghv5ut$fj7$1@fred.mathworks.com>...
> "Johan Carlson"
> > I've been running into comments like "NO, NO, NO, WHATEVER YOU DO,  DO NOT USE EVAL!!!!' in various posts during the past few weeks...
> 
> these lovely people are absolutely correct - and - let me add this, after having used > ML for 26 years - there is absolutely NO evil eval, which you cannot possibly replace >by a genuine string of ML commands or stock functions...
> 
> us

Then maybe you can help me out.

I have the name of a Matlab class stored in a string variable, S. I would like to construct a metaclass object for the class named in the variable, S. Right now I'm doing
>> mc = eval(['?',S]);
or,
>> mc = metaclass(eval(s));

How can I avoid using eval here? Mathwork support has been unable to help me.

NB! Note that in the 2008a-documentation it says that you can do
>> mc = metaclass(S);
This is wrong and has been corrected in the newer documentation.

?yvind