Baffling colon behaviour

  • Follow


I am puzzled by the following (observed in 2009a 64 bit Linux and 2010a 64 bit Windows):

>> [a, b, c] = deal(1, :, 2);
>> strcmp(b, ':')

ans =

     1

I can't fit this into any of my mental schema relating to how things should work, or find any documentation that would explain it. I feel I must be missing something (quite possible at 1 am, as it is here) - can anyone shed any light please?

I can't find a bugreport, but I'm beginning to wonder if I've found a bug.

(For anyone who doesn't see the problem: deal is a function, not an array. You'd expect a naked colon to be meaningless as an argument, and for the first line of my example to cause an error. To get a string back is very strange.)
0
Reply David 3/30/2010 12:23:02 AM

Using 2007b:

>> [a, b, c] = deal(1, :, 2);
??? At compilation, "deal" was determined to be a variable and this
 variable is uninitialized.  "deal" is also a function name and previous versions of MATLAB would have called the function.
 However, MATLAB 7 forbids the use of the same name in the same
 context as both a function and a variable.

What does:
>>which deal
say?
0
Reply Matt 3/30/2010 12:51:05 AM


"Matt Fig" <spamanon@yahoo.com> wrote in message <horhtp$q5e$1@fred.mathworks.com>...
> What does:
> >>which deal
> say?

>> which deal
C:\Program Files\MATLAB\R2010a\toolbox\matlab\datatypes\deal.m
0
Reply David 3/30/2010 12:59:08 AM

Matt: thanks, that's given me something to think about. In 2010a the behaviour you see is preserved (with a shorter message) if there are only 2 arguments to deal:

>> [a, b] = deal(1,:)
??? Undefined variable deal.

I can understand this: if there's a naked colon, then deal must be a variable not a function, it's not defined, so error.

It's looking increasingly as if there is a bug for more than 2 arguments: the function is being called, and a representation of the lexical token is being passed to it without any attempt at evaluation.
0
Reply David 3/30/2010 1:07:06 AM

Did they change DEAL.m?  Is it still just basically:

varargout = varargin;

or what?
0
Reply Matt 3/30/2010 1:29:07 AM

"Matt Fig" <spamanon@yahoo.com> wrote in message <hork53$pjn$1@fred.mathworks.com>...
> Did they change DEAL.m?  Is it still just basically:
> 
> varargout = varargin;
> 
> or what?

It's not a problem with deal - I was just using deal to demonstrate the problem. It's any case where a naked colon appears as one of three arguments to a function.
0
Reply David 3/30/2010 6:30:08 AM

5 Replies
237 Views

(page loaded in 0.04 seconds)


Reply: