stluka@software.org (Fred Stluka) (02/15/91)
Here's one for the language lawyers. I don't think there is a way to do this. Someone please tell me that I'm wrong. From within a generic body GEN, I want to call a procedure PROC1 which was was passed in as a generic parameter PROC. I want to make the call without specifying any parameters, allowing all of them to default to the default expressions specified in the declaration of PROC1. I also do not want to re-specify the default expressions in my declaration of PROC as a generic formal parameter to GEN, because this would override the defaults of PROC1 which may someday be changed. The best I've been able to do so far is to declare constants with the values of all of the defaults, and use these constant names on the declaration of PROC1 and on the declaration of PROC. Then, as long as any future modifier of this code changes the values of the constants instead of changing the default values of the parameters directly, my generic code will still always use the right default values. Any better ideas? --Fred Fred Stluka Internet: stluka@software.org Software Productivity Consortium UUNET: ...!uunet!software!stluka 2214 Rock Hill Rd, Herndon VA 22070 USA -- Fred Stluka Internet: stluka@software.org Software Productivity Consortium UUNET: ...!uunet!software!stluka 2214 Rock Hill Rd, Herndon VA 22070 USA
collard@software.org (David Collard) (02/15/91)
In article <1991Feb14.224435.1512@software.org> stluka@software.org (Fred Stluka) writes: > Here's one for the language lawyers. I don't think there is > a way to do this. Someone please tell me that I'm wrong. > > From within a generic body GEN, I want to call a procedure PROC1 > which was was passed in as a generic parameter PROC. I want to > make the call without specifying any parameters, allowing all of > them to default to the default expressions specified in the > declaration of PROC1. I also do not want to re-specify the default > expressions in my declaration of PROC as a generic formal parameter > to GEN, because this would override the defaults of PROC1 which may > someday be changed. > Are either of these options better? the first takes in your constant as a generic formal and the second takes in a visible function as a generic formal (default). -- (1) -- generic default_for_x : integer; with procedure proc1(x : integer := default_for_x); procedure gen; procedure gen is begin proc1; end gen; with gen; with Text_IO; use Text_IO; procedure boss is def : integer := 1; procedure proc(x : integer := 1) is begin put_line(integer'image(x)); end proc; procedure mygen is new gen(proc1, def); begin mygen; end boss; -- (2) -- generic with function default_for_x return integer is <>; with procedure proc1(x : integer := default_for_x); procedure gen; procedure gen is begin proc1; end gen; with gen; with Text_IO; use Text_IO; procedure boss is function default_for_x return integer is begin return 1; end; procedure proc(x : integer := 1) is begin put_line(integer'image(x)); end proc; procedure mygen is new gen(proc1 => proc); begin mygen; end boss; -- ----------------------------------------------------------------------- D. Thor Collard Internet: collard@software.org Software Productivity Consortium UUNET: ...!uunet!software!collard 2214 Rock Hill Rd, Herndon VA 22070