Talk:Comparison of programming languages (array)
![]() | This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||||
|
Vectorized Operations in Python
editAre 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 (talk • contribs) 18:54, 17 January 2008 (UTC)
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 (talk • contribs) 18:58, 17 January 2008 (UTC)
- 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)
- >>> 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)
- >>> x = [1,2,3]
Multi-dimensional arrays vs. Arrays of arrays
editThe 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)
- 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)
Default base index in Ada
editI'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)
- 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)
Vectorized Operations in PHP
editI 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)
VB
editI'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)
Array Sizes in C
editYou 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)
Simple source snippet to justify my edit.
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)
Scratch (MIT), Sense (OU) or LabVIEW
editno mention of Scratch (MIT), Sense (OU) or LabVIEW (National Instruments)
Unsure about Scratch, but Sense uses 1-indexed and LabVIEW uses zero-indexed arrays/lists — Preceding unsigned comment added by 86.1.43.198 (talk) 01:16, 4 March 2014 (UTC)
Edit by user:Mkcmkc on zero/one based array indexing
editUser:Mkcmkc has restored an edit[1] I reverted Jan19. This adds the following paragraph just before the table in the Syntax/Array dimensions section:
- Note particularly that some languages index from zero while others index from one. At least since Dijkstra's famous essay [1], zero-based indexing has been seen as superior, and new languages tend to use it.
My reasons for reverting this originally was that while the first sentence is true, it's somewhat redundant (the table actually provides that information on a per-language basis, as does the fourth table in the article) and really doesn't belong here. It's also incomplete (many languages can, at least optionally, starting indexing from values other than zero or one), and somewhat poorly worded. The second sentence, while a valid reference to Dijkstra's paper, presents a definite value judgment about the choice of base, which seems inappropriate in this article comparing different languages, even if the judgment is likely the consensus (and I'm not really sure that it is - I think it's likely for languages intended for professional developer's use, but languages inteded for non-specialists may well be different). The final part, that "new languages tend to use it" is unreferenced, although it's plausibly true. Rwessel (talk) 07:15, 31 March 2015 (UTC)
The Dijkstra reference is crucial, and something everyone should know, regardless of where they come down on this. Beyond that, as far as I know, no recent serious language has one-based indexing. The one-based languages are all either legacy from the 1990s and before, or toys. Mkcmkc (talk) 23:11, 13 May 2015 (UTC)
- I fail to see why the Dijkstra reference is crucial *here*. In an article on programming language design, sure, but not here. This article does not justify or evaluate the choices made by the various languages, it merely enumerates them. Nor is the pejorative "toys" useful. As I mentioned I suspect 1 is the default base in more than a few domain specific languages, calling those "toys" is not helpful. And then there's LUA, which is certainly serious, and most definitely not a toy. Rwessel (talk) 00:46, 14 May 2015 (UTC)
Add "fixed type" to "Array system cross-reference list" table
editThe Wikipedia data structure articles generally do not distinguish between the CompSci terms "list" (an ordered group of items) and the more-specific "array" (an ordered group of items of the same kind). And, in some languages, lists are implemented using arrays (such as an array of pointers in C.) That is not a problem in-and-of-itself, but I recommend that we add a column to the comparitive list to add clarity. That let's the reader see whether the array data structure is strict in the sense seen in C/C++ or is list-like like seen in some dynamic languages such as Python. Example:
>>> mylist = [1, 3.2, "hello", None, MyFavoriteClass()]
Proposed modified table header:
Programming language | Default base index | Specifiable index type[1] | Specifiable base index | Bound check | Multidimensional | Dynamically-sized | Vectorized operations | Fixed Type |
---|
The "Fixed Type" column would have either "yes", "no"; or perhaps "single" or "mixed".
Minor Change To APL Characters
edit- In the several subsections in which APL code is presented, lines for APL quite understandably use "ρ" (U+03C1) and "ι" (U+03B9) for the APL functional symbols Rho and Iota — however the Unicode codepoints (U+2374 and U+2373) for these symbols are what APL interpreters actually use. This distinction is important because if one were to Copy and Paste the existing text as is into a Unicode APL session, it would not execute because no Unicode-based APL interpreter recognizes U+03C1 and U+03B9 as APL functional symbols. Instead, these and related characters should be reserved for when the character set for APL names is extended to the Greek language.
- Also, instances of APL functional symbols in the HTML Numeric Character Reference form (&#xXXXX;) can be changed to the single character APL functional symbol for better readability.
As these are very minor changes meaningful to APL programmers only and invisible to everyone else, I propose we publish these changes.
Separate Entries for Wolfram Language and Mathematica
editAccording to the Wolfram Language page, Mathematica uses Wolfram language for its computations. I see no reason to include both in this comparison when they are the same language. — Preceding unsigned comment added by 129.93.191.80 (talk) 15:15, 8 September 2018 (UTC)
C++ adjustments for std::array
editNow that std::array
has been part of the C++ language definition for a dozen years (since C++11), it would probably make sense to adjust the C++ entries accordingly -- e.g. the "Array system cross-reference list" shows C++ as having no bounds checking even though std::array
has element access methods which are bounds checked (.at(); plus ones which aren't like operator[]). std::array
has size, first, and last functionality, which ought to qualify it for inclusion in the "Array dimensions" table (I assume the lack of all those in C-style arrays is what kept C and C++ out of that table, even though Jebix fifteen years ago entered a comment above showing C/C++ recipes for all those?). And C++20 also has std::span
providing slice functionality.
In fact, it's probably useful to separate out C-style arrays (supported in C and C++) from std::array
, since many of the features summarized on this page differ between the two. --24.91.152.172 (talk) 15:10, 7 March 2023 (UTC)