fbpx
Wikipedia

Ellipsis (computer programming)

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.

Ranges edit

In some programming languages (including Ada, Perl, Ruby, Apache Groovy, Kotlin, Haskell, and Pascal), a shortened two-dot ellipsis is used to represent a range of values given two endpoints; for example, to iterate through a list of integers between 1 and 100 inclusive in Perl:

foreach (1..100)

In Ruby the ... operator denotes a half-open range, i.e. that includes the start value but not the end value.

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.[1]

GNU C compatible compilers have an extension to the C and C++ language to allow case ranges in switch statements:

switch(u) {  case 0 ... 0x7F : putchar(c); break;  case 0x80 ... 0x7FF : putchar(0xC0 + c>>6); putchar( 0x80 + c&0x3f); break;  case 0x800 ... 0xFFFF : putchar(0xE0 + c>>12); putchar( 0x80 + (c>>6)&0x3f); putchar( 0x80 + (c>>12) ); break;  default: error("not supported!"); } 

Additionally, GNU C allows a similar range syntax for designated initializers, available in the C language only:

int array[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 edit

On Windows and Unix-like operating systems, ".." is used to access the parent directory in a path.

Incomplete code edit

In Perl[2] and Raku[3] the 3-character ellipsis is also known as the "yada yada yada" operator and, similarly to its linguistic meaning, serves as a "stand-in" for code to be inserted later.

Python3 also allows the 3-character ellipsis to be used as an expressive place-holder for code to be inserted later.

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: B ::= SEQUENCE { a INTEGER, b INTEGER, ..., c INTEGER }

Variable number of parameters edit

C and C++ edit

In the C programming language, an ellipsis is used to represent a variable number of parameters to a function. For example:

int printf( const char* format, ... );[4]

The above function in C could then be called with different types and numbers of parameters such as:

printf("numbers %i %i %i", 5, 10, 15);

and

printf("input string %s, %f", "another string", 0.5);

C99 introduced macros with a variable number of arguments.[5]

C++11 included the C99 preprocessor,[6] and also introduced templates with a variable number of arguments.[7]

Java edit

As of version 1.5, Java has adopted this "varargs" functionality. For example:

public int func(int num, String... strings)

PHP edit

PHP 5.6 supports[8] 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) } 

Multiple dimensions edit

In Python, the ellipsis is a nullary expression that represents the Ellipsis singleton.

It's used particularly in NumPy, where an ellipsis is used for slicing an arbitrary number of dimensions for a high-dimensional array:[9]

>>> import numpy as np >>> t = np.random.rand(2, 3, 4, 5) >>> t[..., 0].shape # 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) 

Other semantics edit

MATLAB edit

In MATLAB, a three-character ellipsis is used to indicate line continuation,[10] making the sequence of lines

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.[11]

PHP edit

Since PHP 8.1, a nullary ellipsis may be used to create a closure from a callable or an object method:[12]

// 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(...); 

Python edit

In Python, the ellipsis can also be used as the first parameter within the collections.abc.Callable type annotation to denote any number of arguments:[13]

from collections.abc import Callable from typing import TypeAlias, Any VarFunction: TypeAlias = Callable[..., Any] 

References edit

  1. ^ perlop - perldoc.perl.org
  2. ^ "Perlsyn - Perl syntax - Perldoc Browser".
  3. ^ "Operators".
  4. ^ "Printf - C++ Reference".
  5. ^ Variadic Macros - Using the GNU Compiler Collection (GCC)
  6. ^ Working draft changes for C99 preprocessor synchronization - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm
  7. ^ "Working Draft, Standard for Programming Language C++" (PDF).: 14.5.3 Variadic templates
  8. ^ "PHP: RFC:variadics".
  9. ^ "Indexing routines — NumPy v1.22 Manual".
  10. ^ . Archived from the original on 2011-06-29. Retrieved 2011-04-14.
  11. ^ Conway, Damian (2006-05-29) [2004-02-26]. Wall, Larry (ed.). . dev.perl.org. 2. Archived from the original on 2011-06-15.
  12. ^ "PHP 8.1.0 Release Announcement". php.net. Retrieved 2023-03-29.
  13. ^ "typing — Support for type hints § typing.Callable". Python 3.11.2 Documentation. Retrieved 2023-03-29.

ellipsis, computer, programming, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, ellipsis, computer, programming, ne. This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Ellipsis computer programming news newspapers books scholar JSTOR September 2014 Learn how and when to remove this message 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 Contents 1 Ranges 2 Parent directory 3 Incomplete code 4 Variable number of parameters 4 1 C and C 4 2 Java 4 3 PHP 5 Multiple dimensions 6 Other semantics 6 1 MATLAB 6 2 PHP 6 3 Python 7 ReferencesRanges editIn some programming languages including Ada Perl Ruby Apache Groovy Kotlin Haskell and Pascal a shortened two dot ellipsis is used to represent a range of values given two endpoints for example to iterate through a list of integers between 1 and 100 inclusive in Perl foreach 1 100 In Ruby the operator denotes a half open range i e that includes the start value but not the end value 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 1 GNU C compatible compilers have an extension to the C and C language to allow case ranges in switch statements switch u case 0 0x7F putchar c break case 0x80 0x7FF putchar 0xC0 c gt gt 6 putchar 0x80 c amp 0x3f break case 0x800 0xFFFF putchar 0xE0 c gt gt 12 putchar 0x80 c gt gt 6 amp 0x3f putchar 0x80 c gt gt 12 break default error not supported Additionally GNU C allows a similar range syntax for designated initializers available in the C language only int array 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 editOn Windows and Unix like operating systems is used to access the parent directory in a path Incomplete code editIn Perl 2 and Raku 3 the 3 character ellipsis is also known as the yada yada yada operator and similarly to its linguistic meaning serves as a stand in for code to be inserted later Python3 also allows the 3 character ellipsis to be used as an expressive place holder for code to be inserted later 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 B SEQUENCE a INTEGER b INTEGER c INTEGER Variable number of parameters editC and C edit In the C programming language an ellipsis is used to represent a variable number of parameters to a function For example span class kt int span span class w span span class nf printf span span class p span span class w span span class k const span span class w span span class kt char span span class o span span class w span span class n format span span class p span span class w span span class p span span class w span span class p span 4 The above function in C could then be called with different types and numbers of parameters such as span class n printf span span class p span span class s numbers i i i span span class p span span class w span span class mi 5 span span class p span span class w span span class mi 10 span span class p span span class w span span class mi 15 span span class p span and span class n printf span span class p span span class s input string s f span span class p span span class w span span class s another string span span class p span span class w span span class mf 0 5 span span class p span C99 introduced macros with a variable number of arguments 5 C 11 included the C99 preprocessor 6 and also introduced templates with a variable number of arguments 7 Java edit As of version 1 5 Java has adopted this varargs functionality For example span class kd public span span class w span span class kt int span span class w span span class nf func span span class p span span class kt int span span class w span span class n num span span class p span span class w span span class n String span span class p span span class w span span class n strings span span class p span PHP edit PHP 5 6 supports 8 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 gt int 3 1 gt int 4 2 gt int 5 Multiple dimensions editIn Python the ellipsis is a nullary expression that represents the Ellipsis singleton It s used particularly in NumPy where an ellipsis is used for slicing an arbitrary number of dimensions for a high dimensional array 9 gt gt gt import numpy as np gt gt gt t np random rand 2 3 4 5 gt gt gt t 0 shape select 1st element from last dimension copy rest 2 3 4 gt gt gt t 0 shape select 1st element from first dimension copy rest 3 4 5 Other semantics editMATLAB edit In MATLAB a three character ellipsis is used to indicate line continuation 10 making the sequence of lines x 1 2 3 br 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 11 PHP edit Since PHP 8 1 a nullary ellipsis may be used to create a closure from a callable or an object method 12 old style PHP 8 0 and older foo this foo fn Closure fromCallable strlen new style PHP 8 1 and newer foo this gt foo fn strlen Python edit In Python the ellipsis can also be used as the first parameter within the collections abc Callable type annotation to denote any number of arguments 13 from collections abc import Callable from typing import TypeAlias Any VarFunction TypeAlias Callable Any References edit perlop perldoc perl org Perlsyn Perl syntax Perldoc Browser Operators Printf C Reference Variadic Macros Using the GNU Compiler Collection GCC Working draft changes for C99 preprocessor synchronization http www open std org jtc1 sc22 wg21 docs papers 2004 n1653 htm Working Draft Standard for Programming Language C PDF 14 5 3 Variadic templates PHP RFC variadics Indexing routines NumPy v1 22 Manual Mathworks com Archived from the original on 2011 06 29 Retrieved 2011 04 14 Conway Damian 2006 05 29 2004 02 26 Wall Larry ed Exegesis 7 Formats dev perl org 2 Archived from the original on 2011 06 15 PHP 8 1 0 Release Announcement php net Retrieved 2023 03 29 typing Support for type hints typing Callable Python 3 11 2 Documentation Retrieved 2023 03 29 Retrieved from https en wikipedia org w index php title Ellipsis computer programming amp oldid 1211889477, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.