<?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: MATLAB Release 2009b &#8211; Best New Feature or ~?</title>
	<atom:link href="http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/</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>Mon, 13 Feb 2012 13:24:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30939</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 05 Jan 2010 12:32:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30939</guid>
		<description>Marc-

That&#039;s not how to use the ~ feature.  Instead, the function would be something like this:

&lt;pre class=&quot;code&quot;&gt;
function myfunc(arg1, ~, arg3)
nargin
&lt;pre&gt;

and nargin returns 3.  You can&#039;t, in the function body, refer to the second input.  It&#039;s there because some other use requires the second input, which this function will totally ignore.

The other use of ~ is to ignore defined outputs. See the example in the post or in the documentation.

--Loren</description>
		<content:encoded><![CDATA[<p>Marc-</p>
<p>That&#8217;s not how to use the ~ feature.  Instead, the function would be something like this:</p>
<pre class="code">
function myfunc(arg1, ~, arg3)<br />
nargin
</pre><pre>
<p>and nargin returns 3.  You can't, in the function body, refer to the second input.  It's there because some other use requires the second input, which this function will totally ignore.</p>
<p>The other use of ~ is to ignore defined outputs. See the example in the post or in the documentation.</p>
<p>--Loren</p>
</pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Marc</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30938</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Mon, 04 Jan 2010 21:10:34 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30938</guid>
		<description>What does the function see for the value of an unused input parameter?  [], or undefined, or something else?  If there are following defined parameters, what does nargin in show?

i.e. if my function is defined as 
&lt;pre&gt;myfunc(argOne, argTwo, argThree)&lt;/pre&gt;

and it&#039;s called like this:
&lt;pre&gt;myfunc(&#039;arg&#039;, ~, &#039;arg&#039;)&lt;/pre&gt;

Is nargin 2, or 3?
Is argTwo undefined or empty or something else?


Thanks</description>
		<content:encoded><![CDATA[<p>What does the function see for the value of an unused input parameter?  [], or undefined, or something else?  If there are following defined parameters, what does nargin in show?</p>
<p>i.e. if my function is defined as </p>
<pre>myfunc(argOne, argTwo, argThree)</pre>
<p>and it&#8217;s called like this:</p>
<pre>myfunc('arg', ~, 'arg')</pre>
<p>Is nargin 2, or 3?<br />
Is argTwo undefined or empty or something else?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30859</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 29 Nov 2009 20:05:21 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30859</guid>
		<description>Ole-

Choosing a symbol is partly a matter of taste, partly a matter to somehow conform to the rest of the language.  We could have chosen _ as you suggest and preferred the looks and the fact that it meant &quot;not&quot; because we thought it would help people realize there was no value available.

--Loren</description>
		<content:encoded><![CDATA[<p>Ole-</p>
<p>Choosing a symbol is partly a matter of taste, partly a matter to somehow conform to the rest of the language.  We could have chosen _ as you suggest and preferred the looks and the fact that it meant &#8220;not&#8221; because we thought it would help people realize there was no value available.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ole Jørgen</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30857</link>
		<dc:creator>Ole Jørgen</dc:creator>
		<pubDate>Sun, 29 Nov 2009 11:03:01 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30857</guid>
		<description>I like this feature, but I don&#039;t get why not underscore was chosen instead. It&#039;s used for the same purpose in other languages and it doesn&#039;t mean anything else already(?) like ~ does (it&#039;s not a valid variable name either)</description>
		<content:encoded><![CDATA[<p>I like this feature, but I don&#8217;t get why not underscore was chosen instead. It&#8217;s used for the same purpose in other languages and it doesn&#8217;t mean anything else already(?) like ~ does (it&#8217;s not a valid variable name either)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30641</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30641</guid>
		<description>Hoi-

Sorry I misunderstood you.  See Steve Lord&#039;s answer regarding keywords.  Introducing new ones also breaks compatibility.

--Loren</description>
		<content:encoded><![CDATA[<p>Hoi-</p>
<p>Sorry I misunderstood you.  See Steve Lord&#8217;s answer regarding keywords.  Introducing new ones also breaks compatibility.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hoi Wong</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30640</link>
		<dc:creator>Hoi Wong</dc:creator>
		<pubDate>Wed, 23 Sep 2009 14:18:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30640</guid>
		<description>Hi Loren,

I&#039;m talking about turning &#039;unused&#039; into keyword that has the same behavior as &#039;~&#039;. That way for R2009b, there won&#039;t be a variable called &#039;unused&#039; to clutter the workspace, yet for older versions it won&#039;t break the code for older versions, as they continue to exist as junk variables. 

Even better, this scheme makes it possible to turn on/off this feature by enabling/disabling the keyword &#039;unused&#039; without breaking any code in any version.

Cheers,
Hoi</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I&#8217;m talking about turning &#8216;unused&#8217; into keyword that has the same behavior as &#8216;~&#8217;. That way for R2009b, there won&#8217;t be a variable called &#8216;unused&#8217; to clutter the workspace, yet for older versions it won&#8217;t break the code for older versions, as they continue to exist as junk variables. </p>
<p>Even better, this scheme makes it possible to turn on/off this feature by enabling/disabling the keyword &#8216;unused&#8217; without breaking any code in any version.</p>
<p>Cheers,<br />
Hoi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve L</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30638</link>
		<dc:creator>Steve L</dc:creator>
		<pubDate>Wed, 23 Sep 2009 13:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30638</guid>
		<description>Tim,

I&#039;m not sure you&#039;re using ~ correctly in post 44.  If by &quot;If MATLAB calls my mexFunction with [x,y]=f(~,b)&quot; you mean that you want to use ~ in the _input_ argument list when you _call_ the function, you can&#039;t do that.  Picture what would happen if you called, for example, PLUS like:

&lt;pre&gt;
y = plus(x, ~);
&lt;/pre&gt;

What would you expect MATLAB to do in this case?  You gave the PLUS function two inputs, as it expected, but you somehow expect it to ignore the second one?

You can use ~ in the _output_ argument list when you call the function (if you don&#039;t care what value the function assigned to that output when you called it) and/or you can use it in the input argument list when you _define_ the function (if you&#039;re going to ignore whatever the caller passed into the function.)  

In a MEX-file, you can&#039;t use ~ in the declaration, but you don&#039;t need to.  You can simply not reference that element of the array containing the right-hand sides, prhs.  In MATLAB, doing that would earn you a warning from M-Lint:

&lt;pre&gt;
function y = myfun(x, t) % t is not used
y = x.^2;
&lt;/pre&gt;

but M-Lint, as the name implies, doesn&#039;t apply to MEX-file source code.  Using ~ in the output argument list of a call to a function works the same way regardless of how the function is implemented -- MEX, M-file, or built-in.

Hoi,

If we&#039;d chosen to create a new keyword for this, it would have the potential to break older code that used the keyword as a variable or function name, as attempting to create a variable whose name is a keyword is an error:

&lt;pre&gt;
for = 4;
&lt;/pre&gt;

and you can&#039;t call a function whose name is a keyword -- the keyword will take precedence.</description>
		<content:encoded><![CDATA[<p>Tim,</p>
<p>I&#8217;m not sure you&#8217;re using ~ correctly in post 44.  If by &#8220;If MATLAB calls my mexFunction with [x,y]=f(~,b)&#8221; you mean that you want to use ~ in the _input_ argument list when you _call_ the function, you can&#8217;t do that.  Picture what would happen if you called, for example, PLUS like:</p>
<pre>
y = plus(x, ~);
</pre>
<p>What would you expect MATLAB to do in this case?  You gave the PLUS function two inputs, as it expected, but you somehow expect it to ignore the second one?</p>
<p>You can use ~ in the _output_ argument list when you call the function (if you don&#8217;t care what value the function assigned to that output when you called it) and/or you can use it in the input argument list when you _define_ the function (if you&#8217;re going to ignore whatever the caller passed into the function.)  </p>
<p>In a MEX-file, you can&#8217;t use ~ in the declaration, but you don&#8217;t need to.  You can simply not reference that element of the array containing the right-hand sides, prhs.  In MATLAB, doing that would earn you a warning from M-Lint:</p>
<pre>
function y = myfun(x, t) % t is not used
y = x.^2;
</pre>
<p>but M-Lint, as the name implies, doesn&#8217;t apply to MEX-file source code.  Using ~ in the output argument list of a call to a function works the same way regardless of how the function is implemented &#8212; MEX, M-file, or built-in.</p>
<p>Hoi,</p>
<p>If we&#8217;d chosen to create a new keyword for this, it would have the potential to break older code that used the keyword as a variable or function name, as attempting to create a variable whose name is a keyword is an error:</p>
<pre>
for = 4;
</pre>
<p>and you can&#8217;t call a function whose name is a keyword &#8212; the keyword will take precedence.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30637</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 23 Sep 2009 10:39:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30637</guid>
		<description>Hoi-

It could be better to use ~ so you don&#039;t clutter your workspace with stuff you don&#039;t need.

Tim-

In your first example, you are looking to query inputs.  Using ~ in your case is really not much different than using [].  In any case, MATLAB doesn&#039;t allow you to optionally use some input if the signature in MATLAB (not C) says it won&#039;t use it.  I think we are designing the C-Mex to mirror MATLAB usage.  So either the function requires input #2 or it doesn&#039;t.

I understand you also want to query whether some outputs are not wanted. Not currently possible in MATLAB or mex.  It is on the wishlist for the future.

--Loren</description>
		<content:encoded><![CDATA[<p>Hoi-</p>
<p>It could be better to use ~ so you don&#8217;t clutter your workspace with stuff you don&#8217;t need.</p>
<p>Tim-</p>
<p>In your first example, you are looking to query inputs.  Using ~ in your case is really not much different than using [].  In any case, MATLAB doesn&#8217;t allow you to optionally use some input if the signature in MATLAB (not C) says it won&#8217;t use it.  I think we are designing the C-Mex to mirror MATLAB usage.  So either the function requires input #2 or it doesn&#8217;t.</p>
<p>I understand you also want to query whether some outputs are not wanted. Not currently possible in MATLAB or mex.  It is on the wishlist for the future.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hoi Wong</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30636</link>
		<dc:creator>Hoi Wong</dc:creator>
		<pubDate>Wed, 23 Sep 2009 05:44:13 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30636</guid>
		<description>Finally! Thanks for implementing this feature. Regarding Cris&#039;s comment on support for older versions, using keywords such as &#039;unused&#039; instead of &#039;~&#039; might be a better move. Who in the right mind will use &#039;unused&#039; to name a variable that they plan to use? 

Loren: any ideas why it&#039;s better to use &#039;~&#039;?</description>
		<content:encoded><![CDATA[<p>Finally! Thanks for implementing this feature. Regarding Cris&#8217;s comment on support for older versions, using keywords such as &#8216;unused&#8217; instead of &#8216;~&#8217; might be a better move. Who in the right mind will use &#8216;unused&#8217; to name a variable that they plan to use? </p>
<p>Loren: any ideas why it&#8217;s better to use &#8216;~&#8217;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30635</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Tue, 22 Sep 2009 20:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/#comment-30635</guid>
		<description>Loren,

Thanks for the feedback.

What I would like is something like this.  If MATLAB calls my mexFunction with [x,y]=f(~,b) then inside the mexFunction f I should be able to query the first and 2nd argument to see if they are really there.

So why not pass me a null pointer for the 1st input argument to my mexFunction?  that&#039;s easy to do, and easy for me to check.  Or pass an empty matrix, and then create a new query function that answers &quot;do you exist?&quot; for any input.  The latter option would be safer, for backward compatibility.

And then for the output arguments, there could be another &quot;do you exist?&quot; query function that I could call.

It would make things like QR a lot easier, which has a boatload of &quot;do this if you have 2 inputs and 1 output, something else if you have 1 input and 1 output, and ...&quot;, and likewise for many other mexFunctions.

These same functions, &quot;do you exist?&quot; applied to inputs and outputs, would be useful for m-file functions too.  Something like this:

&lt;pre&gt;
[x,y]=funky(a,b)
if (~isargpresent(a))
    fprintf (&#039;Hey, you didn&#039;&#039;t pass me anything for a!&#039;)
end
if (~isargpresent(x))
    fprintf (&#039;Whatsa matter?! How come you don&#039;&#039;t want x?&#039;) ;
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>Thanks for the feedback.</p>
<p>What I would like is something like this.  If MATLAB calls my mexFunction with [x,y]=f(~,b) then inside the mexFunction f I should be able to query the first and 2nd argument to see if they are really there.</p>
<p>So why not pass me a null pointer for the 1st input argument to my mexFunction?  that&#8217;s easy to do, and easy for me to check.  Or pass an empty matrix, and then create a new query function that answers &#8220;do you exist?&#8221; for any input.  The latter option would be safer, for backward compatibility.</p>
<p>And then for the output arguments, there could be another &#8220;do you exist?&#8221; query function that I could call.</p>
<p>It would make things like QR a lot easier, which has a boatload of &#8220;do this if you have 2 inputs and 1 output, something else if you have 1 input and 1 output, and &#8230;&#8221;, and likewise for many other mexFunctions.</p>
<p>These same functions, &#8220;do you exist?&#8221; applied to inputs and outputs, would be useful for m-file functions too.  Something like this:</p>
<pre>
[x,y]=funky(a,b)
if (~isargpresent(a))
    fprintf ('Hey, you didn''t pass me anything for a!')
end
if (~isargpresent(x))
    fprintf ('Whatsa matter?! How come you don''t want x?') ;
end
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

