1

I have a domain I'd like to output with commas. In Python I can use the string .join() method, being fed by a list .sort()-ed product, but in Chapel I am not getting the right results.

var names = { "anze kopitar",
              "tyler toffoli",
              "drew doughty",
              "jeff carter",
              "tanner pearson"
               };

writeln( names );
writeln( names.sorted() );
writeln( ",".join( names ) );
writeln( ",".join( names.sorted() ) );

I'd like the last line to read

anze kopitar,drew doughty,jeff carter,tanner pearson,tyler toffoli
user3666197
  • 1
  • 6
  • 50
  • 92
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

1 Answers1

2

In Chapel 1.16, string.join only supports varargs, tuples, and arrays as arguments. For now you will need to convert your domain to one of those types before joining:

var dom = {"apple", "orange", "carrot"};
var A = dom.sorted(); // 'A' is an array
const s = ",".join(A);
writeln(s);

The output is:

apple,carrot,orange
benharsh
  • 396
  • 1
  • 8
  • How complex will be to "inline" a non-DUP method into the Chapel language? Given Brian typically works not with just a few hockey players, but rather with immense data-scales, the *"just"*-the-current-syntax-constraints motivated duplication will not be possible in all cases, where [SPACE] hard-limits do not permit any similar constraint workarounds. Thanks to add more light into this. – user3666197 Oct 20 '17 at 18:11
  • Are you wondering how difficult it would be to add a method/function that removes duplicates from something? I think it depends on what 'something' is. If it's an array, then I suppose one could perform an in-place sort and then walk the array looking for adjacent duplicates. I'm not familiar with the optimal algorithm for this problem, but I'm not aware of anything specific to Chapel that would overly complicate things. – benharsh Oct 20 '17 at 18:26
  • Negative, Sir. The point was to completely avoid a dumb-DUP step of `var A = dom.sorted(); // 'A' is an array` and get the language convert the non-DUP-ed data "on-the-fly" rather than statically duplicating their representation in [SPACE] just to become able to move to the next step to process and finally assign `aStringSEPARATOR.join( A );`. – user3666197 Oct 20 '17 at 18:30
  • 1
    That sounds rather tricky to me. What patterns would trigger this non-DUP behavior? What types would it operate on? To have the compiler automatically insert this kind of operation seems complicated and hopefully unnecessary in the future. I think better behavior would be for `join` to accept any iterable thing, so one could write `sep.join(dom.sorted())`. – benharsh Oct 20 '17 at 18:36
  • 1
    Yes, this was exactly what I tried to formulate when trying to ask **how complex it would be to extend the Chapel language for doing this** ( and principally avoid the costs of double allocated `[SPACE]`-footprint present in the interim workaround proposed in your current-syntax motivated answer ). – user3666197 Oct 20 '17 at 19:05