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
#include "Python.h" | |
static PyObject *simple_example(PyObject *self, PyObject *args) | |
{ | |
PyObject *x; | |
x = PyTuple_GetItem(args, 0); | |
PyObject *zero = PyInt_FromLong(0); | |
if (PyObject_RichCompareBool(x, zero, Py_EQ)) | |
{ | |
Py_DECREF(args); |
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
(defn wrap-foo [foo] | |
(reify | |
IFn | |
(invoke [this arg] | |
(.myMethod foo arg)) | |
IDeref | |
(deref [this] | |
foo))) |
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
(def adder | |
(fn [x] | |
(fn [y] | |
(+ x y)))) | |
(def add5 (adder 5)) | |
(add5 3) | |
=> 8 |
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
(gen-plan | |
[a (assert-entity {:foo 42}) | |
b (if pred? | |
(assert-entity {:a a :bar b}) | |
(no-op))] | |
b) |
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
(def philostate | |
(let [c (chan)] | |
(go (loop [state {:socrates :thinking | |
:plato :thinking | |
:hickey :thinking | |
:sussman :thinking | |
:stroustrup :thinking}] | |
(let [f (<! c) | |
new-state (f state)] |
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
(defn make-read-only [c] | |
(reify clojure.core.async.impl.protocols/ReadPort | |
(take! [port handler] | |
(clojure.core.async.impl.protocols/take! c handler)))) | |
(println (<!! (make-read-only (go 42)))) | |
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
(let [error-chan (chan)] | |
(go | |
(try | |
... | |
(catch Exception ex (>! error-chan ex))))) |
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 hoare.problem | |
(:require [clojure.core.async :refer :all])) | |
(defn fan-in | |
([ins] (fan-in (chan) ins)) | |
([c ins] | |
(go (while true | |
(let [[x] (alts! ins)] | |
(>! c x)))) | |
c)) |
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
(defn close-at-end [x file] | |
(if x | |
(cons (first x) (lazy-seq (close-at-end (next x) file))) | |
(do (.close file) | |
nil))) | |
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
(defn throttle-chan [input] | |
(let [throttle-chan (chan) | |
output-chan (chan)] | |
(go | |
(loop [throttle-msec nil] | |
(let [t-chan (when (= :disabled throttle-msec) | |
(timeout throttle-msec)) | |
[val c] (alt! [input throttle-chan])] | |
(if (= c throttle-chan) | |
(recur val) |