Intro to Clojure on the Web

Lisp is one of those languages that people either love or hate. Count me
among the Lisp lovers. I was brainwashed during my undergraduate
studies at MIT to believe that Lisp is the only "real" programming
language out there, and that anything else is a pale imitation. True,
I use Python and Ruby in my day-to-day work, but I often wish I
had the chance to work with Lisp on a regular basis.

One window of opportunity to do exactly that has opened in the past few
years. Clojure, a modern variant of Lisp that runs on the Java virtual
machine (JVM), has been taking the programming world by storm. It's a
real Lisp, which means that it has all of the goodness you would
want and expect: functional programming paradigms, easy use of complex
data structures and even such advanced facilities as macros. Unlike
other Lisps, and contributing in no small part to its success, Clojure
sits on top of the JVM, meaning that it can interoperate with Java
objects and also work in many existing environments.

In this article, I want to share some of my experiences with starting to
experiment with Clojure for Web development. Although I don't foresee
using Clojure in much of my professional work, I do believe it's
useful and important always to be trying new languages, frameworks
and paradigms. Clojure combines Lisp and the JVM in just the right
quantities to make it somewhat mainstream, which makes it more
interesting than just a cool language that no one is really using for
anything practical.

Clojure Basics

Clojure, as I mentioned above, is a version of Lisp that's based on the
JVM. This means if you're going to run Clojure programs, you're
also going to need a copy of Java. Fortunately, that's not much of an
issue nowadays, given Java's popularity. Clojure itself comes as a
Java archive (JAR) file, which you then can execute.

But, given the number of Clojure packages and libraries you'll
likely want to use, you would be better off using Leiningen, a
package manager for installing Clojure and
Clojure-related packages. (The name is from a story, "Leiningen and
the Ants", and is an indication of how the Clojure community doesn't
want to use the established dependency-management system, Ant.) You
definitely will want to install Leiningen. If your Linux distribution
doesn't include a modern copy already, you can download the shell
script from
https://raw.github.com/technomancy/leiningen/stable/bin/lein.

Execute this shell script, putting it in your PATH. After you download
the Leiningen jarfile, it will download and install Leiningen
in your ~/.lein directory (also known as LEIN_HOME). That's all you
need in order to start creating a Clojure Web application.

With Leiningen installed, you can create a Web application. But in
order to do that, you'll need to decide which framework to use.
Typically, you create a new Clojure project with lein new, either
naming the project on which you want to work (lein new
myproject),
or by naming the template you wish to copy and then the name of the
project (lein new mytemplate myproject). You can get a list of
existing templates by executing lein help new or by looking at the
https://clojars.org site, a repository for Clojure jarfiles and libraries.

You also can open an REPL (read-eval-print loop) in order to
communicate directly with Clojure. I'm not going to go into all the
details here, but Clojure supports all the basic data types you
would expect, some of which are mapped to Java classes. Clojure
supports integers and strings, lists and vectors, maps (that is,
dictionaries or hashes) and sets. And like all Lisps, Clojure
indicates that you want to evaluate (that is, run) code by putting it
inside parentheses and putting the function name first. Thus, you can
say:

You also can assign variables in Clojure. One of the important things
to know about Clojure is that all data is immutable. This is somewhat
familiar territory for Python programmers, who are used to having some
immutable data types (for example, strings and tuples) in the language. In
Clojure, all data is immutable, which means that in order to
"change"
a string, list, vector or any other data type, you really
must reassign the same variable to a new piece of data. For example:

Although it might seem strange to have all data be immutable, this tends
to reduce or remove a large number of concurrency problems. It
also is surprisingly natural to work with given the number of functions
in Clojure that transform existing data and the ability to use
"def"
to define things.

You also can create maps, which are Clojure's implementation of hashes
or dictionaries:

I think Lisp programming language growing popular day by day. Also Clojure for Web development sector Lisp programming language is important. Thanks to introduce me on Clojure Basics. http://www.healthforus.info

The maintenance cost estimates are based on the cost to maintain 50W 24V LED Fire Engine Work lamps a vehicle and perform needed repairs for five years and 75,000 miles, including labor expenses, replacement part prices and the purchase of an extended warranty.

Sponsored by:

Geek Guides

Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.