Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Sat, 7 Feb 2009 15:24:01 +0000 (UTC)
Organization: Xoran Technologies
Lines: 56
Message-ID: <gmk92h$ls9$1@fred.mathworks.com>
References: <ghrlim$oqo$1@fred.mathworks.com> <ghrsc8$194$1@fred.mathworks.com> <ghrujf$d4d$1@fred.mathworks.com> <gi654q$sfk$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234020241 22409 172.30.248.35 (7 Feb 2009 15:24:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 7 Feb 2009 15:24:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:516792


> > "Matt" <mjacobson.removethis@xorantech.com> wrote in message <ghrsc8$194$1@fred.mathworks.com>...
> > > 
> > > The one time that I have found eval() indispensible is in creating overloaded subsref/subsasgn methods for classes.
> > > 
> > > Calling subsref()/subsasgn() by themselves is known to produce unpredictable behavior because of dispatching rules, but if you execute the equivalent expression using eval this tends not to happen.
------------------------------------


"Darik" <dgambleDEL@uwaterlooDEL.caDEL> wrote in message <gi654q$sfk$1@fred.mathworks.com>...
> Just wanted to point out there's the function BUILTIN for this exact reason.
-----------------------------------

Unfortunately, bulitin() is not a perfect solution, since it doesn't seem to handle multiple output arguments very well.

Consider the following structure

v.a={1 2 3};

I will try to get the effect of typing v.a{:} in two different ways, one with eval() and one with builtin():

CASE 1: EVAL


>>s=substruct('.','a','{}',{':'});

>>z='.a{s(2).subs{:}}'

>> eval(['v' z ]) %works fine, same ouput as v.a{:}

ans =

     1


ans =

     2


ans =

     3



CASE 2: BUILTIN

>> builtin('subsref', v,s) %problems with expected number of outputs

ans =

     1


So eval() works where builtin() fails...