Thanks! --Christian

Am 13.10.2014 um 19:41 schrieb Jens Axel Søgaard:
2014-10-13 17:53 GMT+02:00 Christian Wagenknecht <[email protected]>:
With regard of Racket's symbols I have a problem with the consistency of the
terminology as follows.
A symbol in Scheme and maybe in earlier Racket versions is considered as an
identifier. For example xyz is a symbol, whereas 'xyz avoids the evaluation
of xyz.
A symbol is not an identifier. An identifier is a name. Typically identifiers
are represented as syntax objects which besides the actual name also
captures source location information (such as line and column numbers).

A symbol is "almost" a string.

       (string->symbol "foo")  produces a symbol spelled foo
       "foo"                             produces a string

For languages with mutable strings the operation string=? takes time
proportional
to the length of the strings. Consider this program:

     (define a "foo")
     (do-something)
     (define b "foo")
     (string=? a b)

If strings are mutable, then (do-something) might have changed "foo" into "fox".
The call (string=? a b) thus needs to compare all characters in a and b.

If on the other hand strings are immutable, then (define a "foo") can store the
characters f, o, and o in a string in a memory location p. The variable b in
(define b "foo") can now share the string, and simply point to the
same location p.
In other words: strings with the same spelling will only be allocated once.
A comparison (string=? a b) can no be reduced to a simple pointer comparison.

Symbols are immutable strings with the guarantee that only one symbol of a
given spelling will be allocated. In order words comparing symbols for
equality is O(1).

You can create a symbol with the spelling foo in several ways. For example
         (string->symbol "foo")
but, since that is cumbersome to write, one can use the abbreviation
         'foo


Identifiers are names that appear in source code. They can be used for example
to name variables.

When programs need to process source code, these names need to be represented
as a concrete value. In Racket identifiers are not represented as
symbols but as syntax
objects. The syntax object contains a symbol that represent the
spelling of the name,
but it also contains lexical information.

/Jens Axel











In current version the little ' (normally as shorthand for quote) belongs to
the symbol. For example 'xyz is a symbol. A symbol is obviously considered
as a quoted identifier, at least syntactically.

However, when using a symbol as part of an expression the prepending '
disappears. For example: (vector 1 'xyz), consisting of a number and a
symbol evaluates to '#(1 xyz). But xyz is not a symbol but an identifier.
Therefore to say that this vector belongs of a number and a symbol is no
longer valid. (vector-ref '#(1 xyz) 1) returns 'xyz, which is correct,
however, this is also visually a difference where there is none.

Could you help me to get it right, please?


____________________
   Racket Users list:
   http://lists.racket-lang.org/users





Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to