[Swift-user] empty array in Swift
Ketan Maheshwari
ketan at mcs.anl.gov
Mon Feb 3 11:44:06 CST 2014
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/74704b32/attachment.html>
More information about the Swift-user
mailing list