Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
Date: Tue, 09 Dec 2008 17:34:56 -0500
Organization: The MathWorks, Inc.
Lines: 60
Message-ID: <ghmrqg$hq9$1@fred.mathworks.com>
References: <ghmkpn$9ml$1@fred.mathworks.com> <ghml3n$eoe$1@fred.mathworks.com> <ghmlju$ndi$1@fred.mathworks.com> <ghmm6m$7r9$1@fred.mathworks.com> <see-5AE9CC.16502009122008@news.frontiernet.net>
NNTP-Posting-Host: eddinss-lt.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1228862096 18249 172.31.57.98 (9 Dec 2008 22:34:56 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Dec 2008 22:34:56 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
In-Reply-To: <HIDDEN>
Xref: news.mathworks.com comp.soft-sys.matlab:505980


Doug Schwarz wrote:
> In article <ghmm6m$7r9$1@fred.mathworks.com>,
>  "Pithawat " <tanvach+matlab@gmail.com> wrote:
> 
> 
>> But really it's because I'm very surprised MATLAB doesn't have something so 
>> simple as treating array output from a function as array. Just doesn't make 
>> sense to me.
> 
> Yes, it would be nice to be able to write
> 
>   randperm(100)(1:10)
> 
> but the problem is that sometimes the syntax will be ambiguous.  Suppose 
> you have a function, f, that implements the randperm(100) operation, but 
> can operate with no input argument:
> 
>   function x = f(n)
>   if nargin == 0
>       n = 100;
>   end
>   x = randperm(n);
> 
> Now, what does the parser do with
> 
>   f(2)   ?
> 
> Does it call f with no arguments and then return the second value or 
> does it call f with the argument = 2?
> 
> Okay, TMW could define what it does, but it seems to me that this would 
> be a source of confusion, especially for beginners.
> 
> I don't know if that's the reason that it has never been implemented.

That's one of the most important reasons.  Overloading of () to mean 
represent both indexing expressions and function argument lists already 
causes some confusion.

> 
> I wouldn't mind if we were required to supply empty parentheses () if we 
> want to run f with no arguments and maybe that would resolve the 
> ambiguity, but it certainly would break old code.  You'd also have to 
> write things like
> 
>   radians = degrees*pi()/180;
> 

Many of us would like to see this kind of chained indexing supported by 
the language, but the issues mentioned by Doug are hard to address.

It might happen someday.  Or it might not.

I've been at MathWorks for 15 years (as of yesterday!), and this 
discussion has been going on in one form or another for just about the 
whole time.  :-)

---
Steve Eddins
http://blogs.mathworks.com/steve/