Symbol (computer science)

from Wikipedia, the free encyclopedia

Some programming languages have their own symbol data type , which usually has the meaning of a flag . However, “the symbol or ” cannot be assigned, but “it is available or not available”. A symbol is closely related to the identifier , but is not a variable , since a symbol cannot have a value. Sometimes the name of the symbol in the sense of a character string is also important. truefalse

The two types of use "flag" and "character string" are used, for example. B. supported by Common Lisp and Scheme . Symbols are similar to the entries of enumerated types . In some languages ​​a symbol object can be assigned a value; then it becomes (in a sense) a constant, a variable, an object or a function.


Data type (Scheme)

In many functional languages ​​such as B. Common Lisp or Scheme, "Symbol" is directly a data type:

(define l_colour
        (list 'red 'green 'blue 'cyan 'magenta 'yellow 'white 'black 'gray 'brown)
(equals? 'red (car l_colour))
-> #true
(symbol->string (cdar l_colour))
-> green


Symbols are intended to be used as key values for Maps and Objects in JavaScript . A symbol is always unique, i. H.

let a = Symbol('x');
let b = Symbol('x');

ais unequal b . This can be changed explicitly by

let a = Symbol.for('x');
let b = Symbol.for('x');

is used; now applies a === b.

See also

Notes and individual references

  1. In JavaScript there is 'Symbol' as a separate data type from Version 2.0; Source: Herbert Braun: JavaScript is growing up. The innovations in ECMAScript 6. In: C't . Heise Zeitschriften Verlag GmbH & Co KG , December 23, 2014, pp. 168ff , accessed on January 5, 2015 .