Ellipsis (computer programming): Difference between revisions

Content deleted Content added
m PHP: PHP-FIG PSR-2
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 14:
 
The [[GNU Compiler Collection]] has an extension to the C and C++ language to allow ''case ranges'' in [[switch statement]]s:
<sourcesyntaxhighlight lang="C">
switch(u) {
case 0 ... 0x7F : putchar(c); break;
Line 21:
default: error("not supported!");
}
</syntaxhighlight>
</source>
 
Delphi / Turbo Pascal / Free Pascal:
<sourcesyntaxhighlight lang="delphi">
var FilteredChars: set of [#0..#32,#127,'a'..'z'];
var CheckedItems: set of [4,10..38,241,58];
</syntaxhighlight>
</source>
 
In the [[Unified Modeling Language]] (UML), a two-character ellipsis is used to indicate variable cardinality of an association. For example, a cardinality of 1..* means that the number of elements aggregated in an association can range from 1 to infinity (a usage equivalent to [[Kleene plus]]).
Line 66:
PHP 5.6 supports<ref>https://wiki.php.net/rfc/variadics</ref> use of ellipsis to define an explicitly [[variadic function]], where <code>...</code> before an argument in a function definition means that arguments from that point on will be collected into an array. For example:
 
<sourcesyntaxhighlight lang="php">
function variadic_function($a, $b, ...$other)
{
Line 73:
 
var_dump(variadic_function(1, 2, 3, 4, 5));
</syntaxhighlight>
</source>
 
Produces this output:
<sourcesyntaxhighlight lang="php">
array(3) {
[0]=>
Line 85:
int(5)
}
</syntaxhighlight>
</source>
 
== Multiple dimensions ==
In [[Python (programming language)|Python]], particularly in [[numpy]], an ellipsis is used for slicing an arbitrary number of dimensions for a high-dimensional array:<ref>http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html</ref>
 
<sourcesyntaxhighlight lang="numpy">
>>> import numpy as np
>>> t = np.random.rand(2, 3, 4, 5)
Line 97:
>>> t[0, ...].shape # select 1st element from first dimension, copy rest
(3, 4, 5)
</syntaxhighlight>
</source>
 
== Other semantics ==