ArticleslgStudy

computer science

Sigil (computer programming)

Sigil (computer programming) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Sigil (computer programming) rather than just read about it. In short: In computer programming, a sigil () 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, from the Latin sigillum, meaning a "little sign", means a sign or image supposedly having magical power.

Key takeaways

  • Sigil (computer programming) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Sigil (computer programming) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Sigil (computer programming) from memory before moving on to harder problems.

Reference excerpt

In computer programming, a sigil () 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, from the Latin sigillum, meaning a "little sign", means a sign or image supposedly having magical power. Sigils can be used to separate and demarcate namespaces 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 ("$") appended to the names of all strings. Many BASIC dialects use other sigils (like "%") to denote integers and floating-point numbers and their precision, and sometimes other types as well. Larry Wall adopted shell scripting's use of sigils for his Perl programming language. 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 "&"). Raku also uses secondary sigils, or twigils, to indicate the scope of variables. Prominent examples of twigils in Raku include "^" (caret), used with self-declared formal parameters ("placeholder variables"), and ".", used with object attribute accessors (i.e., instance variables).

Sigil use in some languages In CLIPS, scalar variables are prefixed with a "?" sigil, while multifield (e.g., a 1-level list) variables are prefixed with "$?". In Common Lisp, special variables (with dynamic scope) are typically surrounded with * 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 +. In CycL, variables are prefixed with a "?" sigil. Similarly, constant names are prefixed with "#$" (pronounced "hash-dollar"). In Elixir, sigils are provided via the "~" symbol, followed by a letter to denote the type of sigil, and then delimiters. For example, ~r(foo) is a regular expression of "foo". Other sigils include ~s for strings and ~D for dates. Programmers can also create their own sigils. In the esoteric INTERCAL, variables are a 16-bit integer identifier prefixed with either "." (called "spot") for 16-bit values, ":" (called "twospot") for 32-bit values, "," ("tail") for arrays of 16-bit values and ";" ("hybrid") for arrays of 32-bit values. The later CLC-Intercal added "@" ("whirlpool") for a variable that can contain no value (used for classes) and "_" used to store a modified compiler. 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 "$" sigil, while all variables have a "%" prefixed (regardless of local or global variables or data type). Binary variables are prefixed by an "&". In the MUMPS programming language, "$" precedes intrinsic function names and "special variable names" (built-in variables for accessing the execution state). "$Z" precedes non-standard intrinsic function names. "$$" 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 "@" are instances of the object type NSString or, since clang v3.1 / LLVM v4.0, NSNumber, NSArray or NSDictionary. The prefix @ is also used on the keywords interface, implementation, and end to express the structure of class definitions. Within class declarations and definitions as well, a prefix of - is used to indicate member methods and variables, while prefix + indicates class elements. In the PHP language, which was largely inspired by Perl, "$" precedes any variable name. Names not prefixed by this are considered constants, functions or class names (or interface or trait names, which share the same namespace as classes). PILOT uses "$" for buffers (string variables), "#" for integer variables, and "*" for program labels. Python uses a "__" prefix, called dunder, for "private" attributes. In Ruby, ordinary variables lack sigils, but "$" is prefixed to global variables, "@" is prefixed to instance variables, and "@@" is prefixed to class variables. Ruby also allows (strictly conventional) suffix sigils: "?" indicates a predicate method returning a boolean or a truthy or falsy value, and "!" indicates that the method may have a potentially unexpected effect and needs to be handled with care. In Scheme, by convention, the names of procedures that always return a boolean value usually end in "?". Likewise, the names of procedures that store values into parts of previously allocated Scheme objects (such as pairs, vectors, or strings) usually end in "!". Standard ML uses the prefix sigil "'" on a variable that refers to a type. If the sigil is doubled, it refers to a type for which equality is defined. The "'" character may also appear within or at the end of a variable, in which case it has no special meaning. In Transact-SQL, "@" precedes a local variable or parameter name. System functions (previously known as global variables) are distinguished by a "@@" prefix. The scope of temporary tables is indicated by the prefix "#" designating local and "##" designating global. In Windows PowerShell, which was partly inspired by Unix shells and Perl, variable names are prefixed by the "$" sigil. 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. Related to XSLT, XQuery uses the "$" sigil form both in definition and in use. In MEL, variable names are prefixed by "$" to distinguish them from functions, commands, and other identifiers.

Similar phenomena

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Sigil (computer programming)

Start with the simplest possible case. Write down what Sigil (computer programming) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Sigil (computer programming) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Sigil (computer programming) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Sigil (computer programming)

In research
Sigil (computer programming) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Sigil (computer programming) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Sigil (computer programming) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Naming conventions, Source code, Variable (computer science), so understanding it makes those chapters shorter.
In everyday life
Look for Sigil (computer programming) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Sigil (computer programming) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Sigil (computer programming) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Sigil (computer programming) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Sigil (computer programming) in simple terms?

In computer programming, a sigil () 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, from the Latin sigillum, meaning a "little sign", means a sign or image supposedly having magical power.

Why does Sigil (computer programming) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Sigil (computer programming)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Sigil (computer programming).

Tags

  • Naming conventions
  • Source code
  • Variable (computer science)

Keep exploring