Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news2!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe03.iad.POSTED!7564ea0f!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
References: <ghrlim$oqo$1@fred.mathworks.com> <ghromj$f8g$1@fred.mathworks.com> <ghrplu$4in$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-38C92E.18085111122008@news.frontiernet.net>
Lines: 39
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Thu, 11 Dec 2008 23:08:50 UTC
Organization: Frontier
Date: Thu, 11 Dec 2008 18:08:51 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:506443


In article <ghrplu$4in$1@fred.mathworks.com>,
 "Johan Carlson" <Johan.E.Carlson@gmail.com> wrote:

> Thanks everyone!
> I read most of the threads you linked before, and I agree that readability 
> and efficiency should be put before the lazy way out (using eval).
> 
> Now, if everything could be done without eval, why is it still there?

Backwards compatibility.


> In previous versions of MATLAB, before cell arrays etc. there were some cases 
> that became really complicated (thus rendering much less readable code), but 
> nowadays, maybe the function is not necessary anymore.
> 
> The security issue is a good point! 
> 
> /JC


If you really need to create variables you can use assignin inside a 
function.  It should be safer and more readable than eval.

  function assign(varname,value)
  assignin('caller',varname,value)



>> assign('x1',1)
>> x1
x1 =
     1
>>

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.