Hi Bard,

Thanks a lot for your message.

What I mean is that there are 2 different meanings to the same syntax 
construction.
So, the first [something] supplies the type whilst the second [somethingelse] 
supplies a list of initialization values;

So... everytime I see [T] I expect that T refers to a type, whilst it is not 
true when [T] is, in fact a list which contains one variable called T.

If we can say that X10 is based on Scala (I dont know if I'm authorized to say 
it and I dont know if this statement is desirable!)... we should employ 
parenthesis for lists.

So, in Scala you would say
       new Array[Place](host)  instead of Array[Place][host]

I understand the usability of constraints and I prefer explicit types instead 
of inferred ones which eventually work against me.

So, when we talk about explicit types, the syntax below is even more confused:

val a : Array[Place] = new Array[Place][host]; // what?

What is happening under the covers would be much more apparent if it were

val a : Array[Place] = new Array[Place](host);

or even:

val a : Array[Place] = new Array[Place]( [host] );



I mean: when I construct an object, I obviously call the constructor, which 
eventually accepts some arguments. So, when parenthesis dissappear, it leads us 
to think that a constructor is not being called at all.

My 2 cents

Cheers :)






--- On Fri, 19/11/10, Bard Bloom <ba...@us.ibm.com> wrote:

From: Bard Bloom <ba...@us.ibm.com>
Subject: Re: [X10-users] Array constructor?
To: "Mailing list for users of the X10 programming language" 
<x10-users@lists.sourceforge.net>
Cc: "Mailing list for users of the X10 programming language" 
<x10-users@lists.sourceforge.net>
Date: Friday, 19 November, 2010, 12:36

Well, the short-and-simple array constructor is like this:
   [1,2,3,4]
which produces an Array[Int](1).   That type, btw, means "An array of Ints
with 1 dimension."

But suppose that you want an Array[Int{self!=0}]'s?  -- an array of
non-zero Ints?
[1,2,3,4] looks like that, since they're all nonzero, but the type rules
make it just Array[Int](1).

So, by analogy with (1) Java array constants, and (2) object construction,
we let you tell what
type you actually want in the array, by sticking on a prefix "new Array[Int
{self!=0}]" -- or more
generally "new Array[T]".
   new Array[Int{self != 0}] [1,2,3,4]
is an array of non-zero Ints, by type.

I recommend using the simple syntax when you can.   I believe that it
usually does the right thing, and
in particular does so in this case:

   val test2 <: Array[Place] = [host];

(Apologies for sending you untested code.)

If that doesn't give you the type you want, you can use the more detailed
constructor.  But we hope
that the simple constructor does what is wanted most of the time.

See the spec: section 11.26

-- Bard


>
> cc
>
> Subject
>
> Re: [X10-users] Array constructor?
>
> humm.....
>
> val test2 : Array[Place] = new Array[Place](host);
>
> *does not* compile... actually.
>
> I've tried this too:
>
> for (host in Place.places()) {
>      val test1 : Array[Place] = new Array[Place][host,host,host,host];
> }
>
> .. which leads me to think that:
>
> 1. I'm declaring an Array with parametric type Place  :: Array[Place]
> 2. I'm initializing this Array[Place] with 4 elements of value "host"
>
> If I'm correct, the conclusion is that the syntax is pretty confused :(
>
> Thanks
>
> Richard Gomes
> M: +44(77)9955-6813
> http://tinyurl.com/frgomes
> twitter: frgomes
>
> JQuantLib is a library for Quantitative Finance written in Java.
> http://www.jquantlib.org/
> twitter: jquantlib
>
> On 19/11/10 08:40, Richard Gomes wrote:
> > Hi guys,
> >
> > I've seen code more or less like this:
> >
> >       for (host in Place.places()) {
> >           val workers : Array[Place] = new Array[Place][host];
> >    ...
> >       }
> >
> > What it means, exactly?
> > I'm confused with text "[host]" which looks strange.
> >
> >
> > I've changed "[host]" by "(host)" like shown below and it compiles.
> >
> >       for (host in Place.places()) {
> >           val test1 : Array[Place] = new Array[Place][host]; //
compiles
> >           val test2 : Array[Place] = new Array[Place](host); //
compiles
> >    ...
> >       }
> >
> > So... looks like the compiler is automagically interpreting "[host]" as
> > "(host)" ???
> >
> >
> > Thanks a lot
> >
> > Cheers :)
> >
>
>
------------------------------------------------------------------------------

> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users



      
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to