defn , defmacro , defstruct , and these are just macros to determine their corresponding structure, which makes it unnecessary to write boilerplate code. For example, defn makes it easy to write functions, since you no longer have to worry about entering a lambda term (which you can do in the Scheme by simply copying the arguments immediately after the name is defined):
Scheme:
(define hello (lambda (name) (display (string-append "hello, " name)))) (define (hello name) (display (string-append "hello, " name)))
Clojure:
(def hello (fn [name] (println (str "hello, " name)))) (defn hello [name] (println (str "hello, " name)))
You can look at defn as a mnemonic device for def + fn . Such labels make less coding and make the code easier to read as a whole. I teach someone how to program Scheme at the moment, and I force them to use long forms so that they always keep in mind what this language does (and they will appreciate the work saving macro when they finally start using them).
The define or def forms name the following expression. The lambda or fn form gives the name a set of bindings when used in a define or def expression. That things are starting to get more complicated, and using macros keeps you healthy and protects you from typing boredom.
Pinchle
source share