Hi all:
Brad and I have recently been wrestling with the question of which
variable should be given preference in the function aFunc below (with
the choice being between the argument to aFunc() or Foo's module level
variable) and would like your opinion.
module Foo {
var conflicted = 13;
}
module Bar {
proc main {
aFunc(8);
}
proc aFunc(conflicted: int) {
use Foo;
writeln(conflicted); // should this print out 13 or 8?
}
}
*Argument in favor of the module level variable:*
If the contents of aFunc's body were moved into an inner block
statement and the outer block statement contained a new variable with
the same name, the module level definition should take precedent.
Function arguments are at an outer scope to the body of the function
(allowing you to define a variable in the function body without a naming
conflict, to shadow the argument), so they should be considered outer to
the scope where the use occurs. This is also the current behavior.
*Argument in favor of the function argument:*
The user should be able to name their arguments as they choose
without worrying if a module level variable will shadow it. They won't
necessarily know all the module level variables getting included through
this use call (due to the transitivity of Chapel uses), so could be
confused as to why their argument is not being used. Additionally, the
module level variable can be accessed directly using the module name as
a qualifier (i.e. writeln(Foo.conflicted)), while the function argument
cannot otherwise be accessed, so no value is lost through this default
behavior.
We'd also like to add a warning for the cases where confusion could
arise (since we've been flipping back and forth so much, which variable
is accessed will not necessarily be clear otherwise). We think it
should be a warning rather than an error, and so would need to define a
default behavior in either case.
As you can see, both arguments have merit and would be reasonable
behavior, but it is unclear to us which is the right course of action.
What are other's thoughts on the matter? What should our default
behavior be?
Thanks,
Lydia Duncan
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users