Hi Marco --
[I accidentally forgot to include the chapel-bugs mailing list on my
response to Marco yesterday. Re-sending here to keep the archives
accurate.]
Thanks for boiling this down to a simple case.
It does appear that this is a bug, and one that I don't believe we were aware
of previously (in a quick look, I didn't find any references to it). I'm not
aware of any reason that Chapel should not support this offhand, so plan to
file this in our testing system unless you have any objections to my capturing
your test case.
Experimenting briefly, I found that it is possible to dynamically dispatch on a
tuple type, which suggests the following possible workaround for the time
being:
--------
class Logger {
//
// BLC: Avoid reliance on dynamic dispatch for the varargs call by
// only defining it in the parent class. The 'args' argument
// is a tuple that bundles up the varargs, so pass that tuple
// along to a helper function.
//
proc log(args...?k) { log_help(args); }
//
// BLC: Make a helper function that accepts a homogeneous tuple
// (though it could probably be heterogeneous as well?).
//
proc log_help(args) where isHomogeneousTuple(args) {
writeln("Logger#log ...");
}
}
class ConsoleLogger : Logger {
var lock$ : sync bool = false;
//
// BLC: And ditto for the subclass
//
proc log_help(args) where isHomogeneousTuple(args) {
lock$;
write("---", here.id, "--- --> ");
for param i in 1..1 {
write(args(i));
}
writeln();
lock$ = false;
}
}
var consoleLogger : Logger = new ConsoleLogger();
consoleLogger.log("hello");
//
// BLC: Add a second example to be sure:
//
consoleLogger = new Logger();
consoleLogger.log("hello");
--------
Output is:
---0--- --> hello
Logger#log ...
--------
Hopefully this will work for you -- please give a shout if it doesn't.
I'll mention in passing (for the second time this week, I'm embarrassed to say)
that the OOP features of Chapel have not received the attention that the
parallel/locality features have, and that we're currently undergoing an ongoing
effort to beef them up. Support for static methods/members is something that's
on that TODO list, though it's not currently being actively worked on.
Thanks,
-Brad
-------- Original Message --------
Subject: [Chapel-bugs] Shadowing a procedure with variable number of
arguments
Date: Sat, 31 Jan 2015 23:46:18 +0100
From: Marco Postigo <[email protected]>
To: <[email protected]>
Hello again :)
I just wanted to create a class Logger which has some subclasses (e.g.
NoOpLogger that does nothing, ConsoleLogger that logs to console, FileLogger
etc.). Because there are no static methods and with that the ability to make a
singleton object I've handed the object through those classes that needs
logging. Then I noticed that if I just specify that the type must be Logger or
a subclass of it that always the log(...) procedure of the superclass Logger
were invoked, thus it seems to be not possible to shadow a proc with a variable
number of arguments?
I've written a short example that should illustrate my problem:
1 class Logger {
2 proc log(args ...?k) {writeln("Logger#log ...");}
3 }
4
5 class ConsoleLogger : Logger {
6 var lock$ : sync bool = false;
7
8 proc log(args ...?k) {
9 lock$;
10 write("---", here.id, "--- --> ");
11 for param i in 1..k {
12 write(args(i));
13 }
14 writeln();
15 lock$ = false;
16 }
17 }
18
19 var consoleLogger : Logger = new ConsoleLogger();
20 consoleLogger.log("hello");
Output: Logger#log ...
--> the implementation in the superclass Logger.
Kind regards,
Marco
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Chapel-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-bugs