octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default arguments


From: Dmitri A. Sergatskov
Subject: Re: Default arguments
Date: Fri, 15 Dec 2006 10:23:17 -0700

On 12/15/06, Sean O'Rourke <address@hidden> wrote:
My bad.

/s

-----------------------------------------------------------------

Please reply on the list so the discussion is kept archived and public
for others to comment.

Thanks,

jwe

On 15-Dec-2006, Sean O'Rourke wrote:

| "John W. Eaton" <address@hidden> writes:
| > One problem I have with keyword arguments is that if they are
| > allowed for any function argument, then you have to carefully
| > choose the names of all function parameters, and once you've
| > selected them, you can't change them without the potential for
| > breaking a lot of code.
|
| This is a significant constraint on library code (octave and
| octave-forge), but within your own code it seems manageable, and
| these kinds of interface decisions should be finalized before
| code is widely distributed.  I haven't had much trouble either
| with Lisp or with the current "'key', value" approach in Octave.
|
| > There would also be problems with the way variable arguments
| > are overloaded in some Matlab functions.
|
| I would propose that only arguments with default values can be
| passed using keywords, since non-optional keyword arguments are
| just strange.  That way there's no impact on existing functions.
|
| /s



This all starting to remind me IDL, that has both positional and keyword
parameters for functions and procedures. Here is a snip from its manual:

<<<<
The correspondence between the actual parameters of the caller and the
formal parameters of the called procedure is established by position
or by keyword.

Positional Parameters (Arguments)

A positional parameter, or plain argument, is a parameter without a
keyword. Just as its name implies, the position of a positional
parameter establishes the correspondence—the n-th formal positional
parameter is matched with the n-th actual positional parameter.

Keyword Parameters

A keyword parameter, which can be either actual or formal, is an
expression or variable name preceded by a keyword and an equal sign
("=") that identifies which parameter is being passed.
When calling a routine with a keyword parameter, you can abbreviate
the keyword to its shortest, unambiguous abbreviation. Keyword
parameters can also be specified by the caller with the syntax
/KEYWORD, which is equivalent to setting the keyword parameter to 1
(e.g., KEYWORD = 1). The syntax /KEYWORD is often referred to, in the
rest of this documentation, as setting the keyword.
For example, a procedure is defined with a keyword parameter named TEST.
PRO XYZ, A, B, TEST = T
The caller can supply a value for the formal (keyword) parameter T
with the following calls:
; Supply only the value of T. A and B are undefined inside the
; procedure.
XYZ, TEST = A

; The value of A is copied to formal parameter T (note the
; abbreviation for TEST), Q to A, and R to B.
XYZ, TE = A, Q, R

; Variable Q is copied to formal parameter A. B and T are undefined
; inside the procedure.
XYZ, Q
result = FUNCTION(Arg1, Arg2, KEYWORD = value)



FYI

Dmitri.
--



reply via email to

[Prev in Thread] Current Thread [Next in Thread]