Skip to content

Instantly share code, notes, and snippets.

View jneen's full-sized avatar

Jeanine Adkisson jneen

View GitHub Profile
@jneen
jneen / lambda.clj
Last active August 29, 2015 13:59
core.typed and core.match failing to get along, with multimethods this time
(ns type-test.lambda
(require [clojure.core.typed :refer :all]
[clojure.core.match :refer [match]]))
(def-alias Expr "An expression"
(Rec [e]
(U '[(Value :var) Symbol]
'[(Value :lam) Symbol e]
'[(Value :app) e e])))
@jneen
jneen / lambda.hs
Last active August 29, 2015 13:59
what i'm trying to do
data Expr = Var Char
| Lam Char Expr
| App Expr Expr
hasFree :: Char -> Expr -> Bool
hasFree c (Var v) = c == v
hasFree c (Lam arg body) = c /= arg && hasFree c body
hasFree c (App func arg) = hasFree c func && hasFree c arg
@jneen
jneen / gist:d697fbb42399806f46cf
Created May 30, 2014 00:14
/usr/local/bin/wifi
#!/bin/bash
. /usr/lib/network/globals
. "$SUBR_DIR"/wpa
BIN_DIR="$(dirname "$0")"
PREFIX="${WIFI_PREFIX:-$BIN_DIR/..}"
LIB_DIR="$PREFIX/lib/wifi"
NOW="$(date +%s)"
@jneen
jneen / Dockerfile
Created September 5, 2014 18:17
Fig setup
FROM base/devel
RUN pacman --noconfirm -Sy jdk7-openjdk
RUN pacman --noconfirm -Sy socat
ENV LEIN_ROOT 1
RUN curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > /usr/local/bin/lein \
&& chmod +x /usr/local/bin/lein \
&& lein
@jneen
jneen / variant-multimethods.clj
Created November 22, 2014 20:55
Multimethods with variants
; it's a bit cumbersome to set up and there's the unfortunate need to ignore the tag
; in the individual methods, but this allows you to leave the interpretation of open
; variants, well, *open* for extension by multimethod.
; dispatch off the first argument, which will be the tag
(defmethod command-multi (fn [tag & data] tag))
; the first argument to the *method* is still the tag
(defmulti command-multi :print [_ val] (println val))
(defmulti command-multi :read [_ fname] (slurp fname))
(defmacro defvariant
[name [[tag & variant-binders] & other-binders] body]
`(defmethod ~name ~tag [[_# ~@variant-binders]
~@other-binders]
~body)
[name [tag & binders] body]
`(defmethod ~name ~tag [[_# ~@binders]] ~body))
; CompilerException java.lang.RuntimeException: Unable to resolve symbol: & in this context, compiling:(/tmp/form-init8620656005427572977.clj:1:1)
class Variant
class Caser
attr_reader :value
def initialize(variant)
@variant = variant
@invoked = false
end
def try_case(tag, &b)
if @variant.tag == tag
@jneen
jneen / cases.rb
Last active August 29, 2015 14:10
module Kernel
def cases(o, cases={})
o = [o] unless o.is_a? Array
raise "invalid" unless o[0].is_a? Keyword
selection = cases[o[0]] || cases[:else] || raise("non-exhaustive cases!")
selection.call(*cases[1..-1])
end
end
#!/usr/bin/env ruby
require 'gtk3'
fname = ARGV[0]
def window(&b)
w = Gtk::Window.new
proc { w.instance_eval(&b) }
end
@jneen
jneen / order.md
Created June 16, 2015 03:40
Tulip evaluation order (DRAFT)

In tulip, a function call is expressed as a sequence of expressions, with parentheses appearing freely:

f arg1 (arg2) (g arg3)

If a function receives fewer arguments than its arity, the result is a curried function expecting the remaining arguments. If it receives more, it consumes its arity and calls the return value with the rest. The order of evaluation for a function call is:

  • The function expression is evaluated
  • Each argument is evaluated