Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>defn</code>, <code>defmacro</code>, <code>defstruct</code> and such are just macros for defining their corresponding structure, making it unnecessary to write boilerplate code. For example, <code>defn</code> makes it easier to write functions since you no longer have to worry about putting in the lambda term (which you can do in Scheme just by bracketing the arguments immediately after the name being defined):</p> <p>Scheme:</p> <pre><code>(define hello (lambda (name) (display (string-append "hello, " name)))) (define (hello name) (display (string-append "hello, " name))) </code></pre> <p>Clojure:</p> <pre><code>(def hello (fn [name] (println (str "hello, " name)))) (defn hello [name] (println (str "hello, " name))) </code></pre> <p>You can look at <code>defn</code> as a mnemomic device for <code>def</code> + <code>fn</code>. Such shortcuts make for less boilerplate coding and make the code just easier to read in general. I'm teaching someone how to program Scheme at the moment and I make them use the long forms so that they have in mind at all times what the language is doing (and will appreciate the work-saving macros all the more when they finally start using them).</p> <p>The <code>define</code> or <code>def</code> forms give a name to some expression that follows. The <code>lambda</code> or <code>fn</code> form gives the name a set of bindings when used within a <code>define</code> or <code>def</code> expression. That's where things start to get more complex and the use of macro forms keeps you sane and protects you from typing boredom.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload