Penflip - Write better with others
No account? Signup
Ready to write better?
Have an account? Login
Clojure: From Zero to Deploy
start content of chapter 3
about 6 years ago
# More Types
Let's look at a symbol.
A symbol in Clojure is a piece that allows us to reference things locally. For our purposes there is not much more that is needed in digging into them.Their most common use is to be referred to then filled in with a value.
If you are familiar with program concepts in general (which you should be if reading this book) you will have heard the term 'truthiness' many times before. The 'truthiness' structure of Clojure works as follows.
As you can see, there is little surprise here outside of nil returning false. In Ruby we would see this:
So, we now can deduce nil evaluates to false. Now, let us look at the next thing that may catch you off guard if you come from the wonderful land of C.
Clojure's only negative return types are nil and false. Now, we can also use our standard not, and, and or operators.
Not returns the opposite.
(and "pants" "are" "off")
(and false true true false)
And returns the first negative value, or the last one if all are truthy.
(or false "my pants are off")
;=>"my pants are off"
Or returns the first positive value.
Keywords are much like symbols. They contain a value to name something. They are much more useful when being paired with other data rather than operating on their lonesome. (They are just SO clingy)
We'll play with these rascals more once we get into maps later.
Penflip is made by
in Los Angeles, California
Terms & Privacy