Clojure Destructuring with Functions

In clojure terms, destructuring is taking apart a sequence and putting the pieces you care about into variables you can more easily work with. Destructuring involves square brackets that make it look like a vector, but it is really binding a variable from a given seq to a new variable. Let’s look at an example involving a function in Clojure.

Notice the -main function has three variables in a vector: a site address, a web page, and a user name. It is much easier in the new function to unpackage these variables form the vector and bind them to variables that have meaningful names, and then use the names.

The result is as follows.

What if we have more values in the seq than values we intend to bind to? For example, below we added an additional index with the words “random stuff”.

Continue reading “Clojure Destructuring with Functions”

Clojure Redis: Get and Set

For a brief intro to setting up Redis with Clojure using Carmine, see my earlier post on setting up Redis with Clojure.

The most common killer use for Redis is as a key-value store. You simply get and set values in it like in a map. It’s very handy for site wide session storage with web apps, or even in more traditional applications.

Continue reading “Clojure Redis: Get and Set”

Clojure with a Touch of Redis

If you’ve ever done enterprise web application development, you’ve heard of Redis. Redis has a lot of uses, but the most common is as replacement for your standard session. Even just using it’s key-value store (think hashmap on steroids), Redis provides so much power that many enterprise sites integrate it into their larger projects.

Lucky for those of us using Clojure, Redis integrates nicely using Carmine, an open source Clojure library for interacting with Redis.

Continue reading “Clojure with a Touch of Redis”