DART on Googlen avoimen lähdekoodin ohjelmointikieli, joka toimii verkkosivuilla ja servereissä, ja jolla voi JavaScriptiä paremmin hoitaa suurten verkkosovellusten koodaamisen. DART kielen kehitys aloitettiin 9/2011 ja 1.0-versio kielestä julkistettiin loppuvuodesta -2013. Nyt jo on olemassa lähes valmiit työkalut Chrome selainta varten. Blogger-blogien pitäjiä varten saamme ehkä kiintoisia Gadgetteja sivupalkkeihin ja muuta toiminnallisuutta verkkosivuille.
TÄMÄ blogi sisältää pääosin omia pohdintojani ja muistiinpanoja, eikä se varmaankaan tuo kovinkaan paljon uutta DART-kielen opiskeluun. Materiaali on pääosin KOPIOITU :( Dartlang-sivustoilta, josta kannattaa KÄYDÄ TARKISTAMASSA kielen viimeiset syntaksit.

perjantai 24. helmikuuta 2012

Miettimässä DART listoja, rakenne, kielioppi, käyttö

Tämä teksti on peräisin osoitteesta:  http://www.dartlang.org/docs/spec/index.html
Ja on siis   DART lang spec.0.07
Kopioin sen blogiini, jotta voin paremmin miettiä, muokata ja tarkastella sitä.
Kirjaan tähän ehkä omia huomioitani vähitelle.  Jostakin on siis aloitettava, ja listat ovat asia, joka minua on todella suuresti kiinnostanut.
X

Lists

A list literal denotes a list, which is an integer indexed collection of objects.

listLiteral:
     
const? typeArguments? '[' (expressionList ','?)? ']'
   ;
A list may contain zero or more objects. The number of elements in a list is its size. A list has an associated set of indices.  An empty list has an empty set of indices. A non-empty list has the index set {0 … n -1} where n is the size of the list. It is a runtime error to attempt to access a list using an index that is not a member of its set of indices.
If a list literal begins with the reserved word const, it is a constant list literal and it is computed at compile-time. Otherwise, it is a runtime list literal and it is evaluated at runtime.
It is a compile time error if an element of a constant list literal is not a compile-time constant. It is a compile time error if the type argument of a constant list literal includes a type variable.
The binding of a type variable is not known at compile-time, so we cannot use type variables inside compile-time constants.
The value of a constant list literal  const <E>[e1... en] is an object a that implements the built-in interface List<E>The ith element of a is vi+1, where vi is the value of the compile time expressionei.  The value of a constant list literal  const [e1... en] is defined as the value of a constant list literal const <Dynamic>[e1... en]. It is a run-time error to attempt to modify a constant list literal. 
Let list1 = const <V>[e11... e1nand list2 = const <U>[e21... e2nbe two constant list literals and let the  elements of list1 and list2  evaluate to  o11... o1n and o21... o2n respectively. Iff o1i ===o2i for 1 <= i <= n and V = U then list1 === list2.
In other words, constant list literals are canonicalized.
A runtime list literal <E>[e1... en]  is evaluated as follows:
  1. First, the expressions e1... en are evaluated in left to right order, yielding objects o1... on.
  2. A fresh instance a that implements the built-in interface List<E> is allocated.
  3. The ith element of a is set to oi+10 <= i <= n.
  4. The result of the evaluation is a.
Note that this specification does not specify an order in which the elements are set. This allows for parallel assignments into the list if an implementation so desires.  The order can only be observed in checked mode: if element i is not a subtype of the element type of the list, a dynamic type error will occur when a[i] is assigned oi-1.
A runtime list literal  [e1... en] is evaluated as  <Dynamic>[e1... en].

There is no restriction precluding nesting of list literals. It follows from the rules above that
<List<int>>[[1, 2, 3], [4, 5, 6]] is a list with type parameter List<int>, containing two lists with type parameter Dynamic.
The static type of a list literal of the form  const <E>[e1... en]  or the form <E>[e1... en] is List<E>. The static type a list literal of the form  const [e1... en]  or the form [e1... en] is List<Dynamic>.
It is tempting to assume that the type of the list literal would be computed based on the types of its elements. However, for mutable lists this may be unwarranted. Even for constant lists, we found this behavior to be problematic. Since compile-time is often actually runtime, the runtime system must be able to perform a complex least upper bound computation to determine a reasonably precise type. It is better to leave this task to a tool in the IDE. It is also much more uniform (and therefore predictable and understandable) to insist that whenever types are unspecified they are assumed to be the unknown type Dynamic.

So this was it, Dartlang spec 0.07. it is subject to changes, so watch the original page.



Ei kommentteja:

Lähetä kommentti