procedures 
Author Message
 procedures

It is unclear to me the significance of positional association and named
association in procedure calls. Can you e-mail me an explanation.
----------------------------------------------------------------------------

procedure(A,B: in integer;OP in:OP_CODE;
          Z out: integer;ZCOMP out: boolean)

procedure(A, B, OP, Z, ZCOMP);                                  -- Positional association.

procedure(A1=>A, B1=>B, OP1=>OP, Z1=>Z, ZCOMP1=>ZCOMP)           -- Named association.

--
Sharif M. Shahrier                              Tel:    1-609-951-2976
NEC USA Inc.                                    Fax:    1-609-951-2499
4 Independence Way



Sat, 01 Apr 2000 03:00:00 GMT  
 procedures

Quote:

> It is unclear to me the significance of positional association and named
> association in procedure calls. Can you e-mail me an explanation.

With positional association, you have to write the actual parameters in
the right order - they are associated with the formal parameters in the
same order as the formals were written in the procedure header.  That
might be ok for a procedure with just a couple of parameters, but beyond
that, it's not immediately obvious from the call which actual is
associated with which formal.

Named asasociation, on the other hand, lets you write the associations
in any order you choose.  Not only does it free you from having to
remember the order, but it adds self-documentation to the code.

Quote:
> procedure(A,B: in integer;OP in:OP_CODE;
>           Z out: integer;ZCOMP out: boolean)

> procedure(A, B, OP, Z, ZCOMP);

> procedure(A1=>A, B1=>B, OP1=>OP, Z1=>Z, ZCOMP1=>ZCOMP)

This is a good example to start with.  Let's first sort out a few
errors.  First, you need a name for the procedure in the declaration:

procedure foo(A,B: in integer; OP in:OP_CODE;
              Z out: integer; ZCOMP out: boolean);

Next, in each call, you use the procedure name, and write the actual
parameters on the left side of the arrow:

foo(A1, B1, OP1, Z1, ZCOMP1);

foo(A=>A1, B=>B1, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

Now let's compare the two forms of association.  First, note that the
procedure calls are in a statement part, whereas the declaration is in a
declarative part somewhere.  Thus, there may be some separation between
the declaration and the calls.  For example, the declaration may
actually be off in a package somewhere.  For the call using positional
association, you have to go look at the declaration to see which formal
is associated with each actual.  Makes it harder to read.  For named
association, it's all laid out in front of you in the call.  The named
association example could also be written as:

foo(ZCOMP=>ZCOMP1, OP=>OP1, A=>A1, B=>B1, Z=>Z1);

with exactly the same meaning.

Named association is also useful when you have default values for
parameters.  For example, suppose you declare foo as:

procedure foo(A,B: in integer := 0; OP in:OP_CODE;
              Z out: integer; ZCOMP out: boolean);

Then you can write:

foo(A=>3, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

You can't write this call with positional association, since there is no
way to "skip" a parameter to let it take its default value.

One final point to note is that positional and named association are not
just for procedure calls, but also for function calls, generic maps and
port maps.  Aggregates for arrays nd records also have positional and
named forms.  As a matter of style, I nearly always use named
association, for the reasons mentioned above.

Hope this rather protracted discussion answers your questions.  You can
find more details and examples in my book, THE Designer's Guide to
VHDL.  See my web page for info.

Cheers,

PA
--


University of Cincinnati               Phone:   +1 513 556 4756
PO Box 210030                          Fax:     +1 513 556 7326
Cincinnati OH 45221-0030, USA

                http://www.cs.adelaide.edu.au/~petera/
                      (includes PGP public key)



Sun, 02 Apr 2000 03:00:00 GMT  
 procedures

Quote:

> ...

> Named association is also useful when you have default values for
> parameters.  For example, suppose you declare foo as:

> procedure foo(A,B: in integer := 0; OP in:OP_CODE;
>               Z out: integer; ZCOMP out: boolean);

> Then you can write:

> foo(A=>3, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

> You can't write this call with positional association, since there is no
> way to "skip" a parameter to let it take its default value.

I think you CAN use default values with positional association....

e.g. TextIO write procedures are defined with default values for JUSTIFIED
and FIELD parameters :-

    procedure WRITE(L : inout LINE; VALUE : in bit_vector;
              JUSTIFIED: in SIDE := right;
              FIELD: in WIDTH := 0);

You can use these procedures with positional association WITHOUT specifying
values for JUSTIFIED and FIELD

WRITE (L, ABV);

B.



Sun, 02 Apr 2000 03:00:00 GMT  
 procedures

Quote:

> Named association is also useful when you have default values for
> parameters.  For example, suppose you declare foo as:

> procedure foo(A,B: in integer := 0; OP in:OP_CODE;
>               Z out: integer; ZCOMP out: boolean);

> Then you can write:

> foo(A=>3, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

> You can't write this call with positional association, since there is no
> way to "skip" a parameter to let it take its default value.

You can use OPEN as the actual to explicitely associate the formal
with its default value.  That is, you could write

    foo (3, OPEN, OP1, Z1, ZCOMP1);

This works for ports, generics and parameters.



Mon, 03 Apr 2000 03:00:00 GMT  
 procedures

I would like to take the time here to complement Mr. Peter Ashenden for
taking the time to answer some of these questions. I find the
discussions and
his answers to be quite helpful.

Quote:


> > It is unclear to me the significance of positional association and
> named
> > association in procedure calls. Can you e-mail me an explanation.

> With positional association, you have to write the actual parameters
> in
> the right order - they are associated with the formal parameters in
> the
> same order as the formals were written in the procedure header.  That
> might be ok for a procedure with just a couple of parameters, but
> beyond
> that, it's not immediately obvious from the call which actual is
> associated with which formal.

> Named asasociation, on the other hand, lets you write the associations

> in any order you choose.  Not only does it free you from having to
> remember the order, but it adds self-documentation to the code.

> > procedure(A,B: in integer;OP in:OP_CODE;
> >           Z out: integer;ZCOMP out: boolean)

> > procedure(A, B, OP, Z, ZCOMP);

> > procedure(A1=>A, B1=>B, OP1=>OP, Z1=>Z, ZCOMP1=>ZCOMP)

> This is a good example to start with.  Let's first sort out a few
> errors.  First, you need a name for the procedure in the declaration:

> procedure foo(A,B: in integer; OP in:OP_CODE;
>               Z out: integer; ZCOMP out: boolean);

> Next, in each call, you use the procedure name, and write the actual
> parameters on the left side of the arrow:

> foo(A1, B1, OP1, Z1, ZCOMP1);

> foo(A=>A1, B=>B1, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

> Now let's compare the two forms of association.  First, note that the
> procedure calls are in a statement part, whereas the declaration is in
> a
> declarative part somewhere.  Thus, there may be some separation
> between
> the declaration and the calls.  For example, the declaration may
> actually be off in a package somewhere.  For the call using positional

> association, you have to go look at the declaration to see which
> formal
> is associated with each actual.  Makes it harder to read.  For named
> association, it's all laid out in front of you in the call.  The named

> association example could also be written as:

> foo(ZCOMP=>ZCOMP1, OP=>OP1, A=>A1, B=>B1, Z=>Z1);

> with exactly the same meaning.

> Named association is also useful when you have default values for
> parameters.  For example, suppose you declare foo as:

> procedure foo(A,B: in integer := 0; OP in:OP_CODE;
>               Z out: integer; ZCOMP out: boolean);

> Then you can write:

> foo(A=>3, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

> You can't write this call with positional association, since there is
> no
> way to "skip" a parameter to let it take its default value.

> One final point to note is that positional and named association are
> not
> just for procedure calls, but also for function calls, generic maps
> and
> port maps.  Aggregates for arrays nd records also have positional and
> named forms.  As a matter of style, I nearly always use named
> association, for the reasons mentioned above.

> Hope this rather protracted discussion answers your questions.  You
> can
> find more details and examples in my book, THE Designer's Guide to
> VHDL.  See my web page for info.

> Cheers,

> PA
> --


> University of Cincinnati               Phone:   +1 513 556 4756
> PO Box 210030                          Fax:     +1 513 556 7326
> Cincinnati OH 45221-0030, USA

>                 http://www.cs.adelaide.edu.au/~petera/
>                       (includes PGP public key)

--
__/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/

    Richard Schwarz, President
    Associated Professional Systems Inc. (APS)

    web site: http://www.associatedpro.com
    Phone: 410-569-5897
    Fax:   410-661-2760

__/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/



Mon, 03 Apr 2000 03:00:00 GMT  
 procedures

Quote:


> > ...

> > Named association is also useful when you have default values for
> > parameters.  For example, suppose you declare foo as:

> > procedure foo(A,B: in integer := 0; OP in:OP_CODE;
> >               Z out: integer; ZCOMP out: boolean);

> > Then you can write:

> > foo(A=>3, OP=>OP1, Z=>Z1, ZCOMP=>ZCOMP1);

> > You can't write this call with positional association, since there is no
> > way to "skip" a parameter to let it take its default value.

> I think you CAN use default values with positional association....

> e.g. TextIO write procedures are defined with default values for JUSTIFIED
> and FIELD parameters :-

>     procedure WRITE(L : inout LINE; VALUE : in bit_vector;
>               JUSTIFIED: in SIDE := right;
>               FIELD: in WIDTH := 0);

> You can use these procedures with positional association WITHOUT specifying
> values for JUSTIFIED and FIELD

> WRITE (L, ABV);

You're quite right.  You can use default values with positional
association, but only if the parameters you want to default are the last
ones in the list.  Consider for example, how you would write a call to
WRITE with JUSTIFIED defaulted but FIELD specifified as, say, 10.  You
have to use named association for FIELD.  You can start with positional
for the first few parameters, then revert to named for the remaining
non-defaulted parameters:

  WRITE ( L, ABV, FIELD => 10 );

Cheers,

PA

--


University of Cincinnati               Phone:   +1 513 556 4756
PO Box 210030                          Fax:     +1 513 556 7326
Cincinnati OH 45221-0030, USA

                http://www.cs.adelaide.edu.au/~petera/
                      (includes PGP public key)



Mon, 03 Apr 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Adding Procedures to Generated Procedures

2. Mixing ABC procedures and Standard Clarion procedures

3. How to setup a procedure in a DLL that calls a procedure in another DLL

4. Procedures within Procedures

5. Call a procedure from a procedure

6. Calling a procedure with a variable procedure name

7. C55 ABC - how to close a procedure at start of procedure

8. Quest: logowriter (mac) procedure to print other procedures

9. logo procedure for printing other procedures?

10. Procedure that only calls a procedure?

11. procedure variables vs. type-bound procedures

12. Defining procedures whose argument list is result of procedure

 

 
Powered by phpBB® Forum Software