Skip to content

Instantly share code, notes, and snippets.

(go (let [a (<! (async/map identity []))]
(println a)))
blocks instead of printing nil ?
@cark
cark / gist:7376645
Last active December 27, 2015 19:19 — forked from anonymous/gist:7376057
;; project.clj
(defproject bleh "0.0.1-SNAPSHOT"
:decription "bleh"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2024"]
[org.clojure/core.async "0.1.256.0-1bf8cf-alpha"]]
:plugins [[lein-cljsbuild "0.3.3"]]
:cljsbuild {:builds [{:source-paths ["src-cljs"]
:compiler {:output-to "main.js"
:optimizations :whitespace
app.core> (let [maybe (fn [val fun] (if (nil? val) nil (fun val)))]
[(-> nil (maybe inc)) (-> 1 (maybe inc))])
[nil 2]
@cark
cark / orc.hs
Created September 25, 2012 08:32
My take on the orc thingie
{-# LANGUAGE Rank2Types #-}
module Main where
import System.Random
import Control.Monad
import Control.Monad.State
import Data.List
data Player = Player { pHealth :: Int
, pAgility :: Int
, pStrength :: Int
(ns cara.type.core)
;(declare Nothing Just)
(defprotocol PDataType
(get-constructors [self]))
(defprotocol PConstructor
(get-datatype [self]))
insertPerson :: MonadState MyDb m => Person -> m (Fact Person)
insertPerson = insertRecord personRel
--fillit :: MonadState MyDb m => m ()
fillit = do
a <- insertPerson (Person "john")
b <- insertPerson (Person "paul")
return ()
-- if i leave the type declaraion of fillit commented, i get this error :
user> (defmacro bleh [body]
`(fn [{:keys [~'action]}]
~body))
#'user/bleh
user> ((bleh action) {:action 12})
12
@cark
cark / gist:3709981
Created September 12, 2012 21:14
one of two things
user> (defmacro as-doubled-pair [v]
`(let [v# (mapv (partial * 2) ~v)]
[v# v#]))
#'user/as-doubled-pair
user> (macroexpand (as-doubled-pair [1 2 3]))
[[2 4 6] [2 4 6]]
user> (defmacro as-doubled-pair2 [v]
(let [v (mapv (partial * 2) v)]
`(do [~v ~v])))
@cark
cark / gist:3709973
Created September 12, 2012 21:13
one of two things
user> (defmacro as-doubled-pair [v]
`(let [v# (mapv (partial * 2) ~v)]
[v# v#]))
#'user/as-doubled-pair
user> (macroexpand (as-doubled-pair [1 2 3]))
[[2 4 6] [2 4 6]]
user> (defmacro as-doubled-pair2 [v]
(let [v (mapv (partial * 2) v)]
`(do [~v ~v])))
@cark
cark / gist:3667614
Created September 7, 2012 16:34
state-m fetch-val bug and efficiency issue
;; the bug
(defn fetch-val
"Return a state-monad function that assumes the state to be a map and
returns the value corresponding to the given key. The state is not modified."
[key]
(domonad state-m
[s (fetch-state)]
(key s))) ;; only works for keyword keys