From: "Steven Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Mon, 15 Dec 2008 10:54:25 -0500
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <gi5ujh$b3d$>
References: <ghrlim$oqo$> <ghv5ut$fj7$>
Reply-To: "Steven Lord" <>
X-Trace: 1229356465 11373 (15 Dec 2008 15:54:25 GMT)
NNTP-Posting-Date: Mon, 15 Dec 2008 15:54:25 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: comp.soft-sys.matlab:507110

"us " <> wrote in message 
> "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...

I don't believe that's correct.  One use case that I haven't been able to 
think of a way to handle without using EVAL is converting a user-input 
string into an anonymous function.  [And yes, I filed an enhancement request 
for a way to do this, perhaps by enhancing STR2FUNC, back when anonymous 
functions were first under development.]  This would be useful for working 
with the "function functions".

function y = stringToAnonymous(str, vars)
y = eval(['@(' vars ') ' str]);

Steve Lord