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
Sigil (computer programming)
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!
{{Other uses|Sigil (disambiguation)}} {{short description|Symbol affixed to a variable name}} In [[computer programming]], a '''sigil''' ({{IPAc-en|Λ|s|Ιͺ|dΚ|Ιl}}) is a symbol affixed to a [[variable (programming)|variable]] name, showing the variable's [[datatype]] or [[Scope (programming)|scope]], usually a prefix, as in <code>$foo</code>, where <code>$</code> is the sigil. ''[[wikt:sigil|Sigil]]'', from the [[Latin]] ''[[wikt:sigillum|sigillum]]'', meaning a "little sign", means ''a sign or image supposedly having magical power''.<ref>{{cite web|title=Definition of sigil|url=http://www.collinsdictionary.com/dictionary/english/sigil|work=[[Collins English Dictionary]]|access-date=22 May 2012}}</ref> Sigils can be used to separate and demarcate [[namespace]]s that possess different properties or behaviors. == 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]] ("<code>$</code>") appended to the names of all [[string (computer science)|string]]s. Many BASIC dialects use other sigils (like "<code>%</code>") to denote [[integer]]s and [[floating-point number]]s and their precision, and sometimes other types as well. [[Larry Wall]] adopted [[shell script]]ing's use of sigils for his [[Perl]] programming language.{{citation needed|date=April 2018}} In Perl, the sigils do not specify fine-grained data types like strings and integers, but the more general categories of [[scalar (computing)|scalars]] (using a prefixed "<code>$</code>"), arrays (using "<code>@</code>"), [[hash table|hashes]] (using "<code>%</code>"), and [[subroutine]]s (using "<code>&</code>"). [[Raku (programming language)|Raku]] also uses secondary sigils, or '''twigils''',<ref>[http://doc.perl6.org/language/variables#Twigils "Perl 6 variables:Twigils"], Perl 6 Documentation.</ref> to indicate the scope of variables. Prominent examples of twigils in Raku include "<code>^</code>" ([[caret]]), used with self-declared formal parameters ("placeholder variables"), and "<code>.</code>", used with object attribute accessors (i.e., instance variables). ==Sigil use in some languages== In [[CLIPS]], scalar variables are prefixed with a "<code>?</code>" sigil, while multifield (e.g., a 1-level list) variables are prefixed with "<code>$?</code>". In [[Common Lisp]], special variables (with dynamic scope) are typically surrounded with <code>*</code> in what is called the "[[earmuff convention]]". While this is only convention, and not enforced, the language itself adopts the practice (e.g., *standard-output*). Similarly, some programmers surround constants with <code>+</code>. In [[CycL]], variables are prefixed with a "<code>?</code>" sigil.<ref>{{cite web|url=http://www.cyc.com/cycl/syntax/variables/|title=Variables β Cycorp|website=www.Cyc.com|access-date=31 December 2017}}</ref> Similarly, constant names are prefixed with "<code>#$</code>" (pronounced "hash-dollar").<ref>{{cite web|url=http://www.cyc.com/cycl/syntax/constants-0/|title=Constants β Cycorp|website=www.Cyc.com|access-date=31 December 2017}}</ref> In [[Elixir (programming language)|Elixir]], sigils are provided via the "<code>~</code>" symbol, followed by a letter to denote the type of sigil, and then delimiters. For example, <code>~r(foo)</code> is a regular expression of "foo". Other sigils include <code>~s</code> for strings and <code>~D</code> for dates. Programmers can also create their own sigils.<ref>{{cite web | url=https://elixir-lang.org/getting-started/sigils.html | title=Getting Started: Sigils | website=Elixir | access-date=18 January 2022}}</ref> In the [[Esoteric programming language|esoteric]] [[INTERCAL]], variables are a 16-bit integer identifier prefixed with either "<code>.</code>" (called "spot") for 16-bit values, "<code>:</code>" (called "twospot") for 32-bit values, "<code>,</code>" ("tail") for arrays of 16-bit values and "<code>;</code>" ("hybrid") for arrays of 32-bit values.<ref>{{Cite web |title=C-INTERCAL 0.29 Revamped Instruction Manual |url=http://catb.org/~esr/intercal/ick.htm#Constants-and-Variables |access-date=2022-06-30 |website=catb.org}}</ref> The later CLC-Intercal added "<code>@</code>" ("whirlpool") for a variable that can contain no value (used for [[Class (computer programming)|classes]]) and "<code>_</code>" used to store a modified [[compiler]].<ref>{{Cite web |title=CLC-INTERCAL Reference |url=https://oshaboy.github.io/clc_intercal_docs/expressions.html#variables |access-date=2022-06-30 |website=oshaboy.github.io}}</ref> In [[MAPPER]] (aka BIS), named variables are prefixed with "<" and suffixed with ">" because strings or character values do not require quotes. In [[mIRC script]], identifiers have a "<code>$</code>" sigil, while all variables have a "<code>%</code>" prefixed (regardless of local or global variables or data type). Binary variables are prefixed by an "<code>&</code>". In the [[MUMPS (programming language)|MUMPS]] programming language, "<code>$</code>" precedes intrinsic function names and "special variable names" (built-in variables for accessing the execution state). "<code>$Z</code>" precedes non-standard intrinsic function names. "<code>$$</code>" precedes extrinsic function names. Routines (used for procedures, subroutines, functions) and global variables (database storage) are prefixed by a caret (^). The last global variable subtree may be referenced indirectly by a caret and the last subscript; this is referred to as a "naked reference". 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". In [[Objective-C]], string literals preceded with "<code>@</code>" are instances of the object type <code>NSString</code> or, since [[clang]] v3.1 / [[LLVM]] v4.0, <code>NSNumber</code>, <code>NSArray</code> or <code>NSDictionary</code>. The prefix <code>@</code> is also used on the keywords <code>interface</code>, <code>implementation</code>, and <code>end</code> to express the structure of class definitions. Within class declarations and definitions as well, a prefix of <code>-</code> is used to indicate member methods and variables, while prefix <code>+</code> indicates class elements. In the [[PHP]] language, which was largely inspired by Perl, "<code>$</code>" precedes any [[variable (programming)|variable]] name. Names not prefixed by this are considered [[constant (computer science)|constants]], [[function (computer science)|functions]] or [[Class (computer programming)|class]] names (or interface or trait names, which share the same namespace as classes). [[PILOT]] uses "<code>$</code>" for buffers (string variables), "<code>#</code>" for integer variables, and "<code>*</code>" for program labels. [[Python (programming language)|Python]] uses a "<code>__</code>" prefix, called ''dunder'', for [[name mangling#Python|"private" attributes]]. In [[Ruby programming language|Ruby]], ordinary variables lack sigils, but "<code>$</code>" is prefixed to [[global variable]]s, "<code>@</code>" is prefixed to [[instance variable]]s, and "<code>@@</code>" is prefixed to [[class variable]]s. Ruby also allows (strictly conventional) suffix sigils: "<code>?</code>" indicates a predicate method returning a [[Boolean function|boolean]] or a [[truth value#Computing|truthy or falsy]] value, and "<code>!</code>" indicates that the method may have a potentially unexpected effect and needs to be handled with care.<ref>{{cite web|last=Black|first=David A.|title=Bang methods; or, Danger, Will Rubyist!|date=15 August 2007|url=http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist|archive-url=https://web.archive.org/web/20160522235741/http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist|archive-date=22 May 2016}}</ref> In [[Scheme (programming language)|Scheme]], by convention, the names of procedures that always return a boolean value usually end in "<code>?</code>". Likewise, the names of procedures that store values into parts of previously allocated Scheme objects (such as pairs, vectors, or strings) usually end in "<code>!</code>". [[Standard ML]] uses the prefix sigil "<code>'</code>" on a variable that refers to a type. If the sigil is doubled, it refers to a type for which equality is defined. The "<code>'</code>" character may also appear within or at the end of a variable, in which case it has no special meaning. In [[Transact-SQL]], "<code>@</code>" precedes a local variable or parameter name. System functions (previously known as global variables) are distinguished by a "<code>@@</code>" prefix. The scope of temporary tables is indicated by the prefix "<code>#</code>" designating local and "<code>##</code>" designating global. In [[Windows PowerShell]], which was partly inspired by [[Unix shell]]s and Perl, variable names are prefixed by the "<code>$</code>" sigil. In [[XSLT]], variables and parameters have a leading "<code>$</code>" sigil on use, although when defined in <code><xsl:param></code> or <code><xsl:variable></code> with the "<code>name</code>" attribute, the sigil is not included. Related to XSLT, [[XQuery]] uses the "<code>$</code>" sigil form both in definition and in use. In [[Maya Embedded Language|MEL]], variable names are prefixed by "<code>$</code>" to distinguish them from functions, commands, and other identifiers. ==Similar phenomena== ===Shell scripting variables=== In Unix [[shell scripting]] and in utilities such as [[Makefile]]s, the "<code>$</code>" is a unary operator that translates the name of a variable into its contents. While this may seem similar to a sigil, it is properly a [[unary operation|unary operator]] for lexical [[indirection]], similar to the <code>*</code> [[dereference operator]] for pointers in [[C (programming language)|C]], as noticeable from the fact that the dollar sign is omitted when assigning to a variable. ===Identifier conventions=== In [[Fortran language features|Fortran]], sigils are not used, but all variables starting with the letters I, J, K, L, M and N are [[integers]] by default. Fortran documentation refers to this as "implicit typing". Explicit typing is also available to allow any variable to be declared with any type. Various programming languages including [[Prolog]], [[Haskell (programming language)|Haskell]], [[Ruby (programming language)|Ruby]] and [[Go (programming language)|Go]] treat [[identifier]]s beginning with a capital letter differently from identifiers beginning with a small letter, a practice related to the use of sigils. ===Stropping=== {{main|Stropping (syntax)}} Actually a form of [[stropping (syntax)|stropping]], the use of many languages in Microsoft's [[.NET Framework|.NET]] [[Common Language Infrastructure]] (CLI) requires a way to use variables in a different language that may be keywords in a calling language. This is sometimes done by prefixes. In [[C Sharp (programming language)|C#]], any variable names may be prefixed with "<code>@</code>". This is mainly used to allow the use of variable names that would otherwise conflict with keywords.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/x53a06bb.aspx |work=MSDN |title=C# Keywords |access-date=2011-03-23 }}</ref> The same is achieved in [[VB.Net]] by enclosing the name in square brackets, as in <code>[end]</code>.<ref>{{cite web |url=http://msdn.microsoft.com/en-us/library/362314fe.aspx |work=MSDN |title=string (C# Reference) |access-date=2011-03-23 }}</ref> The "<code>@</code>" prefix can also be applied to string literals; see [[#Literal affixes|literal affixes]] below. === Hungarian notation === Related to sigils is [[Hungarian notation]], a [[Naming convention (programming)|naming convention]] for variables 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 specified for the variables (unless using a language with [[type inference]]). 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.<ref name="Linux kernel coding style">[https://slurm.schedmd.com/coding_style.pdf Linux kernel coding style], by Linus Torvalds</ref> ===Literal affixes=== While sigils are applied to names (identifiers), similar prefixes and suffixes can be applied to [[Literal (computer programming)|literals]], notably [[integer literal]]s and [[string literal]]s, specifying either how the literal should be evaluated, or what data type it is. For example, <code>0x10ULL</code> evaluates to the value 16 as an unsigned long long integer in C++: the <code>0x</code> prefix indicates hexadecimal, while the suffix <code>ULL</code> indicates unsigned long long. Similarly, prefixes are often used to indicate a [[raw string]], such as <code>r"C:\Windows"</code> in Python, which represents the string with value <code>C:\Windows</code>; as an escaped string this would be written as <code>"C:\\Windows"</code>. 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. ===Java annotations=== Compare [[Java annotation]]s such as @Override and @Deprecated. ===Confusion=== In some cases the same syntax can be used for distinct purposes, which can cause confusion. For example, in [[C Sharp (programming language)|C#]], the "<code>@</code>" 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. ==See also== * [[Delimiter]] * [[Source code]] * [[Lexical analysis#Token|Token]] ==References== {{Reflist}} {{DEFAULTSORT:Sigil (Computer Programming)}} [[Category:Source code]] [[Category:Variable (computer science)]] [[Category:Naming conventions]]
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)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite web
(
edit
)
Template:IPAc-en
(
edit
)
Template:Main
(
edit
)
Template:Other uses
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)