ArticleslgStudy

science

Symbol (programming)

Symbol (programming) is a 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 Symbol (programming) rather than just read about it. In short: A symbol in computer programming is a primitive data type whose instances have a human-readable form. Symbols can be used as identifiers.

Key takeaways

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

Reference excerpt

A symbol in computer programming is a primitive data type whose instances have a human-readable form. Symbols can be used as identifiers. In some programming languages, they are called atoms. Uniqueness is enforced by holding them in a symbol table. The most common use of symbols by programmers is to perform language reflection (particularly for callbacks), and the most common indirectly is their use to create object linkages. In the most trivial implementation, they are essentially named integers; e.g., the enumerated type in C language.

Support The following programming languages provide runtime support for symbols:

Julia Symbols in Julia are interned strings used to represent identifiers in parsed Julia code(ASTs) and as names or labels to identify entities (for example as keys in a dictionary).

Lisp A symbol in Lisp is unique in a namespace (or package in Common Lisp). Symbols can be tested for equality with the function EQ. Lisp programs can generate new symbols at runtime. When Lisp reads data that contains textual represented symbols, existing symbols are referenced. If a symbol is unknown, the Lisp reader creates a new symbol. In Common Lisp, symbols have the following attributes: a name, a value, a function, a list of properties and a package. In Common Lisp it is also possible that a symbol is not interned in a package. Such symbols can be printed, but when read back, a new symbol needs to be created. Since it is not interned, the original symbol can not be retrieved from a package. In Common Lisp symbols may use any characters, including whitespace, such as spaces and newlines. If a symbol contains a whitespace character, it needs to be written as |this is a symbol|. Symbols can be used as identifiers for any kind of named programming constructs: variables, functions, macros, classes, types, goto tags and more. Symbols can be interned in a package. Keyword symbols are self-evaluating, and interned in the package named KEYWORD.

Examples The following is a simple external representation of a Common Lisp symbol:

Symbols can contain whitespace (and all other characters):

In Common Lisp symbols with a leading colon in their printed representations are keyword symbols. These are interned in the keyword package.

A printed representation of a symbol may include a package name. Two colons are written between the name of the package and the name of the symbol.

Packages can export symbols. Then only one colon is written between the name of the package and the name of the symbol.

Symbols, which are not interned in a package, can also be created and have a notation:

PostScript In PostScript, references to name objects can be either literal or executable, influencing the behaviour of the interpreter when encountering them. The cvx and cvl operators can be used to convert between the two forms. When names are constructed from strings by means of the cvn operator, the set of allowed characters is unrestricted.

Prolog In Prolog, symbols (or atoms) are the main primitive data types, similar to numbers. The exact notation may differ in different Prolog dialects. However, it is always quite simple (no quotations or special beginning characters are necessary). Contrary to many other languages, it is possible to give symbols a meaning by creating some Prolog facts and/or rules.

Examples The following example demonstrates two facts (describing what father is) and one rule (describing the meaning of sibling). These three sentences use symbols (father, zeus, hermes, perseus and sibling) and some abstract variables (X, Y and Z). The mother relationship is omitted for clarity.

Ruby In Ruby, symbols can be created with a literal form, or by converting a string. They can be used as an identifier or an interned string. Two symbols with the same contents will always refer to the same object. It is considered a best practice to use symbols as keys to an associative array in Ruby.

Examples The following is a simple example of a symbol literal in Ruby:

Strings can be coerced into symbols, vice versa:

Symbols are objects of the Symbol class in Ruby:

Symbols are commonly used to dynamically send messages to (call methods on) objects:

Symbols as keys of an associative array:

Smalltalk In Smalltalk, symbols can be created with a literal form, or by converting a string. They can be used as an identifier or an interned string. Two symbols with the same contents will always refer to the same object. In most Smalltalk implementations, selectors (method names) are implemented as symbols.

Examples The following is a simple example of a symbol literal in Smalltalk:

Strings can be coerced into symbols, vice versa:

Symbols conform to the symbol protocol, and their class is called Symbol in most implementations:

Symbols are commonly used to dynamically send messages to (call methods on) objects:

References

Worked examples

Example 1 — a first encounter with Symbol (programming)

Start with the simplest possible case. Write down what Symbol (programming) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In 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 Symbol (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 Symbol (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 Symbol (programming)

In research
Symbol (programming) appears in 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 Symbol (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
Symbol (programming) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Programming constructs, so understanding it makes those chapters shorter.
In everyday life
Look for Symbol (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.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Symbol (programming)” →

How to study Symbol (programming) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Symbol (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 Symbol (programming) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Symbol (programming) in simple terms?

A symbol in computer programming is a primitive data type whose instances have a human-readable form. Symbols can be used as identifiers.

Why does Symbol (programming) matter?

Because it connects several 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 Symbol (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 Symbol (programming).

Tags

  • Programming constructs

Keep exploring