new file: On_Strings.txt

rhgraysonii authored
revision 77d3445d089fc214e3311d5b2755acbd78a37118
Contents
> These files will be included in your book:

chapter1.txt
A_Loose_Introduction.txt
On_Strings.txt
On_Strings
# Strings

Strings are one of the most intrinsic things that we use to communicate. This book is essentially being parsed in your mind as a series of strings. Strings are often objects of input/output in programs to be modified, displayed, and fudged with. If you're familiar with a variety of languages you probably are of the understanding that depending on what you are working with, a string can be both an object or a primitive. In Clojure, we aren't functioning in an Object Oriented language. It is primarily functional in its application.

Though Clojure itself is not an object oriented language, it is, however, implemented in Java. The compilation results in the code being run as Java VM code. This results in a string in Clojure being compiled as an instance of a String object in Java, which is a series of char primitives.

Most of Clojure's data types are immutable, as mentioned prior. They never change. Clojure favors comparison of equality much moreso than comparison of identity. In most languages this is discouraged because the values are deeply built into the structure of each instance of an object. Thusly, Clojure compares content. An example:

(= "pants" ( str "pan" "ts"))
;=>true

However, in Ruby:
class Foo
def hello
"hello"
end
end
Now that we have defined a class, lets make some instances of it

a = Foo.new
b = Foo.new
a == b
>false
a.hello == b.hello
>true

Clojure makes this comparison cheap on resources. A Clojure object in this situation is keeping around a hash of itself, and this hash is what is compared rather than deeply inspecting it. This, however, only works if all parties involved are completely immutable. As stated, not ALL pieces of Clojure are immutable.