[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Default arguments
From: |
John W. Eaton |
Subject: |
Re: Default arguments |
Date: |
Mon, 18 Dec 2006 19:53:14 -0500 |
On 18-Dec-2006, Søren Hauberg wrote:
| Søren Hauberg skrev:
| >> Although I've checked this patch in to the CVS archive, I consider it
| >> to be quite experimental. If any nontrivial problems show up that are
| >> related to this change, I'll simply remove it.
| > I can't really test this until sometime next week (I have a hard
| > deadline on monday), but then I'll report back...
| Okay, I've done a CVS checkout to play around with your changes. I
| haven't found any real problems, but there is one thing, that _might_
| cause problems.
|
| The following function works:
|
| function out = myfun(a = 2, b = sin(a))
| out = a + b;
| endfunction
|
| but this doesn't:
|
| function out = myfun(a = sin(b), b = 2)
| out = a + b;
| endfunction
|
| Now, I can understand why this is the case, but I'm affraid that it
| could cause confusion, i.e. "why doesn't my function work anymore? I've
| just switched the order of the input arguments."
|
| Otherwise, it appears to be working quite nicely,
I suppose we should
* document that function arguments are evaluated left to right,
which means that the first case is OK but second is not
or
* document that the order of evaluation of function arguments is
undefined (more freedom for the interpreter/compiler) in which
case neither can be expected to work
If we choose the second case, it might be nice to have a warning or
error but I don't see an easy way to make that happen.
jwe
- Re: Default arguments, (continued)
- Re: Default arguments, John W. Eaton, 2006/12/15
- Re: Default arguments, Sean O'Rourke, 2006/12/15
- Re: Default arguments, Dmitri A. Sergatskov, 2006/12/15
- Re: Default arguments, John W. Eaton, 2006/12/15
- Re: Default arguments, Paul Kienzle, 2006/12/16
- Re: Default arguments, Tom Holroyd (NIH/NIMH) [E], 2006/12/15
Default arguments, John W. Eaton, 2006/12/14