Backslash

Revision as of 14:59, 26 April 2025 by imported>TheM1sty (Reverted edits by 2600:1700:F91:83F0:94BD:E7D:E912:8A94 (talk) to last version by JMF)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:Distinguish Template:Technical reasons Template:Infobox symbol

The backslash Template:Char is a mark used mainly in computing and mathematics. It is the mirror image of the common slash Template:Char. It is a relatively recent mark, first documented in the 1930s. It is sometimes called a hack, whack, escape (from C/UNIX), reverse slash, slosh, downwhack, backslant, backwhack, bash, reverse slant, reverse solidus, and reversed virgule.<ref>Macquarie Dictionary (3rd edition)</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

HistoryEdit

File:Teletype Wheatstone Perforator keyboard.jpg
A Teletype Wheatstone Perforator keyboard from the 1930s, with backslash in the end of the third row
File:Mappa Teletype ASR-33.jpg
Teletype ASR-33 keyboard layout with ASCII character set, prior to June 14, 1966, with backslash on shift+L

Template:As of, efforts to identify either the origin of this character or its purpose before the 1960s have not been successful. The earliest known reference found to date is a 1937 maintenance manual from the Teletype Corporation with a photograph showing the keyboard of its Kleinschmidt keyboard perforator WPE-3 using the Wheatstone system.<ref>Template:Citation</ref><ref name=Fischer /> The symbol was called the "diagonal key",<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and given a (non-standard) Morse code of Template:Morse.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>Template:Efn

In June 1960, IBM published an "Extended character set standard" that includes the symbol at 0x19.<ref name=Fischer>{{#invoke:citation/CS1|citation |CitationClass=web }} Referencing Template:Cite tech report Computer Standards Collection, Archives Center, National Museum of American History, Smithsonian Institution, box 1.</ref> In September 1961, Bob Bemer (IBM) proposed to the X3.2 standards committee that <syntaxhighlight lang="text" class="" style="" inline="1">[</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">]</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">\</syntaxhighlight> be made part of the proposed standard, describing the backslash as a "reverse division operator" and cited its prior use by Teletype in telecommunications. In particular, he said, the Template:Mono was needed so that the ALGOL Boolean operators <syntaxhighlight lang="text" class="" style="" inline="1">∧</syntaxhighlight> (logical conjunction) and <syntaxhighlight lang="text" class="" style="" inline="1">∨</syntaxhighlight> (logical disjunction) could be composed using Template:Mono and Template:Mono respectively. The Committee adopted these changes into the draft American Standard (subsequently called ASCII) at its November 1961 meeting.<ref name=Fischer />

These operators were used for min and max in early versions of the C programming language supplied with Unix V6<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> and V7.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

UsageEdit

Programming languagesEdit

In many programming languages such as C, Perl, PHP, Python and Unix scripting languages, and in many file formats such as JSON, the backslash is used as an escape character, to indicate that the character following it should be treated specially (if it would otherwise be treated literally), or literally (if it would otherwise be treated specially). For instance, inside a C string literal the sequence <syntaxhighlight lang="text" class="" style="" inline="1">\n</syntaxhighlight> produces a newline byte instead of an 'n', and the sequence <syntaxhighlight lang="text" class="" style="" inline="1">\"</syntaxhighlight> produces an actual double quote rather than the special meaning of the double quote ending the string. An actual backslash is produced by a double backslash <syntaxhighlight lang="text" class="" style="" inline="1">\\</syntaxhighlight>.

Regular expression languages used it the same way, changing subsequent literal characters into metacharacters and vice versa. For instance Template:Mono searches for either '|' or 'b', the first bar is escaped and searched for, the second is not escaped and acts as an "or".

Template:AnchorOutside quoted strings, the only common use of backslash is to ignore ("escape") a newline immediately after it. In this context it may be called a "continued line"<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> as the current line continues into the next one. Some software replaces the backslash+newline with a space.<ref>Template:Cite book</ref>

To support computers that lacked the backslash character, the C trigraph <syntaxhighlight lang="text" class="" style="" inline="1">??/</syntaxhighlight> was added, which is equivalent to a backslash. Since this can escape the next character, which may itself be a <syntaxhighlight lang="text" class="" style="" inline="1">?</syntaxhighlight>, the primary modern use may be for code obfuscation. Support for trigraphs in C++ was removed in C++17, and support for them in C is planned to be removed in C23.

In Visual Basic (and some other BASIC dialects) the backslash is used as an operator symbol to indicate integer division.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> This rounds toward zero.

The ALGOL 68 programming language uses the "\" as its Decimal Exponent Symbol. ALGOL 68 has the choice of 4 Decimal Exponent Symbols: e, E, \, or 10. Examples: Template:Mono, Template:Mono, Template:Mono or Template:Mono.<ref>Template:Cite journal</ref>

In APL Template:Mono is called Expand when used to insert fill elements into arrays, and Scan when used to produce prefix reduction (cumulative fold).

In PHP version 5.3 and higher, the backslash is used to indicate a namespace.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

In Haskell, the backslash is used both to introduce special characters and to introduce lambda functions (since it is a reasonable approximation in ASCII of the Greek letter Template:Nowrap.<ref>O'Sullivan, Stewart, and Goerzen, Real World Haskell, ch. 4: anonymous (lambda) functions, p.99</ref>

FilenamesEdit

MS-DOS 2.0, released 1983, copied the idea of a hierarchical file system from Unix and thus used the (forward) slash as the directory separator.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Possibly on the insistence of IBM,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>Template:Citation</ref> Microsoft added the backslash to allow paths to be typed at the command line interpreter prompt, while retaining compatibility with MS-DOS 1.0 (in which Template:Char was the command-line option indicator. Typing "Template:Mono" gave the "wide" option to the "Template:Mono" command, so some other method was needed if one actually wanted to run a program called Template:Mono inside a directory called Template:Mono). Except for COMMAND.COM, all other parts of the operating system accept both characters in a path, but the Microsoft convention remains to use a backslash, and APIs that return paths use backslashes.<ref> {{#invoke:citation/CS1|citation |CitationClass=web }}</ref> In some versions, the option character can be changed from Template:Mono to Template:Mono via SWITCHAR, which allows COMMAND.COM to preserve Template:Mono in the command name.

The Microsoft Windows family of operating systems inherited the MS-DOS behavior and so still support either character – but individual Windows programs and sub-systems may, wrongly, only accept the backslash as a path delimiter, or may misinterpret a forward slash if it is used as such. Some programs will only accept forward slashes if the path is placed in double-quotes.<ref> {{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The failure of Microsoft's security features to recognize unexpected-direction slashes in local and Internet paths, while other parts of the operating system still act upon them, has led to some serious lapses in security. Resources that should not be available have been accessed with paths using particular mixes, such as Template:Mono.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Text markupEdit

The backslash is used in the TeX typesetting system and in RTF files to begin markup tags.

In USFM,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> the backslash is used to mark format features for editing Bible translations.

In caret notation, <syntaxhighlight lang="text" class="" style="" inline="1">^\</syntaxhighlight> represents the control character 0x1C, file separator.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> This is entirely a coincidence and has nothing to do with its use in file paths.

MathematicsEdit

A backslash-like symbol is used for the set difference.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

The backslash is also sometimes used to denote the right coset space.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Especially when describing computer algorithms, it is common to define backslash so that Template:Math is equivalent to Template:Math.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> This is integer division that rounds down, not towards zero.

In MATLAB and GNU Octave the backslash is used for left matrix divide, while the (forward) slash is for right matrix divide.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Confusion with ¥ and other charactersEdit

In the Japanese encodings ISO 646-JP (a 7-bit code based on ASCII), JIS X 0201 (an 8-bit code), and Shift JIS (a multi-byte encoding which is 8-bit for ASCII), the code point 0x5C that would be used for backslash in ASCII is instead rendered as a yen sign Template:Char. Due to extensive use of the 005C code point to represent the yen sign, even today some fonts such as MS Mincho render the backslash character as a ¥, so the characters at Unicode code points Template:Unichar and Template:Unichar both render as Template:Char when these character sets are selected. Computer programs still treat 005C as a backslash in these environments but display it as a yen sign, causing confusion, especially in MS-DOS filenames.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Several other ISO 646 versions also replace backslash with other characters, including (Korean), Ö (German, Swedish), Ø (Danish, Norwegian), ç (French) and Ñ (Spanish), leading to similar problems, though with less lasting impact compared to the yen sign. Although the conflict is resolved by unique code point allocations in Unicode, the longevity of legacy systems means that (although diminishing) the issue continues to persist.

In 1991, RFC 1345 suggested <syntaxhighlight lang="text" class="" style="" inline="1">//</syntaxhighlight> as a unique two-character mnemonic that might be used in internet standards as "a practical way of identifying [this] character, without reference to a coded character set and its code in [that] coded character set".<ref name="RFC1345">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Consequently, this style may be seen in early Internet Engineering Task Force documents.

UnicodeEdit

Unicode has codepoints for a variety of backslash symbols:


NotesEdit

Template:Notelist

ReferencesEdit

Template:Reflist

External linksEdit

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

Template:Navbox punctuation

pl:Ukośnik