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 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 reader-test.core | |
(:gen-class)) | |
'[(= | |
(Var 2 a) | |
(ListConstant | |
[(StringConstant | |
"ab" | |
(Character 1 2 () []) | |
) |
This file contains 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
;; ___ _ _ ___ | |
;; / __| |_ __ _ _ __| |_ ___ _ _ ( _ ) | |
;; | (__| ' \/ _` | '_ \ _/ -_) '_| / _ \ | |
;; \___|_||_\__,_| .__/\__\___|_| \___/ | |
;; |_| | |
;; This is a challenging chapter because it's not | |
;; clear at the start where it's going. I figured it | |
;; out by reading it and writing about it several |
This file contains 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
;; https://stackoverflow.com/questions/11409140/stumped-with-functional-breadth-first-tree-traversal-in-clojure | |
(def tree [1 [2 [4] [5]] [3 [6]]]) | |
(defn bfs | |
[tree] | |
(loop [ret [] | |
queue (conj [] tree)] | |
(if (seq queue) | |
(let [[node & children] (first queue)] |
This file contains 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
;; metacircular evaluator from sicp | |
(define apply-in-underlying-scheme apply) | |
(define (list-of-values exps env) | |
(if (no-operands? exps) | |
'() | |
(cons (eval (first-operand exps) env) | |
(list-of-values (rest-operands exps) env)))) | |
(define (eval-if exp env) | |
(if (true? (eval (if-predicate exp) env)) |
This file contains 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 types | |
# Helpers | |
# ======= | |
def _obj(): | |
'''Dummy object''' | |
return lambda: None | |
_FILLER = _obj() |
This file contains 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
#+TODO: TODO BACKLOGGED(!) SCHEDULED(!) STARTED(!) SUSPENDED(!) BLOCKED(!) DELEGATED(!) ABANDONED(!) DONE | |
# FOR DOCUMENTATION OF THESE OPTIONS, see 12.2, Export Settings of the Org Info Manual | |
#+OPTIONS: ':t # export smart quotes | |
#+OPTIONS: *:t # export emphasized text | |
#+OPTIONS: -:t # conversion of special strings | |
#+OPTIONS: ::t # fixed-width sections | |
#+OPTIONS: <:t # time/date active/inactive stamps | |
#+OPTIONS: \n:nil # preserve line breaks |
This file contains 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 sys | |
import ast | |
origin_import = __import__ | |
AST = {} | |
def custom_import(name, *args, **kwargs): | |
module = origin_import(name, *args, **kwargs) | |
if not hasattr(module, '__file__'): |
This file contains 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 torch | |
import toolz | |
def kalman (b, # # rows, cols, in Z; # rows in z | |
n, # # rows, cols, in P; # rows in x | |
Z, # b x b observation covariance | |
x, # n x 1, current state | |
P, # n x n, current covariance | |
A, # b x n, current observation partials |
NewerOlder