I grew up on "Algol" style languages like Java, C++, and ActionScript 3 where one of the first things you learn about is the concept of a class, a blueprint for an object. I guess I'm too young to remember a lisp world without Clojure so at first I was amazed that you could even have a programming language that didn't based its foundational architectural patterns around classes or object use classes! I just today was working on a project and found it refreshingly simple to just write some functions in a namespace so I could require and call them from another file. In this post we'll take a look at how to we import functions in a ClojureScript project using the build tool leiningen without classes or objects.
The beauty of Clojure's non-OOP style is that the functions are not tied to some blueprint that needs to be instantiated. Instead, once they are included, required, or loaded, etc. the functions are just there, able to be called at some later point in the code. Because of this, Idiomatic Clojure lends itself well to functions that are pure and can be called in complete isolation. It should be noted that load-file works for both Clojure and ClojureScript!
This is a pretty silly mistake that I was making, but it was really confusing me for a minute. I was forgetting to wrap the arguments and function body within a set of parens when using multi-arity functions in ClojureScript. Let me know you what I mean.
The shorthand syntax for an anonymous function in Clojure can be a bit confusing (at least it was for me when I first saw it!). In this post I'll go over what it is and show that it's actually not all that scary.
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
Sign up here:
- Triple Gainers
- Rippers N' Dippers
- Growingest Growers