Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Why does everyone hate 'eval'?
Date: Mon, 15 Dec 2008 20:18:03 +0000 (UTC)
Organization: Xoran Technologies
Lines: 43
Message-ID: <gi6e1r$sna$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 1229372283 29418 172.30.248.35 (15 Dec 2008 20:18:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 15 Dec 2008 20:18:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:507170

"Darik" <dgambleDEL@uwaterlooDEL.caDEL> wrote in message <gi654q$sfk$1@fred.mathworks.com>...
> "Matt" <mjacobson.removethis@xorantech.com> wrote in message <ghrujf$d4d$1@fred.mathworks.com>...
> > "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.
> > > 
> > > 
> > 
> > For example, if I tried to evaluate this,
> > 
> > A{i}=SomeObject;
> > 
> > using subsasgn() as follows
> > 
> > S=substruct('{}',{i});
> > A=subsasgn(A,S,SomeObject); 
> > 
> > then it may produce non-equivalent behavior because in the  2nd instance the subsasgn() method of  class(SomeObject) will be called. 
> > It takes precedence over the built-in subsasgn methods for @cell types.
> > 
> > However, what does one do if S is in some way dynmically varying?
> > 
> > Maybe I'm running assignments to A in a loop and in one instance S is as above but in later iterations of the loop I have any or both of the following
> > 
> > S=substruct('{}',{i},'{}',{j}) 
> > S=substruct('{}',{i,j}) 
> > 
> > The only solution I've ever been able to find is to derive an indexing expression for each such S in string form and execute it using eval().
> > 
> > If I'm missing a basic alternative though, I welcome advice...
> > 
> 
> Just wanted to point out there's the function BUILTIN for this exact reason.


Probably worth a try. 

I was never sure if builtin() actually works, but that might be because I was trying to use it to overload help(), which is not a .bi file.