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
(defn prime-candidates | |
([] (lazy-seq (list* 2 3 (prime-candidates 1)))) | |
([x] (lazy-seq (list* (dec (* x 6)) (inc (* x 6)) (prime-candidates (inc x)))))) | |
(defn prime-candidates-less-than | |
[threshold] | |
(take-while (partial >= threshold) (prime-candidates))) | |
(defn is-prime? | |
[x] |
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
if ([ "$LEIN_FAST_TRAMPOLINE" != "" ] || [ -r .lein-fast-trampoline ]) && | |
[ -r project.clj ]; then | |
INPUTS="$@ $(cat project.clj) $LEIN_VERSION $(cat "$LEIN_HOME/profiles.clj")" |
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 Player | |
(:gen-class)) | |
(def xDirs {1 "E" 0 "" -1 "W"}) | |
(def yDirs {1 "S" 0 "" -1 "N"}) | |
(def offsets {1 inc 0 identity -1 dec}) | |
(defn -main [& args] | |
(let [[lightX lightY initialTX initialTY] (repeatedly 4 read) | |
tX (atom initialTX) | |
tY (atom initialTY)] |
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 jitu-problem.core | |
(:require [clojure.math.numeric-tower :as math] | |
[clojure.set :as cset]) | |
(:gen-class)) | |
(defn divisible-by? | |
[x y] | |
(zero? (rem y x))) | |
(defn prime-candidates |
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
class Fixnum | |
def is_prime? | |
2.upto(self-1).none? do |y| | |
self%y==0 | |
end | |
end | |
def prime_factors | |
2.upto(self).select do |x| | |
self%x==0 && x.is_prime? |
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
var isPrime=function(x){ | |
for (var i = 2; i <= Math.sqrt(x); i++) { | |
if(x%i==0){return false;} | |
} | |
return true; | |
} | |
var primeFactors=function(x) { | |
var factors=[]; | |
for (var i = 2; i <= x; i++) { |
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
; first argument to list is always a function | |
(println "Hello World") | |
; + - * and / are functions! | |
(+ 2 3) | |
(- 2 3) | |
(* 3 4) | |
(/ 10 5) | |
; They can take multiple arguments |
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 CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |
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
table { | |
text-align: center; | |
} | |
td { | |
padding: 20px; | |
} |
OlderNewer