[Swift-user] empty array in Swift

Mihael Hategan hategan at mcs.anl.gov
Mon Feb 3 12:57:34 CST 2014


Still a bug IMO.

type1 [type2] = []; is a valid statement.

Mihael

On Mon, 2014-02-03 at 18:22 +0000, Wilde, Michael J. wrote:
> 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
> 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
> _______________________________________________
> Swift-user mailing list
> Swift-user at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-user





More information about the Swift-user mailing list