SICP Section 2.3

Jul 29, 2017 09:01 · 188 words · 1 minute read abstraction SICP programming

This section of the book discusses symbols and goes into further details on how to use them(and abstract data) in various examples: symbolic differentiation, representing sets, and Huffman Encoding trees. I will not discuss any of these here.

Scheme supports the use of symbols. They look like this:

(define exampleSymbol 'a)

Symbols can be thought of as arbitrary data objects as opposed to expressions. We use the single quote(as shown) above to represent symbols. Scheme provides us a primitive, eq? as a means of checking if 2 symbols are equal. Here’s a simple demo:

;; a is not a symbol
(define a 10)

;; b is a symbol
(define b 'a)

;; Returns false because
;; you are comparing a symbol
;; to a variable(i.e a=10)
(eq? 'a a)

;; Both return true
(eq? 'a 'a)
(eq? 'a b)

Other procedures for manipulating symbols can be constructed from eq?.


Why are symbols important?

Symbols extend the representational ability of our language by introducing the ability to work with arbitrary symbols as data. A really good example is ‘symbolic differentiation’ which is explained quite well in the book here