RE: Default parameter values for methods

From: Matan Vax <matan_at_.....>
Date: Thu Jun 11 2009 - 00:28:48 PDT
Hey Darren,

 

What I propose is simply to adopt the standard approach to default
parameters. The values provided in the method call get associated with
parameters simply in order from left to right. The types of the
expressions do not affect this strict in-order correlation (so a
parameter type mismatch is reported in the usual way). There is no way
to provide in a method call a value for a parameter without providing
values for all parameters preceding it. Similarly in a method
declaration if a parameter with default is followed by a parameter
without default a compile time error is issued.

 

Following your code example:

 

extend sys {

    // this is the syntax I have in mind, similar to other languages

   my_method(a: bool = TRUE, b: bool = FALSE) is { 

      // ...

   };

 

   run() is also {

      my_method(); // the two defaults are used

      my_method(FALSE); // the default for the first parameter is
overridden, the second is still used

      my_method(FALSE,TRUE); // both defaults are overridden

   };

};

 

Hope this clarifies things.

Matan.

 

________________________________

From: darren.galpin@infineon.com [mailto:darren.galpin@infineon.com] 
Sent: Thursday, June 11, 2009 9:47 AM
To: Matan Vax; ieee1647@eda.org
Subject: RE: Default parameter values for methods

 

Hi Matan,

 

It seems like a good idea, but I have a few questions about this, as I
may be misunderstanding a few things.

 

Firstly, you have a method, such as:-

 

a: default=TRUE; -- An example, syntax will obviously be different

b: default=FALE; -- As above.

my_method(a: bool, b: bool) {

};

 

Normally you would then call the method as follows:-

 

my_method(TRUE, FALSE);

 

Which is fine, but if you do not provide all of the parameters, then
what happens in the following case:-

 

my_method(FALSE);

 

Which of the two boolean parameters have I set, and which of the two
have I missed? It isn't clear to me from the description how this would
operate.

 

Perhaps others could comment? Should we include it?

 

Cheers,

 

Darren

 

________________________________

From: owner-ieee1647@server.eda.org
[mailto:owner-ieee1647@server.eda.org] On Behalf Of Matan Vax
Sent: Wednesday, June 10, 2009 6:54 PM
To: ieee1647@server.eda.org
Subject: Default parameter values for methods

Hello all,

 

As you probably know, many object-oriented languages allow declaring
default values for method parameters. Specifically in our domain both
SystemC (C++) and SystemVerilog support it. The principle is simple - if
a default value is designated for some parameter in the method
declaration providing the parameter in the call becomes optional. If
provided, the user's parameter overrides the default, and otherwise the
default is passed to the method body. Upon method call parameters are
resolved in order, so all parameters with defaults must be placed at the
end of the parameter list.

 

This mechanism can be used to simplify functional APIs of core
libraries, verification IPs, and other packages. When introducing some
operation, library designers often face the dilemma of either defining a
single method and forcing the user to provide all possible parameters,
including trivial ones (NULL, UNDEF, 0, or whatever the natural default
happens to be), or defining multiple method variants with different
parameter sets, each with its own name. Both obscure the natural
semantics of the operation. Note that method overloading may have
similar impact, but is much more complicated to define and implement.

 

So I propose we consider adding this capability to the e standard (and
obviously implement it in tools, Specman in particular). Defining it
formally is relatively straightforward and I volunteer to do it if I get
green light from this forum.

 

What do you say?

Matan.

 


-- 
This message has been scanned for viruses and 
dangerous content by MailScanner <http://www.mailscanner.info/> , and is

believed to be clean. 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jun 11 02:19:00 2009

This archive was generated by hypermail 2.1.8 : Thu Jun 11 2009 - 02:19:03 PDT