Skip to content

Instantly share code, notes, and snippets.

View hypirion's full-sized avatar
👋

Jean Niklas L'orange hypirion

👋
View GitHub Profile
@hypirion
hypirion / lein.bat
Created February 24, 2015 11:41
Leiningen bat for post 2.5.1 syndromes (pre 2.5.2)
@echo off
setLocal EnableExtensions EnableDelayedExpansion
set LEIN_VERSION=2.5.1
if "%LEIN_VERSION:~-9%" == "-SNAPSHOT" (
set SNAPSHOT=YES
) else (
set SNAPSHOT=NO
@hypirion
hypirion / ski.clj
Created February 3, 2015 16:17
What's wrong with my Y Combinator?
;; I'm hitting my head against a wall trying to implement the Y Combinator in SKI in Clojure
;; Anyone with experience implementing it, or is able to detect what's wrong here?
(defn I [x] x)
#_=> #'user/I
(def K (fn [x] (fn [y] x)))
#_=> #'user/K
(def S (fn [x] (fn [y] (fn [z] ((x z)(y z))))))
#_=> #'user/S
;; The culprit:
@hypirion
hypirion / ski.clj
Created February 2, 2015 19:57
SKI in Swearjure
(def I #([%](+)))
(def K (-> (->> $ #(:- %)) (->> #() (-> [$]))))
(def S (-> (->> ((! $) (? $)) #() (-> [$])) (->> #() (-> [?]) #() (-> [!]))))
@hypirion
hypirion / triemap.rs
Created January 11, 2015 17:25
TrieMap with focusing capabilities in Rust 1.0 alpha
// Small (incomplete) implementation of a trie map with focusing capabilities.
// Nice for (exact) autocomplete matching. Example usage in main function at the top.
#![feature(box_syntax)]
#![allow(unstable)]
use std::mem;
use std::collections::dlist::DList;
use std::cmp::Ordering::{Less, Equal, Greater};
fn main() {
@hypirion
hypirion / core.clj
Created June 16, 2013 23:08
(Naive) logic program which finds a meeting schedule where every attendee can attend every meeting without conflicts.
(ns meeting-times.core
(:refer-clojure :exclude [==])
(:use clojure.core.logic
clojure.core.logic.protocols)
(:require [clojure.set :as set])
(:gen-class))
(defn sublists [list]
(take-while (comp pos? dec count)
(iterate rest list)))
@hypirion
hypirion / merge_example.clj
Created December 29, 2012 04:33
meta-merge in fairbrook.
(ns merge-example
(:require [clojure.set :as set]
[fairbrook.path :as path]
[fairbrook.rule :as rule]
[fairbrook.meta :as meta]
[fairbrook.util :as u :refer [<<-]]))
(defn- displace? [obj]
(-> obj meta :displace))
(defmacro defsignal [name bindings out-path & body]
(let [state (gensym "state")]
`(defn ~name [~state]
(let [~@(mapcat (fn [[a b]] [a `(get-in ~state ~b)])
(partition 2 bindings))]
(assoc-in ~state ~out-path (do ~@body))))))
@hypirion
hypirion / test.clj
Created August 9, 2012 11:55 — forked from rf/test.clj
(defn lookup
"Lookup a variable in the model. Respects inversion of the variable if it is
specified with a - symbol. Returns nil if the variable is unset."
[[first-char :as var] model]
(if (= first-char \-) ; If the first character is '-'
(if-let [[_ val] (find model (subs var 1))] ; test for existence
(not val) ; invert value if exists
nil) ; otherwise return nil
(get model v)))