Ellipsis (computer programming)

Uses your system voice; voice and rate in settings.

Snapshot

≈ 6 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

In computer programming, ellipsis notation (.. or ...) is used to denote ranges, an unspecified number of arguments, or a parent directory. Most programming languages require the ellipsis to be written as a series of periods; a single (Unicode) ellipsis character cannot be used.

In computer programming, ellipsis notation (.. or ...) is used to denote ranges, an unspecified number of arguments, or a parent directory. Most programming languages require the ellipsis to be written as a series of periods; a single (Unicode) ellipsis character cannot be used. In Rust the ..= operator denotes an inclusive range for cases in matches and the .. operator represents a range not including the end value.

Perl and Ruby overload the ".." operator in scalar context as a flip-flop operator - a stateful bistable Boolean test, roughly equivalent to "true while x but not yet y", similarly to the "," operator in sed and AWK. GNU C compatible compilers first provided an extension to the C and C++ language to allow case ranges in switch statements. This was later officially added to C in C2Y. include include include void writeUnicode(char32_t c) { switch (c) { // matches any value between [0, 0x7F] inclusive case 0 ...

0x7F: putchar(c); break; // matches any value between [0x80, 0x7FF] inclusive case 0x80 ... 0x7FF: putchar(0xC0 + c >> 6); putchar(0x80 + c & 0x3f); break; // matches any value between [0x800, 0xFFFF] inclusive case 0x800 ...

0xFFFF: putchar(0xE0 + c >> 12); putchar(0x80 + (c >> 6) & 0x3f); putchar(0x80 + (c >> 12)); break; default: unreachable(); } } Additionally, GNU C allows a similar range syntax for designated initializers, available in the C language only: int nums[10] = { [0...5] = 1 }; Delphi / Turbo Pascal / Free Pascal: var FilteredChars: set of [#0..#32,#127,'a'..'z']; var CheckedItems: set of [4,10..38,241,58]; 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).

Parent directory

On Windows and Unix-like operating systems, ".." is used to access the parent directory in a path. In Abstract Syntax Notation One (ASN.1), the ellipsis is used as an extension marker to indicate the possibility of type extensions in future revisions of a protocol specification. In a type constraint expression like A ::= INTEGER (0..127, ..., 256..511) an ellipsis is used to separate the extension root from extension additions.

The definition of type A in version 1 system of the form A ::= INTEGER (0..127, ...) and the definition of type A in version 2 system of the form A ::= INTEGER (0..127, ..., 256..511) constitute an extension series of the same type A in different versions of the same specification. The ellipsis can also be used in compound type definitions to separate the set of fields belonging to the extension root from the set of fields constituting extension additions. Here is an example:

C and C++

In the C and C++ programming languages, an ellipsis is used to represent a variable number of parameters to a function. These C-style variadic parameters are type-unsafe, not capturing any information about types of the passed variadic arguments, and must be stored in a va_list type and read using macros like va_start() , va_arg() , and va_end() .

For example: int printf(const char* fmt, ...); The above function in C could then be called with different types and numbers of parameters such as: // prints "numbers 5 10 15" printf("numbers %i %i %i", 5, 10, 15); // prints "input string another string, 0.5" printf("input string %s, %f", "another string", 0.5); C99 introduced macros with a variable number of arguments.

C++11 included the new variadic macro features introduced in the C99 preprocessor, and also introduced templates with a variable number of arguments, called variadic templates, which are how type-safe variadic parameters are implemented in C++. using std::string_view; template void myPrintf(string_view fmt, Args... parameters);

Java

As of version 1.5, Java has adopted this "varargs" functionality. For example: public int func(int num, String... names); This actually converts to String[] names , but is not required to be wrapped in an array.

PHP

PHP 5.6 supports use of ellipsis to define an explicitly variadic function, where ... before an argument in a function definition means that arguments from that point on will be collected into an array.

For example: function variadic_function($a, $b, ...$other) { return $other; } var_dump(variadic_function(1, 2, 3, 4, 5)); Produces this output: array(3) { [0]=> int(3) [1]=> int(4) [2]=> int(5) } (define-syntax let* (syntax-rules () ((let* () body1 body2 ...) (let () body1 body2 ...)) ((let* ((name1 val1) (name2 val2) ...) body1 body2 ...) (let ((name1 val1)) (let* ((name2 val2) ...) body1 body2 ...))))) SRFI 46 was proposed to extend syntax-rules to allow the user to specify an ellipsis identifier.

This is useful for disambiguating when ellipsis are use in nested macro definitions. This feature was later included in R7RS. import numpy as np from typing import NDArray t: NDArray[int] = np.random.rand(2, 3, 4, 5) select 1st element from last dimension, copy rest (2, 3, 4) t[..., 0].shape select 1st element from first dimension, copy rest (3, 4, 5) t[0, ...].shape x = [ 1 2 3 ...

4 5 6 ]; semantically equivalent to the single line x = [ 1 2 3 4 5 6 ]; In Raku an actual Unicode (U+2026) ellipsis (…) character is used to serve as a type of marker in a format string. // old style: PHP 8.0 and older $foo = [$this, 'foo']; $fn = Closure::fromCallable('strlen'); // new style: PHP 8.1 and newer $foo = $this->foo(...); $fn = strlen(...); type IntTuple = tuple[int, ...] one_int: IntTuple = (0,) two_ints: IntTuple = (0, 1) three_ints: IntTuple = (0, 1, 2) with_bools: IntTuple = (0, True, 1, False) # OK; bool is a subtype of int, so True and False are of type int The ellipsis can also be used as the first parameter in a collections.abc.Callable annotation to denote a callable object with an arbitrary parameter list.

Any callable that returns values of type R is a Callable[..., R] , regardless of how many or what kinds of arguments it accepts: from collections.abc import Callable type ReturnsInt = Callable[..., int] def no_arguments() -> int: return 0 def one_positional_argument(spam: None, /) -> int: return 1 def one_keyword_argument(*, ham: int) -> int: return 2 def variadic_argument_list(*args: str, **kwargs: str) -> int: return 3 def returns_bool(eggs: bool) -> bool: return eggs none: ReturnsInt = no_arguments positional: ReturnsInt = one_positional_argument keyword: ReturnsInt = one_keyword_argument variadic: ReturnsInt = variadic_argument_list returns_subtype: ReturnsInt = returns_bool # OK; every bool is of type int

References

Text derived from https://en.wikipedia.org/w/index.php?oldid=1372636131 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

16 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.