Hi Brad, thanks for the quick response and your help. I'm not in a rush so I'll maybe get back to you in the next few weeks ;)
Best regards, Marco > Gesendet: Donnerstag, 05. Februar 2015 um 00:53 Uhr > Von: "Brad Chamberlain" <[email protected]> > An: "Marco Postigo" <[email protected]> > Cc: "Public Chapel Bugs list" <[email protected]> > Betreff: Re: Aw: Re: [Chapel-bugs] Shadowing a procedure with variable number > of arguments > > > Hi Marco -- > > In the interest of getting you a quick response, here's the easy part of > the message: > > > thank you for the suggestion with the workaround. Unfortunately I have a > > heterogeneous tuple... is there any way to iterate over a heterogeneous > > tuple? With the homogeneous I had no problem but if I try the same with the > > heterogeneous I get a compile error. > > The trick to iterating over a heterogeneous tuple is to use a 'param' > index variable in the loop. This has the effect of fully unrolling the > loop in order to give each iteration its own 'param' (compile-time-known) > variable representing the index. For example: > > var t = (1, "two", 3.0); > > for param i in 1..t.size { > var j = t(i); > writeln(typeToString(j.type)); > } > > The reason that a non-param version of this loop doesn't work is that it > would require the variable 'j' to not have a well-defined type at > compile-time (and since Chapel is a statically-typed language, this isn't > permitted). > > > To the rest of the message (the harder part), there's a part of me that > wonders whether there might be a way to subclass Writer to get the > behavior you want, but I'm not expert enough in the > file/channel/writer/reader hierarchy to know the answer to that offhand > (and the developer who is best equipped to answer it is out of the loop > for another week or two; but if you weren't in a rush, it might make sense > to drag feet until he gets back to see what his thoughts are). > > > > My intent was to create a ConsoleLogger that is able to take any arguments > > (primitives, classes, records ...). Then simply redirect the arguments to > > writeln() which then (if I did not understand anything wrong) uses the > > writeThis(w:Writer) procedure of classes to print them. Later I wanted to > > replace the ConsoleLogger with a FileLogger that is able to do log rotating > > etc... of course hoping that using the writeThis(...) method will help > > saving > > some work :) I didn't want to override the proc +(s: string, myObject: > > object) method (and the other way around ... myObject: object, s: string) in > > all my classes. > > > > Would there be any way to hold a reference to that args tuple? So that I > > could create a class LogMessage which holds only the reference to the > > args... > > Here is an example but of course with known compile errors because I > > couldn't > > find how it could be done or if it even possible yet: > > You may have seen that Chapel has a fairly new feature for storing > references, a la: > > var x: int; > ref y = x; // causes 'y' to be a reference to 'x' any subsequent > // reads/writes to 'y' will actually be to 'x'. > > Unfortunately, 'ref' fields are not yet supported (though the intention is > to do so; and we find more reasons to do so all the time). > > > > 6 // hold reference here... type "args ...k?" is of course invalid, but > > would it be possible to hold a reference? > > 7 // I've never seen a declaration of a tuple where the types are not > > known. > > 8 var args : args ...k?; > > For something like this, I suspect that your best bet today would be to > make 'args' be completely generic (i.e., don't declare its type). This > would permit it to be a member variable of heterogeneous tuple type > (determined by inspecting the constructor calls to the class); but it > wouldn't be a reference to that tuple... Also, it would mean that your > class is generic w.r.t. this type and will be instantiated for each type > signature of 'args' that you use in practice, similar to a C++ template > function. Which, at a sniff, seems like probably way more instantiations > than you'd want for a program like this. > > > Hope this is helpful, > -Brad > ------------------------------------------------------------------------------ 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
