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
[:~/clojure/git/lib-noir on master] | |
λ rm -r ~/.m2/repository/leinjacker 1 ↵ ✭ | |
[:~/clojure/git/lib-noir on master] | |
λ lein clean ✭ | |
Retrieving leinjacker/leinjacker/0.4.1/leinjacker-0.4.1.pom from clojars | |
Retrieving leinjacker/leinjacker/0.3.2/leinjacker-0.3.2.pom from clojars | |
Retrieving leinjacker/leinjacker/0.2.0/leinjacker-0.2.0.pom from clojars | |
Retrieving leinjacker/leinjacker/0.3.2/leinjacker-0.3.2.jar from clojars | |
[:~/clojure/git/lib-noir on master] | |
λ lein deps |
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
[:~/clojure/git/lib-noir on master] | |
λ lein clean 1 ↵ ✭ | |
[:~/clojure/git/lib-noir on master] | |
λ lein deps ✭ | |
[:~/clojure/git/lib-noir on master] | |
λ lein doc ✭ | |
Exception in thread "main" java.lang.AssertionError: Assert failed: (vector? (:dependencies project [])) | |
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
λ lein deps ✭ | |
Retrieving codox/codox/0.6.4/codox-0.6.4.pom from clojars | |
Retrieving codox/codox.leiningen/0.6.4/codox.leiningen-0.6.4.pom from clojars | |
Retrieving codox/codox/0.6.4/codox-0.6.4.jar from clojars | |
Retrieving codox/codox.leiningen/0.6.4/codox.leiningen-0.6.4.jar from clojars | |
[:~/clojure/git/lib-noir on master] | |
λ lein doc ✭ | |
Exception in thread "main" java.lang.AssertionError: Assert failed: (vector? (:dependencies project [])) | |
at leinjacker.deps$add_if_missing.invoke(deps.clj:43) | |
at leiningen.d |
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
(ns codelesson.week4-1 | |
(:require clojure.string) | |
(:import (org.slf4j.impl.StaticLoggerBinder)) | |
(:import (javax.swing JFrame JPanel JButton JLabel JTextField JTextArea JScrollPane)) | |
(:import java.awt.event.ActionListener) | |
(:import (javax.swing.event DocumentListener)) | |
(:import (java.awt GridBagLayout GridBagConstraints Dimension)) | |
(:import (java.util.concurrent TimeUnit))) | |
(def fees { :checking {:interest 0.02 :overdraft 0.10} |
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
(ns codelesson.week3-2) | |
(def fees { :checking {:interest 0.02 :overdraft 0.10} | |
:savings {:interest 0.04 :overdraft 0.075} | |
:money-market {:interest 0.06 :overdraft 0.05}}) | |
(def overall-overdraft (atom 100000)) | |
(def accounts (atom [])) | |
(defn random-account-type [] | |
(rand-nth [:checking :savings :money-market])) |
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
(ns codelesson.week3-1 | |
(:require [clojure.string]) | |
(:gen-class)) | |
(defn merge-with-padding [x y] | |
" merge arrays x & y and padding the shorter of the two with nils " | |
(let [cx (count x) cy (count y)] | |
(if (not= cx cy) | |
(if (< cx cy) | |
(map #(vector %1 %2) (concat x (take (- cy cx) (repeat nil) )) y) |
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
# Because we have some old legacy users in the database, we need to override Devises method for checking if a password is valid. | |
# We first ask Devise if the password is valid, and if it throws an InvalidHash exception, we know that we're dealing with a | |
# legacy user, so we check the password against the SHA1 algorithm that was used to hash the password in the old database. | |
#SOURCES OF SOLUTION: | |
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise | |
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb | |
# https://github.com/plataformatec/devise/blob/master/lib/devise/encryptors/authlogic_sha512.rb | |
alias :devise_valid_password? :valid_password? | |
def valid_password?(password) |
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
(ns codelesson.week1-3) | |
(defn debugme [cp cd rp rd] | |
(prn cp cd ) | |
(prn rp) | |
(prn rd) | |
(println "-------------")) | |
(defn nomore [a b] | |
(and (empty? a) (empty? b))) |
NewerOlder