Skip to content

Instantly share code, notes, and snippets.

import Data.Trie as T (Trie, empty, insert, member)
import Data.Map as M (Map, fromList, (!))
import Data.Set as S (Set, fromList, toList, delete, intersection)
import Data.Array.IArray as A
import Data.List
import Data.Ord
import Data.Ix
import Control.Monad
import Control.Parallel.Strategies
import System.IO.UTF8 as UTF8 (readFile)
(defvar *registry* (make-hash-table))
(defmacro define-statement-abstractor ((name &rest parameters) &body definitions)
`(eval-when (:compile-toplevel :load-toplevel :execute)
(setf (gethash ',name *registry*)
(list ',parameters
',(cdr (assoc :rules definitions))
',(cdr (or (assoc :whole definitions)
'(:whole (expr) expr)))))))
@apskii
apskii / monad.lisp
Last active December 22, 2015 14:39
(defstruct monad lift bind)
(defconstant +id-monad+
(make-monad
:lift #'identity
:bind (lambda (x f) (funcall f x))))
(defconstant +list-monad+
(make-monad
:lift #'list
(define-statement-abstractor (monad m)
(:rules
(val ((name expr) rest) `(let ((,name ,expr)) ,rest))
(get ((name expr) rest) `($ (monad-bind m) ,expr (fn (,name) ,rest)))
(:else (expr rest)
(let ((arg (gensym)))
(if rest
`($ (monad-bind m) ,expr
(fn (,arg) (declare (ignore ,arg)) ,rest))
expr))))
(defmacro monadic (&body statements)
`(let ((m *monad*))
(statements-of (monad m) ,@statements)))
(defun monad-example (ma mb)
(monadic
(get x ma)
(get y mb)
(val z (+ x y))
(ret (list x y z))))
(defmacro $ (&rest rest) `(funcall ,@rest))
(defstruct builder
combine
bind
return
return-from
yield
yield-from
using
package apsk.jpatmat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Function;
public class Entry {
// Simple Arithmetic Language
// utils.js
(function ($,sr) {
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
#!/usr/bin/env python3.4
import sys
import asyncio as aio
import concurrent.futures as cf
from getpass import getpass
from itertools import takewhile
import github3
import scala.collection._
class Bag[E] private (val items: Map[E, Int]) {
def isEmpty = items.isEmpty
def view = items.keys.view
def -(item: E) = new Bag[E](items(item) match {
case 1 => items - item
case n => items.updated(item, n - 1)
})
}