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 m {:a ["a" [1 2 3]] :b ["b" [4 5 6]]}) | |
(for [[k v] m | |
[l xs] v] | |
[l xs]) | |
;;returns... | |
;;([\a nil] [1 2] [\b nil] [4 5]) | |
;;Wat? | |
;;Why are strings being destructured this way? | |
;;Expected |
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 heat | |
(:require [incanter [core :as i] [charts :as c]])) | |
(defn f [x y] (i/minus (i/sq x) (i/sq y))) | |
;;looks good | |
(i/view (c/heat-map f -10 10 -10 10)) | |
;;boxes for xyblock renderer are too small, | |
;;leaving gaps that show the grey background | |
;;behind, giving the appearance of "lines" | |
;;all over the plot. |
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
(defpackage :err-demo | |
(:use :common-lisp)) | |
(in-package :err-demo) | |
(defun str (x &rest xs) | |
(format nil "~{~a~}" (cons x xs))) | |
(defun show-excuse (excuse) | |
((print (str excuse " is no excuse for poor errors!")))) |
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
/* Generated by Clojure */ | |
package org.clojure; | |
import org.clojure.runtime.*; | |
public class Clojure{ | |
/* Generated by Clojure from the following Lisp: | |
(defn* f0 (NIL)) | |
*/ | |
static public class f0 extends AFn{public Object invoke(ThreadLocalData __tld) throws Exception | |
{return null;}} | |
/* Generated by Clojure from the following Lisp: |
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 spec-problem) | |
;;This is a smalle example of some circa clojure 1.7 code I found | |
;;that spec seemed to dislike when I was trying to port it. | |
;;It comes from the fn-fx library by way of the freactive.core | |
;;library fyi. | |
;;dumb function pre-defined... | |
(defn my-fn [x] (+ x 2)) | |
;;dumb macro that just builds an anonymous fn that |
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 incdebug.core | |
(:require [incanter [excel :as xls] [core :as i]] | |
[clojure.core.matrix.impl.dataset :as ds] | |
[clojure.core.matrix.protocols :as mp])) | |
;;this is what incanter is doing....we'll tease it apart | |
;;to debug. | |
#_(defn- read-sheet [rows-it header-keywords] | |
(let [colnames (incanter.excel.cells/read-line-values (first rows-it)) | |
rows (->> (rest rows-it) |
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 blah | |
(:require [clojure.core.async :as a])) | |
(defn error [x] {:error x}) | |
(defn success [x] {:success x}) | |
(defmacro maybe [expr] | |
`(->> (try (success ~expr) | |
(catch ~'Exception e# (error e#))))) |
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
;;So for my incoming API boundary, I only would retain keys defined in | |
;;spec after receiving data from client (to wholesale limit potentially | |
;;dangerous crafting of json/edn payload). | |
;;Likewise, at my outgoing boundary, I would similarly only retain keys | |
;;defined in spec (sending absolute minimum data necessary). | |
(ns incoming | |
(:require [clojure.spec.alpha :as s])) |
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
;;util function to help with bindings | |
(defun partition (n l) | |
(do ((remaining l (setf remaining (subseq remaining 2))) | |
(acc (list))) | |
((null remaining) (nreverse acc)) | |
(let ((nxt (subseq remaining 0 2))) | |
(if (= (length nxt) n) | |
(push nxt acc) | |
(setf remaining nil))))) | |
;;a dumb struct to wrap a list. solely for custom |
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 picking | |
(:require [clojure.pprint :as pprint])) | |
;original implementation from reddit. | |
(defn pick-best? [pred possible-positions] | |
(let [ps (mapv #(when (pred %) %) possible-positions)] | |
(or (second ps) | |
(first ps) | |
(nth ps 2)))) |