June 14, 2004
On Sun, 13 Jun 2004 19:12:57 -0400, Vathix <vathixSpamFix@dprogramming.com> wrote:
>>     func(int[0, 1, 2, 3]);
>
> This one looks pretty cool.

Yep. That's my favourite too.

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 14, 2004
"Matthew" <admin@stlsoft.dot.dot.dot.dot.org> escribió en el mensaje
news:caimnk$1e7l$1@digitaldaemon.com
| Why not require some kind of syntactic hint, as in:
|
|     func([cast(int)0, 1, 2, 3]);
|
| or
|     func([int: 0, 1, 2, 3]);
|
| or
|
|     func((int[])[0, 1, 2, 3]);
|
| or
|
|     func(int[0, 1, 2, 3]);
|
| ?
|

I'd prefer it as C# does it: new int[] [0,1,2,3];

-----------------------
Carlos Santander Bernal


June 14, 2004
"Derek" <derek@psyc.ward> wrote in message news:1ovbt2dsuadke.1hsc4hq8954kj$.dlg@40tude.net...
> >>> The fundamental problem with array literals is the bottom-up nature of
the
> >>> typing of expressions in the semantic phase of compilation. Is
[0,1,2,3] an
> >>> array of chars, bytes, ints, longs, floats, ... ?
> >>>
> >>> This is not an easy problem to solve, which is why it'll be deferred
to a
> >>> 2.0 feature.
> >>
> >> char[4] A = [0,1,2,3]; // chars
> >> byte[4] A = [0,1,2,3]; // bytes
> >> int[4] A = [0,1,2,3]; // ints
> >> long[4] A = [0,1,2,3]; // longs
> >> float[4] A = [0,1,2,3]; // floats
> >>
> >> What don't I understand about this 'difficult problem'?

In the case of an initializer, there is no expression on the right hand side. It's known that it MUST be an array initializer of the array type of the variable.

> In my examples, I was trying to demostrate that the compiler had enough information to work out what the array literals were meant to be. The info comes from the datatype the array literals was being assigned to.

Consider:
    void foo(int[]);
    void foo(uint[]);
    void bar(int, ...);
and:
    foo([1,2,3]);
which foo is called?
    bar(i, [1,3,4]);
what type of array is passed?

> In your example, the compiler still has enough info. If 'somefunc'
requires
> that an 'int[]' be passed to it, then the array literal needs also to be one of ints.
>
> As an array literal (or any literal for that matter) does not exist
outside
> of some context, it should be able to determine its datatype *in* that context. We don't have problems with numeric literals.
>
>   void anotherfunc(float a);
>   . . .
>
>   anotherfunc(4);  // '4' is a float, no?

No, '4' is an int. It gets implicitly converted to a float by matching it against the argument of anotherfunc. Importantly, the types are determined *before* overload function matching is done, otherwise it could never figure out which function to call.


June 14, 2004
"Vathix" <vathixSpamFix@dprogramming.com> wrote in message news:cain1m$1eit$1@digitaldaemon.com...
> >     func(int[0, 1, 2, 3]);
>
> This one looks pretty cool.

It's also ambiguous:

    foo[0,1,2,3]

is this an array of foo's, or is foo an array indexed by [0,1,2,3]?


June 14, 2004
On Sun, 13 Jun 2004 18:43:37 -0700, Walter <newshound@digitalmars.com> wrote:
> "Vathix" <vathixSpamFix@dprogramming.com> wrote in message
> news:cain1m$1eit$1@digitaldaemon.com...
>> >     func(int[0, 1, 2, 3]);
>>
>> This one looks pretty cool.
>
> It's also ambiguous:
>
>     foo[0,1,2,3]
>
> is this an array of foo's, or is foo an array indexed by [0,1,2,3]?


True, ok, how bout:

func( cast(int[]) [0,1,2,3] );

?

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 14, 2004
Carlos Santander B. wrote:
> I'd prefer it as C# does it: new int[] [0,1,2,3];
Or new int[0,1,2,3]?
Sam
June 14, 2004
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opr9kb88nu5a2sq9@digitalmars.com...
> On Sun, 13 Jun 2004 18:43:37 -0700, Walter <newshound@digitalmars.com> wrote:
> > "Vathix" <vathixSpamFix@dprogramming.com> wrote in message news:cain1m$1eit$1@digitaldaemon.com...
> >> >     func(int[0, 1, 2, 3]);
> >>
> >> This one looks pretty cool.
> >
> > It's also ambiguous:
> >
> >     foo[0,1,2,3]
> >
> > is this an array of foo's, or is foo an array indexed by [0,1,2,3]?
>
>
> True, ok, how bout:
>
> func( cast(int[]) [0,1,2,3] );
>
> ?

Ugly <g>.


June 14, 2004
"Walter" <newshound@digitalmars.com> wrote in message news:cajaj5$2e27$1@digitaldaemon.com...
>
> "Regan Heath" <regan@netwin.co.nz> wrote in message news:opr9kb88nu5a2sq9@digitalmars.com...
> > On Sun, 13 Jun 2004 18:43:37 -0700, Walter <newshound@digitalmars.com> wrote:
> > > "Vathix" <vathixSpamFix@dprogramming.com> wrote in message news:cain1m$1eit$1@digitaldaemon.com...
> > >> >     func(int[0, 1, 2, 3]);
> > >>
> > >> This one looks pretty cool.
> > >
> > > It's also ambiguous:
> > >
> > >     foo[0,1,2,3]
> > >
> > > is this an array of foo's, or is foo an array indexed by [0,1,2,3]?
> >
> >
> > True, ok, how bout:
> >
> > func( cast(int[]) [0,1,2,3] );
> >
> > ?
>
> Ugly <g>.

Not that ugly. And if it gives us array literals, it'd be well worth it.

Two questions:

1. Do you have an interest in getting array literals in for 1.0, if a simple and
unambiguous syntax can be determined?
2. Do you have your own ideas for such a syntax?



June 14, 2004
On Sun, 13 Jun 2004 21:41:01 -0700, Walter <newshound@digitalmars.com> wrote:
> "Regan Heath" <regan@netwin.co.nz> wrote in message
> news:opr9kb88nu5a2sq9@digitalmars.com...
>> On Sun, 13 Jun 2004 18:43:37 -0700, Walter <newshound@digitalmars.com>
>> wrote:
>> > "Vathix" <vathixSpamFix@dprogramming.com> wrote in message
>> > news:cain1m$1eit$1@digitaldaemon.com...
>> >> >     func(int[0, 1, 2, 3]);
>> >>
>> >> This one looks pretty cool.
>> >
>> > It's also ambiguous:
>> >
>> >     foo[0,1,2,3]
>> >
>> > is this an array of foo's, or is foo an array indexed by [0,1,2,3]?
>>
>>
>> True, ok, how bout:
>>
>> func( cast(int[]) [0,1,2,3] );
>>
>> ?
>
> Ugly <g>.

True, but is it ambiguous?

Regan.

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 14, 2004
"Regan Heath" <regan@netwin.co.nz> wrote in message news:opr9kj4wsq5a2sq9@digitalmars.com...
> On Sun, 13 Jun 2004 21:41:01 -0700, Walter <newshound@digitalmars.com> wrote:
> > "Regan Heath" <regan@netwin.co.nz> wrote in message news:opr9kb88nu5a2sq9@digitalmars.com...
> >> On Sun, 13 Jun 2004 18:43:37 -0700, Walter <newshound@digitalmars.com> wrote:
> >> > "Vathix" <vathixSpamFix@dprogramming.com> wrote in message news:cain1m$1eit$1@digitaldaemon.com...
> >> >> >     func(int[0, 1, 2, 3]);
> >> >>
> >> >> This one looks pretty cool.
> >> >
> >> > It's also ambiguous:
> >> >
> >> >     foo[0,1,2,3]
> >> >
> >> > is this an array of foo's, or is foo an array indexed by [0,1,2,3]?
> >>
> >>
> >> True, ok, how bout:
> >>
> >> func( cast(int[]) [0,1,2,3] );
> >>
> >> ?
> >
> > Ugly <g>.
>
> True, but is it ambiguous?

Of course. It's an array of ints. In fact, you could specify other things in there, and rely on the implicit conversions, just as with any other variables.