Ellipsis (computer programming): Difference between revisions

Content deleted Content added
Adding local short description: "Notation for ranges or parent directory", overriding Wikidata description "notation for ranges in computer programming"
Zambyte (talk | contribs)
m Scheme: Added reference title
Tags: Mobile edit Mobile app edit Android app edit App section source
 
(9 intermediate revisions by 7 users not shown)
Line 13:
In [[Rust (programming language)|Rust]] the <code>..=</code> operator denotes an inclusive range for cases in matches and the <code>..</code> operator represents a range not including the end value.
 
Perl and Ruby [[Operator overloading|overload]] the ".." operator in scalar context as a [[flip-flop operator]] - a [[stateful]] [[bistability|bistable]] [[Boolean datatypedata type|Boolean]] test, roughly equivalent to "true while ''x'' but not yet ''y''", similarly to the "," operator in [[Sed (programming language)|sed]] and [[AWK programming language|AWK]].<ref>[http://perldoc.perl.org/perlop.html#Range-Operators-operator%2c-range-range-..-... perlop - perldoc.perl.org<!-- Bot generated title -->]</ref>
 
[[GNU Compiler Collection|GNU C]] compatible compilers have an extension to the C and C++ language to allow ''case ranges'' in [[switch statement]]s:
Line 42:
 
== Incomplete code ==
{{anchor|yadayada}} <!-- ref from Perl -->
In Perl<ref>{{Cite web |url=https://perldoc.perl.org/perlsyn.html#The-Ellipsis-Statement |title=Perlsyn - Perl syntax - Perldoc Browser}}</ref> and [[Raku (programming language)|Raku]]<ref>{{Cite web |url=https://doc.perl6.org/language/operators#listop_... |title=Operators }}</ref> 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 <code>A ::= INTEGER (0..127, ..., 256..511)</code> an ellipsis is used to separate the extension root from extension additions. The definition of type A in version 1 system of the form <code>A ::= INTEGER (0..127, ...)</code> and the definition of type A in version 2 system of the form <code>A ::= INTEGER (0..127, ..., 256..511)</code> 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: {{code|2=asn1|1=B ::= SEQUENCE { a INTEGER, b INTEGER, ..., c INTEGER } }} <!-- Is the s.n. ellipsis defined as a "..." trigraph or something else? This paragraph is a matter of syntax, not text *representation*, and therefore is misplaced. --Incnis Mrsi -->
 
== Variable number of parameters ==
Line 92 ⟶ 95:
}
</syntaxhighlight>
 
== Scheme ==
The <code>syntax-rules</code> hygienic macro system originally introduced in [[Scheme (programming language)|R4RS]] uses <code>...</code> to specify that the proceeding pattern may be matched zero or more times. For example, the following code could be used to implement the standard <code>let*</code> form, recursively in terms of itself, and the more primitive <code>let</code>:
 
<syntaxhighlight lang="scheme">
(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 ...)))))
</syntaxhighlight>
 
SRFI 46<ref>{{Cite web |url=https://srfi.schemers.org/srfi-46/srfi-46.html |title=SRFI 46}}</ref> was proposed to extend <code>syntax-rules</code> 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.
 
== Multiple dimensions ==
In [[Python (programming language)|Python]], the ellipsis is a nullary expression that represents the <code>Ellipsis</code> singleton.

It's used particularly in [[NumPy]], where an ellipsis is used for slicing an arbitrary number of dimensions for a high-dimensional array:<ref>{{Cite web |url=http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html |title=Indexing routines — NumPy v1.22 Manual}}</ref>
 
<syntaxhighlight lang="pycon">
Line 106 ⟶ 126:
 
== Other semantics ==
 
In [[MATLAB]], a three-character ellipsis is used to indicate [[line continuation]],<ref>[http://www.mathworks.com/help/techdoc/matlab_env/f0-5789.html#f0-5857 Mathworks.com]</ref> making the sequence of lines
=== MATLAB ===
In [[MATLAB]], a three-character ellipsis is used to indicate [[line continuation]],<ref>[{{Cite web |url=http://www.mathworks.com/help/techdoc/matlab_env/f0-5789.html#f0-5857 |title=Mathworks.com] |access-date=2011-04-14 |archive-date=2011-06-29 |archive-url=https://web.archive.org/web/20110629105840/http://www.mathworks.com/help/techdoc/matlab_env/f0-5789.html#f0-5857 |url-status=dead }}</ref> making the sequence of lines
:<code>x = [ 1 2 3 ...<br />4 5 6 ];</code>
semantically equivalent to the single line
Line 112 ⟶ 134:
 
In Raku an actual [[Unicode]] (U+2026) ellipsis (…) character is used to serve as a type of marker in a format string.<ref>{{cite web |title=Exegesis 7: Formats |editor-first=Larry |editor-last=Wall |editor-link=Larry Wall |author-first=Damian |author-last=Conway |author-link=Damian Conway |date=2006-05-29 |orig-date=2004-02-26 |version=2 |number=7 |website=dev.perl.org |url=http://dev.perl.org/perl6/doc/design/exe/E07.html#And_mark_what_way_I_make... |url-status=dead |archive-url=https://web.archive.org/web/20110615080653/http://dev.perl.org/perl6/doc/design/exe/E07.html#And_mark_what_way_I_make... |archive-date=2011-06-15}}</ref>
 
=== PHP ===
 
Since [[PHP]] 8.1, a nullary ellipsis may be used to create a [[closure (computer programming)|closure]] from a callable or an object method:<ref>{{Cite web |title=PHP 8.1.0 Release Announcement |url=https://www.php.net/releases/8.1/en.php#first_class_callable_syntax |access-date=2023-03-29 |website=php.net}}</ref>
 
<syntaxhighlight lang="php">
// 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(...);
</syntaxhighlight>
 
=== Python ===
 
In Python, the ellipsis can also be used as the first parameter within the <code>collections.abc.Callable</code> type annotation to denote any number of arguments:<ref>{{Cite web |title=typing — Support for type hints § typing.Callable |url=https://docs.python.org/3/library/typing.html#typing.Callable |access-date=2023-03-29 |website=Python 3.11.2 Documentation}}</ref>
<!-- typing.Callable is deprecated in favor of collections.abc.Callable, but documentation has not yet been moved! -->
 
<syntaxhighlight lang="python">
from collections.abc import Callable
from typing import TypeAlias, Any
 
VarFunction: TypeAlias = Callable[..., Any]
</syntaxhighlight>
 
==References==