[Swift-user] empty array in Swift

Wilde, Michael J. wilde at mcs.anl.gov
Mon Feb 3 12:22:36 CST 2014


The following following should declare an array with no elements:

  string args[];

- Mike
--
Michael Wilde
Mathematics and Computer Science          Computation Institute
Argonne National Laboratory                    The University of Chicago

________________________________
From: swift-user-bounces at ci.uchicago.edu [swift-user-bounces at ci.uchicago.edu] on behalf of Ketan Maheshwari [ketan at mcs.anl.gov]
Sent: Monday, February 03, 2014 11:44 AM
To: Swift User
Subject: [Swift-user] empty array in Swift

Hi,

I was working on a problem where user can pass a dynamic number of arguments to an app, including zero.

A possible Swift script as follows:

type file;

app (file _out, file _err) anapp(file _exec, int _i, string _args[]){
    sh @_exec _i _args stdout=@_out stderr=@_err;
}
string args[]=["any", "num", "args"]; # generated via a wrapper script

file exec<"./echo.sh">;
foreach i in [0:9:1]{
    file out <single_file_mapper; file=@strcat("outloc", "/", i, ".out")>;
    file err <single_file_mapper; file=@strcat("outloc", "/", i, ".err")>;
    (out,err) = anapp(exec, i, args);
}

However, it seems that I cannot have an array with no elements:

string args[]=[];

In this case Swift complains:
Compile error in assignment at line 8: You cannot assign value of type [int] to a variable of type string[int]

Which works when I say:

string args[]=[""]

However, it results in an array with one element.

So, is there a way in Swift to have an array with zero elements?

Thanks,
Ketan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-user/attachments/20140203/1b86385c/attachment.html>


More information about the Swift-user mailing list