(ns yourproject.yourns | |
(:require [clojure.java.io :as io])) | |
(defn delete-directory-recursive | |
"Recursively delete a directory." | |
[^java.io.File file] | |
;; when `file` is a directory, list its entries and call this | |
;; function with each entry. can't `recur` here as it's not a tail | |
;; position, sadly. could cause a stack overflow for many entries? | |
;; thanks to @nikolavojicic for the idea to use `run!` instead of |
import types | |
# Helpers | |
# ======= | |
def _obj(): | |
'''Dummy object''' | |
return lambda: None | |
_FILLER = _obj() |
#!/usr/bin/env python | |
import gym | |
import numpy as np | |
import tensorflow as tf | |
class PolicyGradientAgent(object): | |
def __init__(self, hparams, sess): |
(ns clj-spec-playground | |
(:require [clojure.string :as str] | |
[clojure.spec :as s] | |
[clojure.test.check.generators :as gen])) | |
;;; examples of clojure.spec being used like a gradual/dependently typed system. | |
(defn make-user | |
"Create a map of inputs after splitting name." | |
([name email] |
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 post also appears on lisper.in.
Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.
Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):
The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.
/* | |
* Copyright (c) 2013, Daniel Park | |
* All rights reserved. | |
* | |
* Permission to modify and redistribute this software is granted to | |
* anyone provided the above copyright notice, this condition and the | |
* following disclaimer are retained. | |
* | |
* This software is provided "as is", without and express or implied | |
* warranty. In no event shall the author be liable for damages arising |
#include <algorithm> | |
#include <vector> | |
#include <iterator> | |
#include <iostream> | |
template< class F, class X, class S > | |
constexpr X foldl( F&& f, X x, const S& s ) { | |
return std::accumulate ( | |
std::begin(s), std::end(s), |