Skip to content

Instantly share code, notes, and snippets.

@orchid-hybrid
orchid-hybrid / staterand.hs
Created July 10, 2015 14:48
State and Rand Commute
{-# LANGUAGE GeneralizedNewtypeDeriving, NoMonomorphismRestriction #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Random
newtype SR g s a = SR { unSR :: RandT g (State s) a }
deriving (Monad, Applicative, Functor)
runSR m = do
@orchid-hybrid
orchid-hybrid / gist:3edf0f16748a7c17a306
Created June 27, 2015 16:10
find word context script.js
System.import("github:contextscript-packages/text-extractor")
.then(({"default": extractText})=>{
var result = extractText({skipSelector:".ctxscript-container"});
var found = 0;
for(i in result.nodeMappings) {
var words = result.nodeMappings[i].node.nodeValue.split(" ");
for(j in words) {
if(words[j] == 'quantum') {
words[j] = "<span style='background-color: yellow';>"+words[j]+"</span>";
found++;
@orchid-hybrid
orchid-hybrid / R7RS modules problem.md
Last active April 10, 2018 16:45
R7RS modules problem

This is a problem I have with my minikanren implementation, it's split into a lot of files and I want to swap out the implementation of substitutions. Here is a cut down explanation of the problem:

Libraries that share a structure, and code based on them

I have a module peano which I implement another module four using.

;; peano.sld
(define-library (peano)
  (import (scheme base))
@orchid-hybrid
orchid-hybrid / diff.c
Last active July 23, 2021 08:41
Diff in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct list {
int x, y;
struct list *tail;
};
void main(void) {
@orchid-hybrid
orchid-hybrid / defunctionalize-nbe.scm
Created March 12, 2015 16:25
defunctionalize NbE
;; http://www.brics.dk/RS/01/23/BRICS-RS-01-23.pdf
(define (eval term env)
(match term
((symbol? s) (lookup s env))
(`(lambda (,(symbol? v)) ,body) (lambda (x) (eval body (cons (cons v x) env))))
(`(,m ,n) ((eval m env) (eval n env)))))
;; Defunctionalize ==>
@orchid-hybrid
orchid-hybrid / appendo.scm
Created March 5, 2015 22:31
silly appendo thing
(define (appendo p q)
(fresh (f rec base)
(== f `(lambda (a)
(lambda (b)
(fold ,rec ,base a))))
(eval-expo `((,f '(a b c)) '(u v)) '() '(a b c u v))
(eval-expo `((,f '(x y)) '(z)) '() '(x y z))
(eval-expo `((,f '()) '(o k !)) '() '(o k !))
@orchid-hybrid
orchid-hybrid / README.md
Last active August 29, 2015 14:16
Synthesizing functions as folds from test cases

Intro

The fold function captures a common recursion pattern

(define (fold kons knil list) ;; Uncurried version
  (if (null? list)
      knil
      (kons (car list) (fold kons knil (cdr list)))))
@orchid-hybrid
orchid-hybrid / cell.scm
Created March 3, 2015 18:58
making a mutable cell in scheme
> (define (make-cell value) (cons (lambda () value) (lambda (new-value) (set! value new-value))))
> (define cell (make-cell 'x))
> ((car cell))
x
> ((cdr cell) 'y)
> ((car cell))
y
@orchid-hybrid
orchid-hybrid / autokanren.scm
Last active August 29, 2015 14:15
autokanren.scm
;; This runs in veneer http://tca.github.io/veneer/editor.html
;; (developed inside veneer!)
;; Questions
;; A. How to shuffle all the recursive calls to the end, or just bubble unifications to the top?
;; B. How to optimize away simple things? seems very "one way" I do a tiny bit of optimization already..
;; it can generate kanren versions of four scheme functions (append, mem, rember, unwrap)
(define (nullo e)
@orchid-hybrid
orchid-hybrid / match.sld
Created January 26, 2015 11:50
Test case for loading library into sagittarius scheme
;; Test case for sagittarius scheme, using this library https://github.com/ilammy/sr
(load "sr/ck.sld")
(load "sr/ck/kernel.sld")
(load "sr/ck/lists.sld")
(load "sr/ck/maps.sld")
(define-library (match)
(import (rnrs)
(sr ck)