Jump to content

Talk:Comparison of programming languages (array)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Oneiros (talk | contribs) at 19:40, 17 January 2013 (project). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconComputing: CompSci Start‑class Low‑importance
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
StartThis article has been rated as Start-class on Wikipedia's content assessment scale.
LowThis article has been rated as Low-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Computer science (assessed as Low-importance).
Things you can help WikiProject Computer science with:

Vectorized Operations in Python

Are you sure that native python supports vectorized operations? I am under the impression that this requires an external set of packages such as numpy. If so, then "yes" in the vectorized column is a bit misleading and a footnote should be added explaining this. —Preceding unsigned comment added by Ty8inf (talkcontribs) 18:54, 17 January 2008 (UTC)[reply]

I did a quick test in python2.4:

 Python 2.4.4 (#2, Apr  5 2007, 20:11:18) 
 [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> x = [1,2,3]
 >>> y = [4,5,6];
 >>> x+y;
 [1, 2, 3, 4, 5, 6]

So it appears that native python does not provide such support. —Preceding unsigned comment added by Ty8inf (talkcontribs) 18:58, 17 January 2008 (UTC)[reply]

Note that there is no reason for footnote 18 - because with 3rd party extension every programming lanugage - including assember support vectorized operations - this is nothing special which need to be mentioned. Also note that I did not put down an Yes for Ada even while Ada has "Ada.Numerics.Generic_Real_Arrays" and "Ada.Numerics.Generic_Complex_Arrays" - but they are libraries and not language features. --Krischik T 08:49, 30 March 2008 (UTC)[reply]
>>> x = [1,2,3]
>>> y = [4,5,6]
>>> map(lambda a,b: a+b, x,y)
[5, 7, 9]
just using keywords :) --77.3.191.111 (talk) 13:33, 6 August 2010 (UTC)[reply]

Multi-dimensional arrays vs. Arrays of arrays

The table would benefit if there were two columns. One for support for multi-dimensional arrays and the other for support for arrays of arrays. I think it's always true that a language supporting arrays of arrays can emulate multi-dimensional arrays, so this fact should be in a paragraph and not a footnote. I also think it's always true that a language supporting arrays of arrays can have triangular arrays. That may be worth mentioning also. Unfortunately I'm not knowledgeable about all the languages in the table to make the change myself. —Egriffin (talk) 21:31, 23 January 2008 (UTC)[reply]

Indeed an extra article is needed - also mentioning which features are not supported by the emulation - two dimensional array slices come to my mind here. Mind you: most languages which don't support two dimensional arrays also don't support array slices. And this might not be a coincidence: Having one but not the other might not make much sense. Note: Triangular arrays need access types and heap memory in the middle (C/C++ users might might overlook that because C/C++ mixes the two concepts into some mushy hybrid). --Krischik T 09:10, 11 February 2008 (UTC)[reply]

Default base index in Ada

I'm not sure it's correct to say that Ada has a default base index; the base index is always specified explicitly when the array is declared. However it does appear that Ada culture is 1-origin; for instance, the dimensions of a multidimensional array are numbered from 1 in attribute invocations. ScottBurson (talk) 18:24, 27 January 2008 (UTC)[reply]

Consider the following example:
type Base_Colours is (Red, Green, Blue);
type Colour_Value is mod 256;
type RGB_Colour is array Base_Colours of Colour_Value;
The base index is not given but implicitly taken from the enumeration. Note that all Ada Compilers I know of will internally us a 0 to represent Red. The one place where Ada culture is 1-origin are Strings. But beware - in following demo World'First will be 7 not 1!
Hello_World : String := "Hello World!"
World       : String := Hello_World (7 .. 11);
Note that both examples are not theoretically border cases but quite common in Ada culture. --Krischik T 09:24, 11 February 2008 (UTC)[reply]

Vectorized Operations in PHP

I know that PHP defines array slices, but I see nothing to indicate that PHP supports the type of vectorized arithmetic operations that pertains to this article. Could someone knowledgable comment on PHP's capabilities in this area? -- Ty8inf (talk) 01:27, 29 January 2008 (UTC)[reply]

VB

I've corrected the Visual Basic lowerbound to 0. To quote the VB 6.0 help, "Because the default base is 0, the Option Base statement is never required." NB. The default lowerbound was also 0 in QBasic, GW-Basic and iirc earlier MS Basics. So the article, in specifying 1 as the default lowerbound for BASIC, may be incorrect, depending which edition of BASIC it is talking about (the original Dartmouth one maybe?). —Preceding unsigned comment added by 195.72.173.51 (talk) 15:11, 11 December 2008 (UTC)[reply]

Array Sizes in C

You can find the number of elements in a C array because the sizeof operator returns the number of bytes occupied by an array. It even works for multi-dimensional arrays.

#include <stdio.h>

int main(void) {
	int array[][4] = {{1, 2, 3, 0}, {4, 5, 6, 0}, {7, 8, 9, 0}};
	unsigned long nelm, nrow, ncol;
	
	printf("The array occupies %lu bytes.\n", sizeof(array));
	printf("Each row in the array occupies %lu bytes.\n", sizeof(*array));
	printf("Each element in the array occupies %lu bytes.\n", sizeof(**array));

	nelm = sizeof(array) / sizeof(**array); /* number of elements */
	nrow = sizeof(array) / sizeof(*array); /* number of rows */
	ncol = sizeof(*array) / sizeof(**array); /* number of columns */
	printf("The array has %lu elements in %lu rows by %lu columns.\n", nelm, nrow, ncol);
	
	return 0; 
}

The output is:

 The array occupies 48 bytes.
 Each row in the array occupies 16 bytes.
 Each element in the array occupies 4 bytes.
 The array has 12 elements in 3 rows by 4 columns.

The sizes are implementation/hardware dependent, but the simple math for the number of elements works out despite of this. This method is commonly used when passing an array to a function. Otherwise the size information is lost because an array is converted to a pointer to the first element when it is passed to a function. Jebix (talk) 05:10, 17 December 2008 (UTC)[reply]

Simple source snippet to justify my edit.

{

	double array_data[1024], *array;
	int n;

	array = &(array_data[512]);
	
	for (n=-512; n<512; n++)
	{
		array[n] = (double)n;
	}
	

}

96.252.13.17 (talk) 00:34, 28 February 2010 (UTC)[reply]