Sigil (computer programming)

From Wikipedia for FEVERv2
Jump to navigation Jump to search

In computer programming, a sigil (/ˈsɪdʒəl/) is a symbol affixed to a variable name, showing the variable's datatype or scope, usually a prefix, as in $foo, where $ is the sigil. Sigil (computer programming)_sentence_0

, from the Latin , meaning a "little sign", means a sign or image supposedly having magical power. Sigil (computer programming)_sentence_1

In 1999 Philip Gwyn adopted the term "to mean the funny character at the front of a Perl variable." Sigil (computer programming)_sentence_2

Historical context Sigil (computer programming)_section_0

The use of sigils was popularized by the BASIC programming language. Sigil (computer programming)_sentence_3

The best known example of a sigil in BASIC is the dollar sign ("$") appended to the names of all strings. Sigil (computer programming)_sentence_4

Many BASIC dialects use other sigils (like "%") to denote integers and floating point numbers and their precision, and sometimes other types as well. Sigil (computer programming)_sentence_5

Larry Wall adopted shell scripting's use of sigils for his Perl programming language. Sigil (computer programming)_sentence_6

In Perl, the sigils do not specify fine-grained data-types like strings and integers, but the more general categories of scalars (using a prefixed "$"), arrays (using "@"), hashes (using "%"), and subroutines (using "&"). Sigil (computer programming)_sentence_7

Raku also uses secondary sigils, or twigils, to indicate the scope of variables. Sigil (computer programming)_sentence_8

Prominent examples of twigils in Raku include "^", used with self-declared formal parameters ("placeholder variables"), and ". Sigil (computer programming)_sentence_9

", used with object attribute accessors (i.e., instance variables). Sigil (computer programming)_sentence_10

In CLIPS, scalar variables are prefixed with a "?" Sigil (computer programming)_sentence_11

sigil while multifield (e.g., a 1-level list) variables are prefixed with "$? Sigil (computer programming)_sentence_12

". Sigil (computer programming)_sentence_13

In Common Lisp, special variables (with dynamic scope) are typically surrounded with * in what is dubbed the "earmuff convention". Sigil (computer programming)_sentence_14

While this is only convention, and not enforced, the language itself adopts the practice (e.g., *standard-output*). Sigil (computer programming)_sentence_15

Similarly, some programmers surround constants with +. Sigil (computer programming)_sentence_16

In CycL, variables are prefixed with a "?" Sigil (computer programming)_sentence_17

sigil. Sigil (computer programming)_sentence_18

Similarly, constant names are prefixed with "#$" (pronounced "hash-dollar"). Sigil (computer programming)_sentence_19

In Elixir, string sigils are provided via the "~" symbol. Sigil (computer programming)_sentence_20

In MAPPER (aka BIS), named variables are prefixed with "<" and suffixed with ">" because strings or character values do not require quotes. Sigil (computer programming)_sentence_21

In mIRC script, identifiers have a "$" sigil, while all variables have a "%" prefixed (regardless of local or global variables or data type). Sigil (computer programming)_sentence_22

Binary variables are prefixed by an "&". Sigil (computer programming)_sentence_23

In the MUMPS programming language, "$" precedes intrinsic function names and 'special variable names' (built-in variables for accessing the execution state). Sigil (computer programming)_sentence_24

"$Z" precedes non-standard intrinsic function names. Sigil (computer programming)_sentence_25

"$$" precedes extrinsic function names. Sigil (computer programming)_sentence_26

Routines (used for procedures, subroutines, functions) and global variables (database storage) are prefixed by a caret (^). Sigil (computer programming)_sentence_27

The last global variable subtree may be referenced indirectly by a caret and the last subscript; this is referred to as a "naked reference". Sigil (computer programming)_sentence_28

System-wide routines and global variables (stored in certain shared database(s)) are prefixed with ^%; these are referred to as "percent routines" and "percent globals". Sigil (computer programming)_sentence_29

In Objective-C, string literals preceded with "@" are instances of the object type NSString or, since clang v3.1 / LLVM v4.0, NSNumber, NSArray or NSDictionary. Sigil (computer programming)_sentence_30

The prefix-@ is also used on the keywords interface, implementation, and end to express the structure of class definitions. Sigil (computer programming)_sentence_31

Within class declarations and definitions as well, a prefix of - is used to indicate member methods and variables, while prefix + indicates class elements. Sigil (computer programming)_sentence_32

In the PHP language, which was largely inspired by Perl, "$" precedes any variable name. Sigil (computer programming)_sentence_33

Names not prefixed by this are considered constants, functions or class names (or interface or trait names, which share the same namespace as classes). Sigil (computer programming)_sentence_34

PILOT uses "$" for buffers (string variables), "#" for integer variables, and "*" for program labels. Sigil (computer programming)_sentence_35

Python uses a "@" prefix to denote a decorator. Sigil (computer programming)_sentence_36

In Ruby, ordinary variables lack sigils, but "$" is prefixed to global variables, "@" is prefixed to instance variables, and "@@" is prefixed to class variables. Sigil (computer programming)_sentence_37

Ruby also uses (strictly conventional) suffix sigils: "?" Sigil (computer programming)_sentence_38

indicates a predicate method returning (usually) a boolean value; and "!" Sigil (computer programming)_sentence_39

indicates that the method may have a potentially unexpected effect, and needs to be handled with care. Sigil (computer programming)_sentence_40

In Scheme, by convention, the names of procedures that always return a boolean value usually end in "?". Sigil (computer programming)_sentence_41

Likewise, the names of procedures that store values into parts of previously allocated Scheme objects (such as pairs, vectors, or strings) usually end in "! Sigil (computer programming)_sentence_42

". Sigil (computer programming)_sentence_43

Standard ML uses the prefix sigil "'" on a variable that refers to a type. Sigil (computer programming)_sentence_44

If the sigil is doubled, it refers to a type for which equality is defined. Sigil (computer programming)_sentence_45

The "'" character may also appear within or at the end of a variable, in which case it has no special meaning. Sigil (computer programming)_sentence_46

In Transact-SQL, "@" precedes a local variable or parameter name. Sigil (computer programming)_sentence_47

System variables (known as global variables) are distinguished by a "@@" prefix. Sigil (computer programming)_sentence_48

In Windows PowerShell, which was partly inspired by Unix shells and Perl, variable names are prefixed by the "$" sigil. Sigil (computer programming)_sentence_49

In XSLT, variables and parameters have a leading "$" sigil on use, although when defined in <xsl:param> or <xsl:variable> with the "name" attribute, the sigil is not included. Sigil (computer programming)_sentence_50

Related to XSLT, XQuery uses the "$" sigil form both in definition and in use. Sigil (computer programming)_sentence_51

In MEL, variable names are prefixed by "$" to distinguish them from functions, commands, and other identifiers. Sigil (computer programming)_sentence_52

Similar phenomena Sigil (computer programming)_section_1

Shell scripting variables Sigil (computer programming)_section_2

In Unix shell scripting and in utilities such as , the "$" is a unary operator that translates the name of a variable into its contents. Sigil (computer programming)_sentence_53

While this may seem similar to a sigil, it is properly a unary operator for lexical indirection, similar to the * dereference operator for pointers in C, as noticeable from the fact that the dollar sign is omitted when assigning to a variable. Sigil (computer programming)_sentence_54

Identifier conventions Sigil (computer programming)_section_3

In Fortran, sigils are not used, but all variables starting with the letters I, J, K, L, M and N are integers by default. Sigil (computer programming)_sentence_55

Fortran documentation refers to this as "implicit typing", though explicit typing is always available to allow any variable to be declared with any type. Sigil (computer programming)_sentence_56

(The choice of range I–N conforms to traditional mathematical naming conventions.) Sigil (computer programming)_sentence_57

Various programming languages including Prolog, Haskell, Ruby and Go treat identifiers beginning with a capital letter differently from identifiers beginning with a small letter, a practice related to the use of sigils. Sigil (computer programming)_sentence_58

Stropping Sigil (computer programming)_section_4

Main article: Stropping (syntax) Sigil (computer programming)_sentence_59

Actually a form of stropping, the use of many languages in Microsoft's .NET Common Language Infrastructure (CLI) requires a way to use variables in a different language that may be keywords in a calling language. Sigil (computer programming)_sentence_60

This is sometimes done by prefixes. Sigil (computer programming)_sentence_61

In C#, any variable names may be prefixed with "@". Sigil (computer programming)_sentence_62

This is mainly used to allow the use of variable names that would otherwise conflict with keywords. Sigil (computer programming)_sentence_63

The same is achieved in VB.Net by enclosing the name in square brackets, as in [end]. Sigil (computer programming)_sentence_64

The "@" prefix can also be applied to string literals; see literal affixes below. Sigil (computer programming)_sentence_65

Hungarian notation Sigil (computer programming)_section_5

Related to sigils is Hungarian notation, a naming convention for variables that specifies variable type by attaching certain alphabetic prefixes to the variable name. Sigil (computer programming)_sentence_66

Unlike sigils, however, Hungarian notation provides no information to the compiler; as such, explicit types must be redundantly specified for the variables (unless using a language with type inference). Sigil (computer programming)_sentence_67

As most standard compilers do not enforce use of the prefixes, this permits omission and also makes code prone to confusion due to accidental erroneous use. Sigil (computer programming)_sentence_68

Literal affixes Sigil (computer programming)_section_6

While sigils are applied to names (identifiers), similar prefixes and suffixes can be applied to literals, notably integer literals and string literals, specifying either how the literal should be evaluated, or what data type it is. Sigil (computer programming)_sentence_69

For example, 0x10ULL evaluates to the value 16 as an unsigned long long integer in C++: the 0x prefix indicates hexadecimal, while the suffix ULL indicates unsigned long long. Sigil (computer programming)_sentence_70

Similarly, prefixes are often used to indicate a raw string, such as r"C:\Windows" in Python, which represents the string with value C:\Windows; as an escaped string this would be written as "C:\\Windows". Sigil (computer programming)_sentence_71

As this affects the semantics (value) of a literal, rather than the syntax or semantics of an identifier (name), this is neither stropping (identifier syntax) nor a sigil (identifier semantics), but it is syntactically similar. Sigil (computer programming)_sentence_72

Java annotations Sigil (computer programming)_section_7

Compare Java annotations such as @Override and @Deprecated. Sigil (computer programming)_sentence_73

Confusion Sigil (computer programming)_section_8

In some cases the same syntax can be used for distinct purposes, which can cause confusion. Sigil (computer programming)_sentence_74

For example, in C#, the "@" prefix can be used either for stropping (to allow reserved words to be used as identifiers), or as a prefix to a literal (to indicate a raw string); in this case neither use is a sigil, as it affects the syntax of identifiers or the semantics of literals, not the semantics of identifiers. Sigil (computer programming)_sentence_75

See also Sigil (computer programming)_section_9

Sigil (computer programming)_unordered_list_0

  • DelimiterSigil (computer programming)_item_0_0
  • Source codeSigil (computer programming)_item_0_1
  • TokenSigil (computer programming)_item_0_2

Credits to the contents of this page go to the authors of the corresponding Wikipedia page: (computer programming).