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
;; 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
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__'): |
TL;DR* Here's what the license entails:
1. Anyone can copy, modify and distribute this software.
2. You have to include the license and copyright notice with each and every distribution.
3. You can use this software privately.
4. You can use this software for commercial purposes.
5. If you dare build your business solely from this code, you risk open-sourcing the whole code base.
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
#!/usr/bin/env python | |
import gym | |
import numpy as np | |
import tensorflow as tf | |
class PolicyGradientAgent(object): | |
def __init__(self, hparams, sess): |
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
""" | |
A perl Data.Dumper clone for Python | |
Author: [email protected] | |
2011-07-08 | |
""" | |
#!/bin/env python | |
import sys | |
from types import * |
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
#! /usr/bin/env python | |
''' | |
Simple example demonstrating how to take a screenshot | |
''' | |
import time | |
import sys | |
import os | |
import argparse | |
#OpenGL |
NewerOlder