[Swift-devel] Join function?

Mihael Hategan hategan at mcs.anl.gov
Tue Apr 3 16:59:11 CDT 2012


Maybe it didn't wait for the array to be closed?

On Tue, 2012-04-03 at 16:13 -0500, Michael Wilde wrote:
> for an array created like this:
> 
> string a[] = ["a","b","c"];
> 
> @length(a) returned 3 when called from open code, but when applied to the argument s[] inside a function, to which a was passed, returned 0 inside that function.
> 
> In trying to replicate this without divulging the source code to recursive strjoin() ;) which I was leaving as an exercise to the (email) reader, I see that there is further weirdness, likely due to confusion/race between @length() and array closing semantics.
> 
> For example:
> 
> com$ cat length.swift
> string a[] = ["a","b","c"];
> 
> string b[];
> b[0] = "a";
> b[1] = "b";
> b[2] = "c";
> 
> (string o) strjoin(string s[], string sep)
> {
>  #  o = strjoinf(s, sep, @length(s));  # length returns 0 here!
>  trace("len inside", at length(s));
> 
> }
> 
> trace("len a outside", @length(a));
> trace("len b outside", @length(b));
> 
> string js = strjoin(a,"---");
> 
> ####
> 
> Gives this non-determinsitic output:
> 
> com$ swift length.swift
> 
> no sites file specified, setting to default: /home/wilde/swift/rev/trunk/etc/sites.xml
> Swift trunk swift-r5739 cog-r3368 (cog modified locally)
> 
> RunID: 20120403-1559-ulurhdrf
> Progress:  time: Tue, 03 Apr 2012 15:59:31 -0500
> SwiftScript trace: len b outside, 2
> SwiftScript trace: len inside, 3
> SwiftScript trace: len a outside, 3
> Final status: Tue, 03 Apr 2012 15:59:31 -0500
> 
> com$ swift length.swift
> 
> no sites file specified, setting to default: /home/wilde/swift/rev/trunk/etc/sites.xml
> Swift trunk swift-r5739 cog-r3368 (cog modified locally)
> 
> RunID: 20120403-1559-x3ovo0i6
> Progress:  time: Tue, 03 Apr 2012 15:59:39 -0500
> SwiftScript trace: len b outside, 2
> SwiftScript trace: len a outside, 0
> SwiftScript trace: len inside, 0
> Final status: Tue, 03 Apr 2012 15:59:39 -0500
> 
> com$ swift length.swift
> 
> no sites file specified, setting to default: /home/wilde/swift/rev/trunk/etc/sites.xml
> Swift trunk swift-r5739 cog-r3368 (cog modified locally)
> 
> RunID: 20120403-1559-zkglev13
> Progress:  time: Tue, 03 Apr 2012 15:59:42 -0500
> SwiftScript trace: len b outside, 3
> SwiftScript trace: len a outside, 0
> SwiftScript trace: len inside, 0
> Final status: Tue, 03 Apr 2012 15:59:42 -0500
> 
> com$ swift length.swift
> 
> no sites file specified, setting to default: /home/wilde/swift/rev/trunk/etc/sites.xml
> Swift trunk swift-r5739 cog-r3368 (cog modified locally)
> 
> RunID: 20120403-1559-5ttgglqc
> Progress:  time: Tue, 03 Apr 2012 15:59:48 -0500
> SwiftScript trace: len a outside, 0
> SwiftScript trace: len b outside, 3
> SwiftScript trace: len inside, 3
> Final status: Tue, 03 Apr 2012 15:59:48 -0500
> com$ 
> 
> 
> ----- Original Message -----
> > From: "Jonathan Monette" <jonmon at mcs.anl.gov>
> > To: "Mihael Hategan" <hategan at mcs.anl.gov>
> > Cc: "Glen Hocky" <glen842 at uchicago.edu>, "swift-devel at ci.uchicago.edu Devel" <swift-devel at ci.uchicago.edu>
> > Sent: Tuesday, April 3, 2012 3:47:18 PM
> > Subject: Re: [Swift-devel] Join function?
> > I do not know what Mike was experiencing. I was going to investigate
> > myself and ask what his example was. Perhaps he can elaborate more on
> > what he was witnessing.
> > 
> > On Apr 3, 2012, at 3:46 PM, Mihael Hategan wrote:
> > 
> > > On Tue, 2012-04-03 at 15:43 -0500, Jonathan Monette wrote:
> > >> So Swift does have an @length built-in function that returns the
> > >> length of an array. Mike said he also tried coming up with a Swift
> > >> function to this same think and said that @length does not always
> > >> behave as he thought it should. I am going to look into fixing
> > >> @length so we do have a way finding the length of an array.
> > >
> > > Can you be more specific as to what's wrong with @length?
> > >
> > 
> > _______________________________________________
> > Swift-devel mailing list
> > Swift-devel at ci.uchicago.edu
> > https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
> 





More information about the Swift-devel mailing list