Exploring Clojure (Lisp on the JVM) - Part 4: Not Your Daddy's Namespaces. Wednesday, October 29, 2008 Ok, now I know that Namespaces are probably not the sexiest topic for a blog post and, since you're reading this at all, you are probably just curious as to why someone would possibly want to blog about them! Well, when I first started looking at namespaces in Clojure , I probably would have said the same thing. However, as I played around with them a bit, I found that namespaces provided some interesting info about how Clojure works "under the covers".
So, in this post, I won't try to cover all of the namespace functions (that's easy enough to read up on), I'll just try to go through the "interesting bits" that I discovered while playing. First of all, Clojure exposes 6 different namespaces through it's API : user> (resolve 'concat) #=(var clojure/concat) user> (resolve 'do) nil Therefore, if you re-define something that is a special form, you have to specify the namespace as well when using the new definition: (.
Clojure Setup Tutorial with EMACS: clojure, clojure.contrib, swank, slime, maven and maven-clojure-plugin in a couple of seconds. As of 22nd September 2011, this is still working fine, this time on Fedora 14 (substituting yum for apt-get, but that's the only difference) I've just (15th February 2011) had to set this up again for someone on an Ubuntu 10.10 box. And to my speechless amazement (16th February 2011), it worked absolutely the same way on Radek Ostrowski (a complete stranger) 's mac at dev8d, thus condemning him to years of suffering at the hands of Aquamacs. This method is still my favourite, still the one I actually use in practice, and still the easiest, and it's been stable for about a year now.
Since I've just confirmed that it still works, I've moved it back to the top. Install maven: $sudo apt-get install maven2 Then create a pom.xml file to tell maven which repositories to use. If you like to use EMACS instead, then $mvn clojure:swank Will start a swank server, which you can connect to with M-x slime-connect.That's it from the clojure side. <replScript>startup.clj</replScript> World Cognition By Programming: Setting up Emacs for Clojure programming. When starting my first Clojure journey recently, I faced the problem of setting up Emacs for Clojure programming. It can seem cumbersome to do it right if you aren't aware of some pitfalls, and many tutorials and answers at stackoverflow are outdated. So, I leave simple up to date instructions here intended for complete Emacs beginners (you must have at least read the built-in tutorial available on C-h t). Why Emacs Personally, I find Emacs the most suited editor for Clojure (far beyond Eclipse, IntelliJ plugins).
It supports Lisps very well through being itself written and extended (mostly) in Lisp dialect. Secondly, I loved its minimalistic and fully configurable interface, so now I find myself trying to reduce the visual clutter when using Eclipse or IntelliJ by hiding tool-bars, panels, menus and so on. And finally: you will never overgrow it. Choosing version This tutorial aims to be OS-agnostic so the setup will work on Linux, OSX, Windows without any changes.
Leiningen 2. Clojure Libraries. 4clojure – Welcome! Docs - clojure.core/zipmap. Clojure: Destructuring. In The Joy of Clojure (TJoC) destructuring is described as a mini-language within Clojure. It's not essential to learn this mini-language; however, as the authors of TJoC point out, destructuring facilitates concise, elegant code. What is destructuring? Clojure supports abstract structural binding, often called destructuring, in let binding lists, fn parameter lists, and any macro that expands into a let or fn. -- The simplest example of destructuring is assigning the values of a vector. user=> (def point [5 7])#'user/point user=> (let [[x y] point] (println "x:" x "y:" y))x: 5 y: 7 note: I'm using let for my examples of destructuring; however, in practice I tend to use destructuring in function parameter lists at least as often, if not more often.
I'll admit that I can't remember ever using destructuring like the first example, but it's a good starting point. User=> (def indexes [1 2 3])#'user/indexes user=> (def point {:x 5 :y 7})#'user/point. Writing a Clojure/Clojurescript Web Project: Part 1 | Clojured - Figuring out Clojure, Clojurescript, Web frameworks and more. This post is an explanation of what I'm using to write Clojure/Clojurescript web projects. I will take you through the basics of writing web app using the technologies I enjoy working with the most. It will delve into the following topics:A basic review and explanation of the concepts of Clojure/Clojurescript.The software ecosystem surrounding writing a Clojure/Clojurescript web project.The libraries and frameworks I've chosen to use.How to write something basic. Part 2 will cover: How to run the server and deploy a standalone (uberjar) executable which includes your web project and the jetty web server to serve it.Adding NoSQL database functionality with the Redis NoSQL database server and the carmine Redis library.
Basic Clojure and Clojurescript Roles and Concepts This is to reinforce the difference between Clojure and Clojurescript. Software Ecosystem I'm doing my development on Windows 7, however the tools I'm using should all be available for both OSX and Linux. Leiningen Light Table. Learning Clojure through the REPL. First hundred days of Clojure | byte bohemian. In politics you have a one hundred days period of grace. In December I started to work with Clojure, so I guess it’s time to have a clojure look. In the last couple of years I encountered a couple of different languages. At scoyo it was ActionScript and Flex from Adobe. I had the honor to lead a team of great engineers, but with good people you don’t get close enough to the real stuff. At gamigo the new technology was PHP. But for the last thirteen years Java was always a big part of my career…At my new job the new kid on the block is Clojure – a LISP dialect based on Java VM.
When we started to work on our new product I said to my boss and my colleagues: In Java I know how a state of the art application has to look like, but I have no clue how to build a Clojure application. Leiningen (aka lein) – The build and dependency managmement tool for Clojure.Noir – A nice library to build websites/-services in Clojure.CongoMongo and mongoDB – The database driver and the database we use. Incanter: Statistical Computing and Graphics Environment for Clojure. Ready Set Clojure! The Clojure Toolbox. Frak takes an entirely different approach to generating regular expressions. Hot on the heals of our Verbal Expressions coverage comes Frak by Joel Holdbrooks.
Frak also generates regular expressions for you, but it does it in a completely different way. With Frak, you don’t write an expression to match string patterns. Instead, you give it a set of strings and it generates an expression which matches them. Frak is written in Clojure, so you install it by adding a dependency to your project.clj file: [frak "0.1.2"] To use it, simply require it, pass it a collection of strings, and it will return the resulting regular expression: user> (require 'frak) nil user> (frak/pattern ["foo" "bar" "baz" "quux"]) #"(?
Check out the README to learn how it works, see some benchmarks, and get frak’in! If you have an opinion share it on Hacker News. Basic Web Development | Clojure Documentation | Clojure Docs. This guide covers building a simple web-application using common Clojure libraries. When you're done working through it, you'll have a little webapp that displays some (x, y) locations from a database, letting you add more locations as well. It's assumed that you're already somewhat familiar with Clojure. If not, see the Getting Started and Introduction guides. This work is licensed under a Creative Commons Attribution 3.0 Unported License (including images & stylesheets). This guide uses Clojure 1.5, as well as current versions of the component libraries noted below. Conceptual Overview of Components We'll use four major components (briefly described below) for our little webapp: RingCompojureHiccupH2 Ring Ring (at clojars) is a foundational Clojure web application library.
For this tutorial, we won't actually need to deal with these maps by-hand, as you'll soon see. For more info, see: Compojure Hiccup Hiccup (at clojars) provides a quick and easy way to generate html. Becomes Add some styling.