Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tilde
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Computer languages ==== =====Regex===== The tilde is used in the [[AWK]] [[programming language]] as part of the pattern match operators for [[regular expression]]s:<ref>{{cite web |title=The GNU Awk User's Guide |website=GNU Manuals Online |url=https://www.gnu.org/software/gawk/manual/html_node/Regexp-Usage.html |publisher=Free Software Foundation, Inc. |access-date=2024-10-20 |at=3.1 How to Use Regular Expressions}}</ref> *<code>''variable'' ~ /''regex''/</code> returns true if the variable is matched. *<code>''variable'' !~ /''regex''/</code> returns false if the variable is matched. The operators are also used in the [[SQL]] variant of the database [[PostgreSQL]].<ref>{{cite web |title=PostgreSQL 17.0 Documentation |author=The PostgreSQL Global Development Group |date=2024-09-26 |url=https://www.postgresql.org/docs/17/index.html |access-date=2024-10-20 |at=[https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP 9.7.3.{{nbsp}}POSIX Regular Expressions]}}</ref> A variant of this, with the plain tilde replaced with <code>=~</code>, was adopted in [[Perl]]<ref>{{cite web |title=Perl expressions: operators, precedence, string literals |website=Perldoc Browser |url=https://perldoc.perl.org/5.40.0/perlop |access-date=2024-10-20 |at=[https://perldoc.perl.org/5.40.0/perlop#Binding-Operators Binding Operators]}}</ref><!--, and this semi-standardization has led to the use of these operators in other programming languages-->. [[Ruby programming language|Ruby]] also uses this variant without the negated operator.<ref>{{cite web |title=class Regexp |work=Documentation for Ruby 3.3 |url=https://docs.ruby-lang.org/en/3.3/Regexp.html |access-date=2024-10-20}}</ref> =====Negation===== In [[APL (programming language)|APL]]<ref name="j303">{{cite web |title=APL2 Programming: Language Reference |publisher=[[IBM]] |url=https://www.ibm.com/downloads/cas/ZOKMYKOY |date=February 1994 |edition=2nd |access-date=2024-10-22}}</ref>{{rp|68}} and [[MATLAB]],<ref>{{cite web |title=MATLAB Operators and Special Characters - MATLAB & Simulink |website=MathWorks |url=https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html |access-date=2024-10-22}}</ref> tilde represents the monadic logical function NOT. and in APL it additionally represents the dyadic [[multiset]] function ''without'' ([[Complement (set theory)#Relative complement|set difference]]).<ref name="j303"/>{{rp|258}} In [[C (programming language)|C]] the tilde character is used as [[bitwise NOT]] unary [[Operators in C and C++|operator]], following the notation in logic (an <code>!</code> causes a logical NOT, instead).<ref>{{cite web |title=Programming languages — C |url=https://files.lhmouse.com/standards/ISO%20C%20N2176.pdf |author=ISO/IEC |access-date=2024-10-19 |page=64 }}</ref> This is also used by many languages based on or influenced by C, such as [[C++]], [[C Sharp (programming language)|C#]], [[D programming language|D]], [[Java (programming language)|Java]], [[JavaScript]], [[Perl]], [[PHP]], and [[Python (programming language)|Python]].<ref name="rigaux">{{Cite web |title=syntax across languages (One Big Page) |url=https://rigaux.org/language-study/syntax-across-languages.html |access-date=2024-11-28 |website=rigaux.org |archive-url=https://web.archive.org/web/20240823220158/http://rigaux.org/language-study/syntax-across-languages.html |archive-date=2024-08-23}}</ref> The [[MySQL|MySQL database]] also use tilde as bitwise invert<ref>{{Cite web|url=https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_bitwise-invert|title=MySQL :: Reference Manual :: Bit Functions and Operators|website=dev.mysql.com|access-date=2019-12-20}}</ref> as does Microsoft's SQL Server [[Transact-SQL|Transact-SQL (T-SQL)]] language. ======~~ cast====== <!-- This section title is linked to, so if you change the section title then please place this anchor in the page text here: {{anchor|~~ cast}} --> [[JavaScript]] also uses tilde as bitwise NOT. Because bitwise operators work on integers, and numbers in JavaScript are 64 bit floating point numbers, the operator converts numbers to a 32-bit signed integer before it performing the negation.<ref>{{Cite web |title=JavaScript Bitwise Operations |url=https://www.w3schools.com/js/js_bitwise.asp |access-date=2024-11-28 |website=W3Schools |language=en-US |archive-url=https://web.archive.org/web/20241128173553/https://www.w3schools.com/js/js_bitwise.asp |archive-date=2024-11-28}}</ref> The conversion truncates the fractional part and most significant bits. This lets two tildes <code>~~x</code> to be used as a short syntax to cast to integer. However, it is not recommended as use for truncation. In contrast, it does not truncate BigInts, which are arbitrarily large integers.<ref>{{Cite web |date=2023-08-15 |title=Bitwise NOT (~) - JavaScript |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT |access-date=2024-11-28 |website=MDN |language=en-US |archive-url=https://web.archive.org/web/20241128173342/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_NOT |archive-date=2024-11-28}}</ref> =====Other uses===== In C++<ref>{{Cite web |date=2023-12-01 |title=Destructors (C++) |url=https://learn.microsoft.com/en-us/cpp/cpp/destructors-cpp?view=msvc-170 |access-date=2024-11-28 |website=Microsoft Learn |publisher=[[Microsoft]] |language=en-us |archive-url=https://web.archive.org/web/20241128170724/https://learn.microsoft.com/en-us/cpp/cpp/destructors-cpp?view=msvc-170 |archive-date=2024-11-28}}</ref> and C#,<ref>{{Cite web |date=2023-03-14 |title=Finalizers (C# Programming Guide) |url=https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/finalizers |access-date=2024-11-28 |website=Microsoft Learn |publisher=[[Microsoft]] |language=en-us |archive-url=https://web.archive.org/web/20241117135601/https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/finalizers |archive-date=2024-11-17}}</ref> the tilde is also used as the first character in a [[Class (computer science)|class]]'s [[method (computer science)|method]] name (where the rest of the name must be the same name as the class) to indicate a [[destructor (computer science)|destructor]] – a special method which is called at the end of the [[Object lifetime|object's life]]. In ASP.NET applications, tilde ('~') is used as a shortcut to the root of the application's virtual directory.<ref>{{Cite web |date=2022-06-03 |title=ASP.NET Core built-in Tag Helpers |url=https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/?view=aspnetcore-9.0 |access-date=2024-11-28 |website=Microsoft Learn |publisher=[[Microsoft]] |language=en-us |archive-url=https://web.archive.org/web/20241128180850/https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/?view=aspnetcore-9.0 |archive-date=2024-11-28}}</ref> In the [[Cascading Style Sheets|CSS]] stylesheet language, the tilde finds the element selected by the right-hand side that shares the parent with an element selected by the left-hand side.<ref>{{Cite web |date=2022-11-11 |title=Selectors Level 4 |url=https://www.w3.org/TR/selectors-4/ |archive-url=https://web.archive.org/web/20241122212236/https://www.w3.org/TR/selectors-4/ |archive-date=2024-11-22 |access-date=2024-11-28 |publisher=CSS Working Group |at=[https://www.w3.org/TR/selectors-4/#general-sibling-combinators 15.4. Subsequent-sibling combinator (~)] |type=W3C Working Draft}}</ref> In the [[D programming language]], the tilde is used as bitwise not operator, [[concatenation]] operator such as those of [[Array data structure|arrays]],<ref>{{Cite web |title=Expressions |url=https://dlang.org/spec/expression.html |archive-url=https://web.archive.org/web/20241128204134/https://dlang.org/spec/expression.html |archive-date=2024-11-28 |access-date=2024-11-28 |website=dlang.org}}</ref> and to indicate an object destructor.<ref>{{Cite web |title=Structs, Unions |url=https://dlang.org/spec/struct.html |archive-url=https://web.archive.org/web/20241128210801/https://dlang.org/spec/struct.html |archive-date=2024-11-28 |access-date=2024-11-28 |website=dlang.org}}</ref><ref>{{Cite web |title=Classes |url=https://dlang.org/spec/class.html |archive-url=https://web.archive.org/web/20241128210843/https://dlang.org/spec/class.html |archive-date=2024-11-28 |access-date=2024-11-28 |website=dlang.org}}</ref> Tilde operator can be overloaded for user types,<ref>{{Cite web |title=Operator Overloading |url=https://dlang.org/spec/operatoroverloading.html |archive-url=https://web.archive.org/web/20241128204128/https://dlang.org/spec/operatoroverloading.html |archive-date=2024-11-28 |access-date=2024-11-28 |website=dlang.org}}</ref> and binary tilde operator is mostly used to merging two objects, or adding some objects to set of objects. It was introduced because plus operator can have different meaning in many situations. For example, "120" + "14" may produce "134" (addition of two numbers), "12014" (concatenation of strings), or something else.<ref>{{Cite web |title=Arrays |url=https://dlang.org/spec/arrays.html |archive-url=https://web.archive.org/web/20241128204600/https://dlang.org/spec/arrays.html |archive-date=2024-11-28 |access-date=2024-11-28 |website=dlang.org}}</ref> D disallows + operator for arrays (and strings), and provides separate operator for concatenation (similarly [[PHP]] programming language solved this problem by using dot operator for concatenation, and + for number addition, which will also work on strings containing numbers). In [[Eiffel (programming language)|Eiffel]], the tilde is used for object comparison. If ''a'' and ''b'' denote objects, the Boolean expression ''a'' ~ ''b'' has value true if and only if these objects are equal, as defined by the applicable version of the library routine ''is_equal'', which by default denotes field-by-field object equality but can be redefined in any class to support a specific notion of equality.<ref>{{Cite web |date=June 2006 |title=Eiffel: Analysis, Design and Programming Language |url=https://www.ecma-international.org/wp-content/uploads/ECMA-367_2nd_edition_june_2006.pdf |archive-url=https://web.archive.org/web/20241128214008/https://www.ecma-international.org/wp-content/uploads/ECMA-367_2nd_edition_june_2006.pdf |archive-date=2024-11-28 |access-date=2024-11-28 |publisher=ECMA International |id=ECMA-367 |edition=2nd}}</ref>{{rp|114-115}} If ''a'' and ''b'' are references, the object equality expression ''a'' ~ ''b'' is to be contrasted with ''a'' = ''b'' which denotes reference equality. Unlike the call ''a''.''is_equal'' (''b''), the expression ''a'' ~ ''b'' is [[type safety|type-safe]] even in the presence of [[Covariance and contravariance (computer science)|covariance]].<!--{{Citation needed|date=November 2024}}--> In the [[Groovy (programming language)|Apache Groovy programming language]] the tilde character overloaded as a bitwise binary negation operation, and as the "pattern operator" that creates a [[regular expression]] pattern object. <code>=~</code> and <code>==~</code> can in Groovy be used to match a regular expression.<ref>{{cite web|url=https://groovy-lang.org/operators.html|title=The Groovy programming language – Operators}}</ref> In [[Haskell (programming language)|Haskell]], the tilde is used in type constraints to indicate type equality.<ref>{{Citation | url = http://www.haskell.org/haskellwiki/GHC/Type_families#Equality_constraints | title = Haskell Wiki | contribution = Type Families}}.</ref> Also, in pattern-matching, the tilde is used to indicate a lazy pattern match.<ref>{{cite web|url=http://www.haskell.org/haskellwiki/Lazy_pattern_match|title=Lazy pattern match}}</ref> In the [[Inform]] 6 programming language, the tilde is used to indicate a quotation mark inside a quoted string. Tilde itself is created by <code>@@126</code>. <ref>{{Cite book |last=Nelson |first=Graham |date=July 2001 |contribution=§1 Routines |contribution-url=https://www.inform-fiction.org/manual/html/s1.html |archive-url=https://web.archive.org/web/20240607185340/https://www.inform-fiction.org/manual/html/s1.html |archive-date=2024-06-07 |access-date=2024-11-28 |title=The Inform Designer's Manual |publisher=Interactive Fiction Library |isbn=0-9713119-0-0 |edition=4th}}</ref> In "text mode" of the [[LaTeX]] typesetting language a tilde diacritic can be obtained using, e.g., <code>\~{n}</code>, yielding "ñ". A stand-alone tilde can be obtained by using <code>\textasciitilde</code> or <code>\string~</code>. In "math mode" a tilde diacritic can be written as, e.g., <code>\tilde{x}</code>. For a wider tilde <code>\widetilde</code> can be used. The <code>\sim</code> command produce a tilde-like binary relation symbol that is often used in mathematical expressions, and the double-tilde [[≈]] is obtained with <code>\approx</code>.In both text and math mode, a tilde on its own (<code>~</code>) renders a white space with no line breaking.In both text and math mode, a tilde on its own (<code>~</code>) renders a white space with no line breaking.<ref>{{cite web |last=Doob| first=Michael|date=Jan 21, 2002 |title=A Gentle Introduction to TeX |url=https://texdoc.org/serve/gentle.pdf/0 |website=texdoc.org | page=11,12,15,32,36,37|location=Winnipeg, Manitoba |access-date=Apr 6, 2025}}</ref> The <code>url</code> package also supports entering tildes directly, e.g., <code><nowiki>\url{http://server/~name}</nowiki></code>.{{Citation needed|date=April 2025}} . In [[MediaWiki]] syntax, four tildes are a shortcut for a user's signature. Three and five tildes puts the signature without timestamp and only the timestamp, respectively.<ref>{{Cite web |title=Help:Signatures |url=https://www.mediawiki.org/w/index.php?title=Help:Signatures&oldid=6657175 |date=20 July 2024 |access-date=2024-11-28 |website=MediaWiki |language=en |archive-url=https://web.archive.org/web/20241128225211/https://www.mediawiki.org/w/index.php?title=Help:Signatures&oldid=6657175 |archive-date=2024-11-28}}</ref> In [[Common Lisp]], the tilde is used as the prefix for format specifiers in format strings.<ref>{{cite web|url=http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm |title=CLHS: Section 22.3 |publisher=Lispworks.com |date=2005-04-11 |access-date=2010-07-30}}</ref> In [[Max/MSP]], MSP objects have names ending with a tilde. MSP objects process at the computer's sampling rate and mainly deal with sound.<ref>{{Cite web |author="Cycling '74" |title=MSP Basics Tutorial 1: Test Tone |url=https://docs.cycling74.com/learn/articles/05_mspbasicchapter01/ |archive-url=https://web.archive.org/web/20241206215808/https://docs.cycling74.com/learn/articles/05_mspbasicchapter01/ |archive-date=2024-12-06 |access-date=2024-12-06 |website=Cycling '74 Documentation |language=en}}</ref> In [[Standard ML]], the tilde is used as the prefix for negative numbers and as the unary negation operator.<ref>{{Cite web |last=Fisher |first=Kathleen |title=Learning Standard ML |url=https://www.cs.tufts.edu/comp/105-2017f/readings/ml.html |access-date=2024-12-06 |website=www.cs.tufts.edu |at=[https://www.cs.tufts.edu/comp/105-2017f/readings/ml.html#expressions-ii-minus-signs Expressions II: Minus signs]}}</ref> In [[OCaml]], the tilde is used to specify the label for a labeled parameter.<ref>{{Cite web |title=Labelled and Optional Arguments |url=https://ocaml.org/docs/labels |archive-url=https://web.archive.org/web/20241206214050/https://ocaml.org/docs/labels |archive-date=2024-12-06 |access-date=2024-12-06 |website=OCaml |language=en}}</ref> In [[R (programming language)|R]], the tilde operator is used to separate the left- and right-hand sides in a model formula.<ref>[https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf The R Reference Index ]</ref> In [[Object REXX]], the twiddle is used as a "message send" symbol. For example, <code>Employee.name~lower()</code> would cause the <code>lower()</code> method to act on the object <code>Employee</code>'s <code>name</code> attribute, returning the result of the operation. <code>~~</code> returns the object that received the method rather than the result produced. Thus, it can be used when the result need not be returned or when cascading methods are to be used. <code>team~~insert("Jane")~~insert("Joe")~~insert("Steve")</code> would send multiple concurrent <code>insert</code> messages, thus invoking the <code>insert</code> method three consecutive times on the <code>team</code> object.<ref>{{Cite web |last1=Ashley |first1=W. David |last2=Flatscher |first2=Rony G. |last3=Hessling |first3=Mark |last4=McGuire |first4=Rick |last5=Miesfeld |first5=Mark |last6=Peedin |first6=Lee |last7=Tammer |first7=Rainer |last8=Wolfers |first8=Jon |date=August 14, 2009 |title=Terms, Expressions, and Operators |url=https://www.oorexx.org/docs/rexxref/x974.htm |url-status=dead |archive-url=https://web.archive.org/web/20210116122945/https://www.oorexx.org/docs/rexxref/x974.htm |archive-date=2021-01-16 |access-date=2024-12-06 |website=Open Object Rexx™: Reference |series=Version 4.0.0 Edition}}</ref> In [[Raku (programming language)|Raku]], a prefixing tilde [[type conversion|converts]] a value to a string. An infix tilde [[concatenate]]s strings,<ref name="rakudocs-operators">{{Cite web |date=2024-09-13 |title=Operators |url=https://docs.raku.org/language/operators |archive-url=https://web.archive.org/web/20241130145259/https://docs.raku.org/language/operators |archive-date=2024-11-30 |access-date=2024-12-06 |website=Raku documentation}}</ref> taking place of the dot operator in Perl, as the dot is used for member access instead of {{code|->}}.<ref name="rakudocs-perl">{{Cite web |date=2024-08-01 |title=Perl to Raku guide - in a nutshell |url=https://docs.raku.org/language/operators |archive-url=https://web.archive.org/web/20241203160657/https://docs.raku.org/language/5to6-nutshell |archive-date=2024-12-03 |access-date=2024-12-06 |website=Raku documentation}}</ref> {{code|~~}} is called "the smartmatch operator" and its semantics depend on the type of the right-side argument. Namely, it checks numeric and string equalities, performs [[regular expression]] match tests (as opposed to {{code|{{=}}~}} in Perl<ref name="rakudocs-perl" />), and [[type checking]].<ref name="rakudocs-operators" /> <syntaxhighlight lang="raku"> my $concatResult = "Hello " ~ "world!"; $concatResult ~~ /<|w><[A..Z]><[a..z]>*<|w>/; say $/; # outputs "Hello" # the $/ variable holds the last regex match result </syntaxhighlight> In [[YAML]], the "Core schema," a set of aliases that processors are recommended to use, resolves a tilde as null.<ref>{{Cite web |date=2021-10-01 |title=YAML Ain't Markup Language (YAML™) revision 1.2.2 |url=https://yaml.org/spec/1.2.2/ |archive-url=https://web.archive.org/web/20241124004709/https://yaml.org/spec/1.2.2/ |archive-date=2024-11-24 |access-date=2024-11-28 |at=10.3.2. Tag Resolution}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)