[Swift-devel] New syntax for appending to arrays

David Kelly davidkelly999 at gmail.com
Tue Jun 28 10:00:52 CDT 2011


How about:

a[5] .= 1;
a[5] .= 2;

That seems very appendish to me, similar to some operators in PHP and Perl.

On Tue, Jun 28, 2011 at 9:16 AM, Michael Wilde <wilde at mcs.anl.gov> wrote:

> Ah, you mean specifically using the operator += conflicts with its use as
> an increment operator in C? I wasn't thinking of that - I was just
> commenting that "append will be useful".
>
> I agree, now that you raise the issue. I need to study this length thread -
> Ive not been following it close enough.  Were any other symbols proposed for
> the operator other than the original "!"?
>
> Would "<<" be more appropriate, suggestive of various stream-append
> operators? Or append() as a built-in function rather than an operator?
>
> a << 123;
>
> - Mike
>
> ----- Original Message -----
> > $0,02 from me -- given that Swift has a C-like syntax, this syntax
> > will surely confuse people??
> >
> > On Jun 28, 2011, at 9:04 AM, Michael Wilde wrote:
> >
> > > This sound good. I assume one should be able to append to any
> > > dimension of a multi-dimensional array with +=.
> > >
> > > int a[][];
> > >
> > > a[5] += 1
> > > a[5] += 2
> > >
> > > sets a[5][?] = 1
> > >     a[5][?] = 2
> > >
> > > where ? is the index values chosen by +=
> > >
> > > Further, as you work out the typing rules for array subscripts,
> > > should the following work?
> > >
> > > int a[][[];
> > > int b[];
> > > b += 100;
> > > b += 200;
> > > a += b; # <=== should this append a new array to a?
> > >
> > > - Mike
> > >
> > > ----- Original Message -----
> > >>> As proposed earlier, a new syntax for appending values to
> > >>> arrays have been implemented. Examples are given below.
> > >>
> > >> I think I have been won over to the += syntax.
> > >>
> > >>> Please note that, we still need to make sure that when we can
> > >>> only append to an array, so to associate keys and multiple
> > >>> values, (i think) we will need two(or more) dimensional arrays.
> > >>
> > >> yes. but there are already multi-dimensional arrays in swift.
> > >>
> > >> also, a one dimensional array should still work, like this:
> > >>
> > >> int a[];
> > >> a += 232;
> > >> a += 111;
> > >>
> > >> --
> > >
> > > --
> > > Michael Wilde
> > > Computation Institute, University of Chicago
> > > Mathematics and Computer Science Division
> > > Argonne National Laboratory
> > >
> > > _______________________________________________
> > > Swift-devel mailing list
> > > Swift-devel at ci.uchicago.edu
> > > https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
>
> --
> Michael Wilde
> Computation Institute, University of Chicago
> Mathematics and Computer Science Division
> Argonne National Laboratory
>
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20110628/b6a111b5/attachment.html>


More information about the Swift-devel mailing list