Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
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$1@fred.mathworks.com>
References: <ghrlim$oqo$1@fred.mathworks.com> <ghv5ut$fj7$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1229356465 11373 144.212.105.187 (15 Dec 2008 15:54:25 GMT)
X-Complaints-To: news@mathworks.com
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: news.mathworks.com comp.soft-sys.matlab:507110


"us " <us@neurol.unizh.ch> wrote in message 
news: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...

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
slord@mathworks.com