search


The Power of Names
Sat Mar 10 15:52:06 UTC 2018
Call him Voldemort, Harry. Always use the proper name for things. Fear of a name increases fear of the thing itself.
What is a name?

This may seem like a silly question. Everyone has a name and everything we know about has a name. Everyone intuitively knows what a name is but when asked to define it, most people will have difficulty. In magic, knowing the True Name of something, gives you power over it. Knowing the incantations of a spell gives you magical power that can affect the world. In Semitic religions like Judaism, Christianity and Islam, the name of God is so scared that it is unknown. In the Old Testment, the Israelite did not know God's name but only refer to him as Yahweh which is Hebrew for 'I am who I am'. The Ten Commandments forbids the use of God's name.

Needless to say names are important, but what is it? Are names simply sequence of letters written on paper? Blind people cannot see those letters yet they can make and use names. Are names the sound that come out our of mouths? Deaf people cannot hear sounds yet they can make and use names. The ability to name things is essential to language. Imagine what it would be like if we could not name things. We could not have language.

Names are abstract symbols used to represent or substitute for something else. The name of a thing is not the thing itself. For someone with eyes, the abstract symbol takes the form of letters written on paper or computer screen. For a blind person, it is the feel of the bumps and grooves on their braille reader . For a deaf person, it is motion of the hands and fingers and facial expression.

Giving something a name gives us power over it. It allows us to to discuss it, to communicate it even if we do not know what it is. Science and mathematics are full of examples of this. Dark Matter is a prime example. Scientist do not know what Dark Matter is but they gave it a name. In algebra, an unknown is given an arbitary symbol x. Imaginary numbers were discoverd when trying to find solutions to quadratic equations. The square root of -1 keeps popping up as a solution. Mathematician didn't know what the square root of -1 was so they named it i for imaginary number. They thought it was a fake number because any real number squared is always positive. It turns out if imaginary numbers did not exist, we could not describe electricity or quantum mechanics which means if imaginary numbers didnt exist, we would not exist. Assigning the symbol i to the square root of -1 allowed mathemticians to explore and discover its properties. Centuries later, something that was thought to be imaginary, turned out to be essential to the description of the universe.

Giving something a name is important and it is the simplest and most fundament form of abstraction. Pick names carefully so that they capture the essence of the thing they represent. Software is nothing more than abstractions built on top of abstractions. It is the closest thing we have to magic spells. To the uninitiated, the symbols of names in a program look like the gibberish of a magic spell. These cryptic symbols and names bestow magical powers onto the person who understands their secrets allowing him/her to use the computer like a wizzard uses the magic wand to cast spells.

Naming things in Clojure

def is a "special form" that allows us to create global names. I shall use names and symbols interchangably.

(def my-name "sonny")

This creates a symbol called my-name to the string "sonny". Whereever I need to refer to the string "Sonny", I can substitute the symbol my-name instead.

We already saw one way of creating a function with a name using the defn macro

(defn square [x] (* x x))

square is the name of the function and x is the name of the parameter of that function. defn macro is a short-hand for def and fn . For example:

(def square (fn [x] (* x x))) ;;same as (defn square [x] (* x x))

fn is the special form that creates an anonymous function, or a function without a name. def is then used to associate the symbol square with anonymous function.

fn is also called lambda in other LISP dialects like Scheme . Lambda is where Lambda Calculus derives its name

def creates global names. Clojure also provides a mechanism for creating local names using let macro

(let [my-name "sonny"])

the symbol my-name is only visible within the let scope. In other programming language, this is called a local variable We will talk more about scope later. For the curious, let is a macro that expands into a function

Namespaces

All symbols exist in a namespaces. Namespace prevent collision of symbols with the same name. You are already familar with the concept of a namespace. For example, there are many people in the world with a first-name Sonny. To prevent confusion, we also have a last-name and a middle-name. My last-name is Su and my middle-name is Chung. My complete namespace consists of my first-name, middle-name, and last-name. Symbols in Clojures are organized in the same way to prevent conflict of name. if you look at the REPL above, you'll see 'cljs.user/square This means square is a symbol in the cljs.user namespace.

A namspace can be created using the ns form. For example:

(ns odessa) (defn square [x] (* x x))

Notice above that the namespace of the square symbol is now odessa and not cljs.user . This is like twp person having the same first-name but different last-name.