Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe02.iad.POSTED!7564ea0f!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-5AE9CC.16502009122008@news.frontiernet.net>
Lines: 45
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Tue, 09 Dec 2008 21:50:18 UTC
Organization: Frontier
Date: Tue, 09 Dec 2008 16:50:20 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:505971


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.

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;

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.