Special characters

From Rosetta Code
Revision as of 23:43, 22 August 2008 by rosettacode>Mwn3d (Moved to Basic learning cat)
Task
Special characters
You are encouraged to solve this task according to the task description, using any language you may know.

List the special characters and escape sequences in the language.

Brainf***

The only characters that mean anything in BF are its commands:

> move the pointer one to the right

< move the pointer one to the left

+ increment the value at the pointer

- decrement the value at the pointer

, input one byte to memory at the pointer

. output one byte from memory at the pointer

[ begin loop if the value at the pointer is not 0

] end loop

All other characters are comments.

Haskell

Comments

-- comment here until end of line
{- comment here -}

Operator symbols (nearly any sequence can be used)

! # $ % & * + - . / < = > ? @ \ ^ | - ~ :
: as first character denotes constructor

Reserved symbol sequences

.. : :: = \ | <- -> @ ~ => _ 

Infix quotes

`identifier` (to use as infix operator)

Characters

'.'
\ escapes

Strings

"..."
\ escapes

Special escapes

\a alert
\b backspace
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab

Other

( )   (grouping)
( , ) (tuple type/tuple constructor)
{ ; } (grouping inside let, where, do, case without layout)
[ , ] (list type/list constructor)
[ | ] (list comprehension)

Unicode characters, according to category:

Upper case (identifiers)
Lower case (identifiers)
Digits (numbers)
Symbol/punctuation (operators)

Java

Math:

& | ^ ~ (bitwise AND, OR, XOR, and NOT)
>> << (bitwise arithmetic shift)
>>> (bitwise logical shift)
+ - * / = % (+ can be used for String concatenation)
any of the previous math operators can be placed in front of an equals sign to make a self-operation replacement:
x = x + 2 is the same as x += 2
++ -- (increment and decrement--before a variable for pre (++x), after for post(x++))

Boolean:

! ~ (both NOT)
^ && || (XOR, AND, OR)
== < > != <= >= (comparison)

Other:

{ } (scope)
( ) (for functions)
; (line delimiter)
[ ] (array index)
" (string literal)
' (character literal)
? : (ternary operator)

Escape characters:

 \b     (Backspace)
 \n     (Line Feed)
 \r     (Carriage Return)
 \f     (Form Feed)
 \t     (Tab)
 \0     (Null) Note. This is actually a OCTAL escape but handy nonetheless
 \'     (Single Quote)
 \"     (Double Quote)
 \\     (Backslash)
 \DDD   (Octal Escape Sequence, D is a number between 0 and 7)
 \uDDDD (Unicode Escape Sequence, D is any digit between 0 and 9)

LaTeX

LaTeX has ten special characters: # $ % & ~ _ ^ \ { }

To make any of these characters appear literally in output, prefix the character with a \. For example, to typeset 5% of $10 you would type

5\% of \$10

Note that the set of special characters in LaTeX isn't really fixed, but can be changed by LaTeX code. For example, the package ngerman (providing German-specific definitions, including easier access to umlaut letters) re-defines the double quote character (") as special character, so you can more easily write German words like "hören" (as h"oren instead of h{\"o}ren).

PowerShell

PowerShell is unusual in that it retains many of the escape sequences of languages descended from C, except that unlike these languages it uses a backtick ` as the escape character rather than a backslash \. For example `n is a new line and `t is a tab.