[Swift-devel] Confusion about evaluation of array arguments

Michael Wilde wilde at mcs.anl.gov
Tue Dec 11 22:49:02 CST 2012


Im confused about when a string array, passed as an argument to a app() or primitive, is evaluated as a string of space-separated values, and when its evaluated as an array.  Is this behavior dependent on the receiving primitive?

A string array passed to an app() and placed on the command line of the app is expanded into space-separated strings.

The same array passed to @strjoin() yields the expected string of separated array elements.

But the same array passed to @strcat is not evaluated but instead becomes a single string with the value "fnames:string[int] - Open".

Is the difference between these two behaviors determined by the primitive or context in which the array is evaluated, with @strjoin() and app() command-line expansion performing an expansion of the array's value, while being referenced by @strcat() does not force such evaluation?

This is the behavior in the test example below.

- Mike


type file;

app (file o) sh (string cmd)
{
  sh "-c" cmd stdout=@o;
}

app shf (file cmd)
{
  sh stdin=@cmd;
}

app (file o) echo (string a[])
{
  echo "array: " a stdout=@o;
}

foreach year in [1979:1980] {
  string find     = @strcat("ls -1 /home/wilde/swift/lab/*.swift");
  string fnames[] = readData(sh(find));
//  string cdo      = @strcat("echo ", @strjoin(fnames," "));
  string cdo      = @strcat("echo ", fnames);
  file script<single_file_mapper;file=@strcat("script.",year)>;
  file echo_out<single_file_mapper;file=@strcat("echo.",year,".out")>;
  echo_out = echo(fnames);
  script = writeData(cdo);
  shf(script);
}




-- 
Michael Wilde
Computation Institute, University of Chicago
Mathematics and Computer Science Division
Argonne National Laboratory




More information about the Swift-devel mailing list