<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Thoughts about Anonymous Functions</title>
	<atom:link href="http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Wed, 12 Jun 2013 12:35:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33181</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Fri, 28 Sep 2012 17:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33181</guid>
		<description><![CDATA[Interesting suggestion, Eric.  Please enter that as an enhancement request.  You can use the Technical Support link on the right of my blog.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Interesting suggestion, Eric.  Please enter that as an enhancement request.  You can use the Technical Support link on the right of my blog.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33180</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 28 Sep 2012 17:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33180</guid>
		<description><![CDATA[Thanks Loren (sorry for the name mixup earlier, I had just been talking to someone named Lori :)

I understand your point, I suppose I just haven&#039;t had the need to use arrays/strings/etc in an anonymous function.

What do you think about modifying DISP to display the workspace contents captured in the anonymous function, using a display format similar to WHOS? I&#039;m thinking something like this:


&gt;&gt; a = 1;
&gt;&gt; b = rand(10);
&gt;&gt; c = &#039;test&#039;;
&gt;&gt; fn = @(x) a*x.^2

fn = 

    @(x)a*x.^2

Captured variables:
  Name       Size            Bytes  Class              Attributes

  a          1x1                 8  double                       
  b         10x10              800  double                       
  c          1x4                 8  char                         
]]></description>
		<content:encoded><![CDATA[<p>Thanks Loren (sorry for the name mixup earlier, I had just been talking to someone named Lori :)</p>
<p>I understand your point, I suppose I just haven&#8217;t had the need to use arrays/strings/etc in an anonymous function.</p>
<p>What do you think about modifying DISP to display the workspace contents captured in the anonymous function, using a display format similar to WHOS? I&#8217;m thinking something like this:</p>
<p>&gt;&gt; a = 1;<br />
&gt;&gt; b = rand(10);<br />
&gt;&gt; c = &#8216;test&#8217;;<br />
&gt;&gt; fn = @(x) a*x.^2</p>
<p>fn = </p>
<p>    @(x)a*x.^2</p>
<p>Captured variables:<br />
  Name       Size            Bytes  Class              Attributes</p>
<p>  a          1&#215;1                 8  double<br />
  b         10&#215;10              800  double<br />
  c          1&#215;4                 8  char                         </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33173</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Thu, 27 Sep 2012 12:05:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33173</guid>
		<description><![CDATA[Eric-

We intentionally do not show values in anonymous function displays.  What if the variables to display had size 1000x1000; would you really want to see that?  Doubtful.  Technically, you can have a new function that you use to show that information, and possibly could overload display.

Please feel free to request this as an enhancement using the link to Technical Support on the right of my blog.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Eric-</p>
<p>We intentionally do not show values in anonymous function displays.  What if the variables to display had size 1000&#215;1000; would you really want to see that?  Doubtful.  Technically, you can have a new function that you use to show that information, and possibly could overload display.</p>
<p>Please feel free to request this as an enhancement using the link to Technical Support on the right of my blog.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33171</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Wed, 26 Sep 2012 23:43:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33171</guid>
		<description><![CDATA[Thanks Lori, it will be very nice when anonymous functions only grab referenced variables.

Do you think the DISP function could be modified to show the value of the captured variables, instead of the variable names? This would help people realize that they are indeed captured/frozen instead of taking on new &#039;live&#039; values at the time of execution...

for instance:

&gt;&gt; a = 3.14;
&gt;&gt; fn = @(x) a*x.^2

fn =

     @(x) 3.14*x.^2  % instead of current @(x) a*x.^2

&gt;&gt;]]></description>
		<content:encoded><![CDATA[<p>Thanks Lori, it will be very nice when anonymous functions only grab referenced variables.</p>
<p>Do you think the DISP function could be modified to show the value of the captured variables, instead of the variable names? This would help people realize that they are indeed captured/frozen instead of taking on new &#8216;live&#8217; values at the time of execution&#8230;</p>
<p>for instance:</p>
<p>&gt;&gt; a = 3.14;<br />
&gt;&gt; fn = @(x) a*x.^2</p>
<p>fn =</p>
<p>     @(x) 3.14*x.^2  % instead of current @(x) a*x.^2</p>
<p>&gt;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33170</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Wed, 26 Sep 2012 15:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33170</guid>
		<description><![CDATA[Navin-

I don&#039;t understand your comment/code for the stand-alone cases you mention, especially @(x)@(y).

Your understanding of the meanings of the other calls is correct.

I am not clear what you want to see about multi-variable inputs.  Can you say more?

--Loren]]></description>
		<content:encoded><![CDATA[<p>Navin-</p>
<p>I don&#8217;t understand your comment/code for the stand-alone cases you mention, especially @(x)@(y).</p>
<p>Your understanding of the meanings of the other calls is correct.</p>
<p>I am not clear what you want to see about multi-variable inputs.  Can you say more?</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Navin</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33169</link>
		<dc:creator>Navin</dc:creator>
		<pubDate>Wed, 26 Sep 2012 13:54:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33169</guid>
		<description><![CDATA[I&#039;ve been using Anonymous functions for over a year now, primarily as arguments for the fmincon() function [used for constrained non-linear optimization]. 
I&#039;ve to admit, though, I&#039;d never understood its full potential, and after reading thru this nice article, more doubts haunt me.

For instance, in standalone cases, I haven&#039;t see any difference while creating or calling anonymous functions with @(x) or @(x,y) or @(x)@(y).

As regards the above article, my understanding of the following lines of code is that:


myline = @(x) straightline(x,m,b);

is equivalent to myline(x); 
and that
 
slopeIntercept = @(slope,intercept) straightline(data, slope, intercept);

is equivalent to slopeIntercept(slope,intercept), which in turn invokes straightline(...).


newline1 = @(X) straightline(X, slp(1), intcpt(1));

translates as newline1(X), which then calls straightline().


differentLine = @(slope, intercept, X) straightline(X, slope, intercept);

is the same as calling straightline() with a different order of parameters.
Please correct me if I&#039;m wrong.

Could you shed further light on the issue, including multi-variable anonymous functions, &amp; if possible,  illustrate with examples where necessary?

Further, in case anyone&#039;s used fmincon(), could you please share your experience and explain further? For instance, is it possible to optimize the function with multiple variables, in which case, you might need to use multi-variable anonymous functions as arguments to the objective function &amp; the constraint function?

Thanks,
Navin.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ve been using Anonymous functions for over a year now, primarily as arguments for the fmincon() function [used for constrained non-linear optimization].<br />
I&#8217;ve to admit, though, I&#8217;d never understood its full potential, and after reading thru this nice article, more doubts haunt me.</p>
<p>For instance, in standalone cases, I haven&#8217;t see any difference while creating or calling anonymous functions with @(x) or @(x,y) or @(x)@(y).</p>
<p>As regards the above article, my understanding of the following lines of code is that:</p>
<p>myline = @(x) straightline(x,m,b);</p>
<p>is equivalent to myline(x);<br />
and that</p>
<p>slopeIntercept = @(slope,intercept) straightline(data, slope, intercept);</p>
<p>is equivalent to slopeIntercept(slope,intercept), which in turn invokes straightline(&#8230;).</p>
<p>newline1 = @(X) straightline(X, slp(1), intcpt(1));</p>
<p>translates as newline1(X), which then calls straightline().</p>
<p>differentLine = @(slope, intercept, X) straightline(X, slope, intercept);</p>
<p>is the same as calling straightline() with a different order of parameters.<br />
Please correct me if I&#8217;m wrong.</p>
<p>Could you shed further light on the issue, including multi-variable anonymous functions, &amp; if possible,  illustrate with examples where necessary?</p>
<p>Further, in case anyone&#8217;s used fmincon(), could you please share your experience and explain further? For instance, is it possible to optimize the function with multiple variables, in which case, you might need to use multi-variable anonymous functions as arguments to the objective function &amp; the constraint function?</p>
<p>Thanks,<br />
Navin.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33165</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Tue, 25 Sep 2012 20:10:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33165</guid>
		<description><![CDATA[Eric-

The long-term plan is to have anonymous functions pick up only what they need from the environment.  That is on the enhancement list for the language.  For now, there is no way to avoid it - best to create the anonymous functions from a function if memory is an issue.

It would be helpful if you submitted the other wording and doc enhancements on mathworks.com.  Thanks.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Eric-</p>
<p>The long-term plan is to have anonymous functions pick up only what they need from the environment.  That is on the enhancement list for the language.  For now, there is no way to avoid it &#8211; best to create the anonymous functions from a function if memory is an issue.</p>
<p>It would be helpful if you submitted the other wording and doc enhancements on mathworks.com.  Thanks.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33164</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Tue, 25 Sep 2012 16:25:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33164</guid>
		<description><![CDATA[Loren, is there any possibility of changing the way that anonymous functions snapshot their environment, so that only variables that are explicitly reference in the anonymous function definition are stored in it? From my brief thinking, the only behavior change that this would introduce is if existing user code plays &#039;games&#039; with eval() in the anonymous function to access the non-explicitly referenced variables - this would no longer work, but do you think many users do this? It&#039;s not documented functionality...

The current behavior can be unnecessarily memory/HD intensive, and in my experience has caught many programmers off guard... This is not helped by the fact that the documentation makes it sound like they only store referenced variables: http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html . Also, the wording of the following phrase could be improved, from &quot;To supply different values for the coefficients, you must create a new function handle:&quot; to &quot;...you must redefine the function handle:&quot;

Cheers]]></description>
		<content:encoded><![CDATA[<p>Loren, is there any possibility of changing the way that anonymous functions snapshot their environment, so that only variables that are explicitly reference in the anonymous function definition are stored in it? From my brief thinking, the only behavior change that this would introduce is if existing user code plays &#8216;games&#8217; with eval() in the anonymous function to access the non-explicitly referenced variables &#8211; this would no longer work, but do you think many users do this? It&#8217;s not documented functionality&#8230;</p>
<p>The current behavior can be unnecessarily memory/HD intensive, and in my experience has caught many programmers off guard&#8230; This is not helped by the fact that the documentation makes it sound like they only store referenced variables: <a href="http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html" rel="nofollow">http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html</a> . Also, the wording of the following phrase could be improved, from &#8220;To supply different values for the coefficients, you must create a new function handle:&#8221; to &#8220;&#8230;you must redefine the function handle:&#8221;</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33160</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Mon, 24 Sep 2012 15:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33160</guid>
		<description><![CDATA[Carl - 

I understand the desire for multi-statement anonymous functions.  Right now, plot returns handles to the entities that are plotted, not to their axes.  

If I understand your example, you would like that to change maybe (in addition to the multi-statements)?

--Loren]]></description>
		<content:encoded><![CDATA[<p>Carl &#8211; </p>
<p>I understand the desire for multi-statement anonymous functions.  Right now, plot returns handles to the entities that are plotted, not to their axes.  </p>
<p>If I understand your example, you would like that to change maybe (in addition to the multi-statements)?</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://blogs.mathworks.com/loren/2012/08/29/thoughts-about-anonymous-functions/#comment-33159</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Mon, 24 Sep 2012 00:02:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=515#comment-33159</guid>
		<description><![CDATA[What I&#039;m sure Drzick and Bogdan meant is to create multi-statement anonymous functions. It&#039;s the one thing R has I wish MATLAB had.

I&#039;d love to be able to write something like

doubleplot = @(x,a,b) ...
   subplot(1,2,1),varargout{1} = plot(x,a); ...
   subplot(1,2,2),varargout{2} = plot(x,b);


... and then be able to call

[ha hb] = doubleplot([1 2],[1 1],[2 1]);


... and see two subplots appear in the Figure and two handles to axes objects appear in the workspace.]]></description>
		<content:encoded><![CDATA[<p>What I&#8217;m sure Drzick and Bogdan meant is to create multi-statement anonymous functions. It&#8217;s the one thing R has I wish MATLAB had.</p>
<p>I&#8217;d love to be able to write something like</p>
<p>doubleplot = @(x,a,b) &#8230;<br />
   subplot(1,2,1),varargout{1} = plot(x,a); &#8230;<br />
   subplot(1,2,2),varargout{2} = plot(x,b);</p>
<p>&#8230; and then be able to call</p>
<p>[ha hb] = doubleplot([1 2],[1 1],[2 1]);</p>
<p>&#8230; and see two subplots appear in the Figure and two handles to axes objects appear in the workspace.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
