Sigil (computer programming)

Sigil (computer programming)

In computer programming, a sigil (pronounced /'sɪdʒ.ɪl/ or /'sɪg.ɪl/; plural "sigilia" or "sigils") is a symbol attached to a variable name, showing the variable's datatype or scope. The term was first applied to Perl usage by Philip Gwyn in 1999 to replace the more cumbersome "funny character in front of a variable name". The name is based on the word meaning a magical symbol (see "sigil (magic)").

Historical context

The use of sigils was popularized by the BASIC programming language. The best known example of a sigil in BASIC is the dollar sign (“$”) appended to the names of all strings. Many BASIC dialects use other sigils to denote integers and floating point numbers, and sometimes other types as well.

Larry Wall adopted shell scripting’s use of sigils for his scripting language Perl. However, as Perl is a dynamically typed language, the sigils specify not fine-grained data types like strings and integers, but general categories such as scalars (using a prefixed “$”), arrays (using a “@”), hashes (using a “%”), and subroutines (using a “&”). Perl 6 introduces secondary sigils, or twigils, which are used to indicate the scope of variables. Prominent examples of twigils in Perl 6 include “^”, used with self-declared formal parameters (“placeholder variables”), and “.”, used with object attribute accessors (i.e., instance variables).

Language comparison

In Unix shell scripting and other utilities such as Makefiles, the "$" is a unary operator that translates the name of a variable into its contents. Many people confuse this with a sigil, but it is properly a unary operator for lexical indirection, similar to the * indirection operator for pointers in C.

In the PHP language, which was partly inspired by Perl, “$” precedes any variable name. Names not prefixed by this are considered constants.

In the MUMPS programming language, global variables and routines (procedures or subroutines) are prefixed by an uparrow (^), and the last identifier used can be referenced indirectly by an uparrow alone, this is referred to as the "naked" identifier.

In Ruby, ordinary variables lack sigils, but “$” is prefixed to global variables, “@” is prefixed to instance variables, and “@@” is prefixed to class variables (the second “@” cannot be considered a twigil, so “@@” is just a longer sigil).

In Windows PowerShell, which was partly inspired by Unix shells and Perl, variable names are prefixed by the $ sigil.

In Transact-SQL, “@” precedes a local variable or parameter name. System variables (known as global variables) are distinguished by a “@@” prefix.

In mIRC script, identifiers have a $ sigil, while all variables have a % prefixed (regardless of local or global variables or data type). Binary variables are prefixed by a &.

In XSLT, variables and parameters have a leading $ sigil on use, although when defined in or with the “name” attribute, the sigil is not included. Related to XSLT, XQuery uses the $ sigil form both in definition and in use.

In Fortran, sigils are not used, but all variables starting with the letters I, J, K, L, M and N are integers by default. Fortran refers to this as "implicit typing".

In CLIPS, scalar variables are prefixed with a ? sigil while multifield (i.e. a 1-level list) variables are prefixed with $?.

In C#, any variable names may be prefixed with @. This is mainly used to allow the use of variable names that would otherwise conflict with keywords.The @ sigil can also be applied to string literals, which changes the way they are interpreted (character escapes are not used and strings can extend over multiple lines).

Hungarian notation

Related to sigils is Hungarian notation, a convention for variable-naming that specifies variable type by attaching certain alphabetic prefixes to the variable name. Unlike sigils, however, Hungarian notation provides no information to the compiler; as such, explicit types must be redundantly given for the variables and the prefixes are not enforced, making them more prone to omission and misuse.

ee also

*Identifier
*Source code
*Token
*Tokenizing


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Sigil — may refer to:*Sigil (magic), a type of symbol used in magic *Sigil (computer programming), a symbol that must be attached to a variable name in some programming languages. *A seal (device) or signet ring *Sigla, a symbol used to identify… …   Wikipedia

  • Comparison of programming languages (mapping) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • C (programming language) — C The C Programming Language[1] (aka K R ) is the seminal book on C …   Wikipedia

  • Dollar sign — $ redirects here. For the unit of currency, see Dollar or Peso. For other uses, see $ (disambiguation). $ Dollar sign …   Wikipedia

  • $ (disambiguation) — $ is the dollar or peso currency sign, primarily used to represent currencies. $ may also refer to: Contents 1 Currency 2 Mathematics and Computers …   Wikipedia

  • Variable — A variable (pronEng|ˈvɛərɪəbl) is an attribute of a physical or an abstract system which may change its value while it is under observation. Examples include the height of a child, the temperature across a state, or the input to a function. This… …   Wikipedia

  • Ampersand — This article is about the symbol. For the magazine, see Ampersand (magazine). Ampersand Punctuation …   Wikipedia

  • Common Lisp — Paradigm(s) Multi paradigm: procedural, functional, object oriented, meta, reflective, generic Appeared in 1984, 1994 for ANSI Common Lisp Developer ANSI X3J13 committee Typing discipline …   Wikipedia

  • Perl 6 — Infobox programming language name = Perl paradigm = Multi paradigm year = 2000 designer = Larry Wall latest release version = pre release latest release date = typing = dynamic, static influenced by = Perl 5, Haskell, Smalltalk influenced =… …   Wikipedia

  • PERL — Paradigmen: prozedural, modular, teilweise objektorientiert Erscheinungsjahr: 1987 Entwickler: Larry Wall, Perl Porter Aktuelle  …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”