Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.lang.reflect.*; | |
| //This is still basically an estimate, but should be reasonably accurate. | |
| public class SizeOf { | |
| //4 bytes on 32 bit JVM | |
| public static final int REFERENCE_SIZE = 8; | |
| public static int deepSize(boolean b) { return 1; } | |
| public static int deepSize(byte b) { return 1; } | |
| public static int deepSize(char c) { return 2; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn digits | |
| "Generate a list of digits contained in the number" | |
| [number] | |
| (loop [found-digits '() base (quot number 10) digit (rem number 10)] | |
| (let [found-digits (conj found-digits (if (neg? digit) (- digit) digit))] | |
| (if (zero? base) | |
| found-digits | |
| (recur found-digits (quot base 10) (rem base 10)))))) | |
| (defn divisible-digits |
Check these boxes as they're completed.
- Dev Planning/Spike
- 30% Review
A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.
How to use:
- The link in the table of content jumps at the copy of the answer on this page.
- The link on the answer itself points back at the original post.