This file contains hidden or 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
| 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) |
This file contains hidden or 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
| (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))))))) |
This file contains hidden or 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
| (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 |
This file contains hidden or 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
| (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)))) |
This file contains hidden or 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
| (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)))) |
This file contains hidden or 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
| (defmacro $ (&rest rest) `(funcall ,@rest)) | |
| (defstruct builder | |
| combine | |
| bind | |
| return | |
| return-from | |
| yield | |
| yield-from | |
| using |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| // 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); |
This file contains hidden or 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
| #!/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 |
This file contains hidden or 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
| 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) | |
| }) | |
| } |