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 fold [vals, seed, next, return, error] | |
(if (< 0 (count vals)) | |
#(next | |
(first vals) | |
seed | |
(fn [result] | |
(fold (subvec vals 1) result next return error)) | |
error) | |
#(return seed))) |
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
(use 'clojure.walk) | |
(defmacro _>_ [& exprs] | |
(reduce | |
(fn [inner step] | |
(clojure.walk/postwalk-replace {'___ inner} step)) | |
(reverse exprs))) | |
(defn cat [lst, val, cont] #(cont (conj lst val))) |
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
;; feed macro | |
(use 'clojure.walk) | |
(defmacro _>_ [& exprs] | |
(reduce | |
(fn [inner step] | |
(clojure.walk/postwalk-replace {'___ inner} step)) | |
(reverse exprs))) | |
;; Protocol for dodo prototypes | |
(defprotocol DodoProtocol |
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
# Dodo code, imperative style | |
# --- | |
String s = "" | |
loop for (int n = 1; n < 100; ++.n) | |
{ | |
test | |
{ | |
n % 4 = 0: | |
continue. |
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
;; Dispatch message to object | |
(defmacro call* [obj, getter & args] | |
`(let [object# ~obj] | |
(((keyword '~getter) @(type object#)) object# ~@args))) | |
(defrecord Dodo [instance]) | |
(def DodoClass (new Dodo 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
# Imported Clojure functions | |
clojure('=', 2) -> eq | |
clojure('dec', 1) -> dec | |
clojure('conj', 2) -> conj | |
clojure('vector', 0) -> vector | |
clojure('count', 1) -> count | |
clojure('merge', 2) -> combine | |
clojure('first', 1) -> first | |
clojure('next', 1) -> rest | |
clojure('concat', 2) -> concat |
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 dodo*fork [coroutine, return] | |
(let [outcome (promise)] | |
(println "starting coroutine") | |
(future | |
(coroutine ; run in parallel | |
(fn [& args] (deliver outcome {:return args})) | |
(fn [e] (deliver outcome {:error e})))) | |
(println "returning blocking function") | |
(return | |
(fn wait [return, error] |
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
; I have this in my code | |
(defn fun [f, continuation] (-> f continuation)) ; pass f to continuation | |
; I want to change it to this | |
(defn fun [argc, f, continuation] | |
(continuation | |
(fn [& 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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct | |
{ | |
char* description; | |
} event; | |
typedef void (*fun)(); |
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
var a = {}; | |
a.foo = function() { | |
return "foo"; | |
} | |
a.bar = function() { | |
return "bar"; | |
} |
OlderNewer