Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "VJET/Typing Arrays with VJETDocs"
Line 1: | Line 1: | ||
− | + | <span style="color:#333333">In JavaScript there is the Array type.</span> Below <span style="color:#333333">are examples of using JavaScript Array.</span><br/> | |
<source lang="javascript"> | <source lang="javascript"> | ||
var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array | var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array | ||
Line 11: | Line 11: | ||
What elements you put in the array are up to you. In essence, any JavaScript object can be put in the array. In our previous examples it appears that we only want browser names in our Array. Actually we only want Strings from a typing standpoint. | What elements you put in the array are up to you. In essence, any JavaScript object can be put in the array. In our previous examples it appears that we only want browser names in our Array. Actually we only want Strings from a typing standpoint. | ||
− | + | <span style="color:#333333">VJETDocs allows you to be very specific about what type you want your array to be. </span> | |
− | + | <span style="color:#333333">{_}Array-Dimension{_}</span><span style="color:#333333"> = "<nowiki>[[</nowiki>" "<nowiki>]]</nowiki>"</span> | |
− | + | <span style="color:#333333">Ex: <nowiki>[[</nowiki><nowiki>]]</nowiki> </span> | |
− | + | <span style="color:#333333">{_}Array-Dimensions{_}</span><span style="color:#333333"> = one or more </span><span style="color:#333333">{_}Array-Dimension's{_}</span><span style="color:#333333"> back to back</span> | |
− | + | <span style="color:#333333">Ex: <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> or <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> </span> | |
− | + | <span style="color:#333333">Array-Type: </span><span style="color:#333333">{_}Limited-Type-Name{_}</span><span style="color:#333333"> </span><span style="color:#333333">{_}Array-Dimensions{_}</span><span style="color:#333333"> </span> | |
− | + | <span style="color:#333333">Examples of a Vjet Array Type: String<nowiki>[[</nowiki><nowiki>]]</nowiki> or Number<nowiki>[[</nowiki><nowiki>]]</nowiki> or Date<nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki>or worker.Task<nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> </span> | |
− | + | <span style="color:#333333">An array with a single <nowiki>[[</nowiki><nowiki>]]</nowiki> pairs is called a single dimension array. </span><br/> | |
<source lang="javascript"> | <source lang="javascript"> | ||
var out = vjo.sysout.println; | var out = vjo.sysout.println; | ||
Line 38: | Line 38: | ||
console> | console> | ||
− | + | <span style="color:#333333">Mark: 91</span> | |
− | + | <span style="color:#333333">Sean: 77</span> | |
− | + | <span style="color:#333333">Juan: 84 </span><br/> | |
− | + | <span style="color:#333333">It is possible to define arrays of arrays; these are called multi-dimension arrays. Multi-dimension arrays are defined by how many consecutive <nowiki>[[</nowiki><nowiki>]]</nowiki> pairs. The number of <nowiki>[[</nowiki><nowiki>]]</nowiki> pairs is often referred to as the n-dimensional array. Thus <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> means a 2 dimensional array and <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> means a 3-dimensional array and so on. </span><span style="color:#333333">For example <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> is a two-dimensional array. <nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki><nowiki>[[</nowiki><nowiki>]]</nowiki> is a three dimensional array and so on.</span><br/> | |
− | + | <span style="color:#333333">Here is an example of a two dimensional array of Number.</span><br/> | |
<source lang="javascript"> | <source lang="javascript"> | ||
var keys = [ //< Number[][] | var keys = [ //< Number[][] | ||
Line 58: | Line 58: | ||
</source> | </source> | ||
− | + | <span style="color:#333333">console> total: 45 </span><br/> | |
− | + | <span style="color:#333333">We can have arrays of native types and vjet types. We can even have arrays of functions (we haven't described them yet). </span> | |
− | + | <span style="color:#333333">We can even have an array of type-reference (although it may not be too useful).</span> | |
[[Category:VJET]] | [[Category:VJET]] |
Revision as of 07:23, 1 December 2012
In JavaScript there is the Array type. Below are examples of using JavaScript Array.
var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array var browsers = new Array('Firefox', 'Chrome', 'Safari') ; //< Array var browsers = new Array() ; //< Array browsers[0] = 'FireFox' ; browsers[1] = 'Chrome' ; browsers[2] = 'Safari' ;
What elements you put in the array are up to you. In essence, any JavaScript object can be put in the array. In our previous examples it appears that we only want browser names in our Array. Actually we only want Strings from a typing standpoint.
VJETDocs allows you to be very specific about what type you want your array to be.
{_}Array-Dimension{_} = "[[" "]]"
Ex: [[]]
{_}Array-Dimensions{_} = one or more {_}Array-Dimension's{_} back to back
Ex: [[]][[]] or [[]][[]][[]]
Array-Type: {_}Limited-Type-Name{_} {_}Array-Dimensions{_}
Examples of a Vjet Array Type: String[[]] or Number[[]] or Date[[]][[]]or worker.Task[[]][[]][[]]
An array with a single [[]] pairs is called a single dimension array.
var out = vjo.sysout.println; var scores = [91, 77, 84] ; //< Number[] var names = ['Mark', 'Sean', 'Juan'] ; //< String[] for(var i = 0; i < 3; i++) { var name = names[i] ; //< String var score = scores[i] ; //< Number out(name + ": " + score)
console>
Mark: 91
Sean: 77
Juan: 84
It is possible to define arrays of arrays; these are called multi-dimension arrays. Multi-dimension arrays are defined by how many consecutive [[]] pairs. The number of [[]] pairs is often referred to as the n-dimensional array. Thus [[]][[]] means a 2 dimensional array and [[]][[]][[]] means a 3-dimensional array and so on. For example [[]][[]] is a two-dimensional array. [[]][[]][[]] is a three dimensional array and so on.
Here is an example of a two dimensional array of Number.
var keys = [ //< Number[][] [1, 2, 3], [4, 5, 6], [7, 8, 9] ]; var total = 0 ; //< Number for(var row = 0; row < 3; row++) { for (var col = 0; col < 3; col++) { total += keys[row][col] ; vjo.sysout.println('total: ' + total) ;
console> total: 45
We can have arrays of native types and vjet types. We can even have arrays of functions (we haven't described them yet). We can even have an array of type-reference (although it may not be too useful).