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 / 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 / ski.clj
Created February 2, 2015 19:57
SKI in Swearjure
(def I #([%](+)))
(def K (-> (->> $ #(:- %)) (->> #() (-> [$]))))
(def S (-> (->> ((! $) (? $)) #() (-> [$])) (->> #() (-> [?]) #() (-> [!]))))
@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 / 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 / pvec.py
Last active August 29, 2015 14:23
Small (unoptimised) persistent vector in Python
## This is not an optimised persistent vector, just an implementation "straight
## off" http://hypirion.com/thesis.pdf. However, compared to Clojure's
## persistent vector, it is interesting in that this implementation
##
## - has O(n) runtime on iteration/reduce and map
## -> Clojure's implementations run in O(n log n) time
## - has submap and subiterators that runs in O(min(log n, m)) time,
## where m is the amount of elements to walk over
## -> Clojure doesn't support submap, although has subiterator indirectly
## through subvec, which runs in O(min(log n, m log n)) time
@hypirion
hypirion / text.txt
Created September 26, 2015 16:44
Result of building leiningen
jeannikl@Madonna of the Wasps  ~/leiningen   master ●  git rev-parse HEAD
d701275464c185f4f22be58450b1af4b94a79836
jeannikl@Madonna of the Wasps  ~/leiningen   master ●  cd leiningen-core
jeannikl@Madonna of the Wasps  ~/leiningen/leiningen-core   master  lein version
Leiningen 2.5.3 on Java 1.8.0_66-internal OpenJDK 64-Bit Server VM
jeannikl@Madonna of the Wasps  ~/leiningen/leiningen-core   master  lein bootstrap
Created /home/jeannikl/leiningen/leiningen-core/target/leiningen-core-2.6.0-SNAPSHOT.jar
Wrote /home/jeannikl/leiningen/leiningen-core/pom.xml
Installed jar and pom into local repo.
jeannikl@Madonna of the Wasps  ~/leiningen/leiningen-core   master ●  cd ..
@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)))
(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 / 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))
@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)))