Skip to content

Instantly share code, notes, and snippets.

@igorw
igorw / vm.php
Last active August 29, 2015 14:03
My stack machine from cute little interpreters at dpc14.
<?hh
// examples:
//
// ~$ echo '1 jnz(:start) :foo call(:bar) ret :bar 42 print ret :start call(:foo)' | hhvm vm.php
// float(42)
//
// ~$ echo '3 :loop 1 - print jnz(:loop)' | hhvm vm.php
// float(2)
// float(1)
@igorw
igorw / concat.php
Last active August 29, 2015 14:01
Playing with concatenative programming.
<?hh
// concatenative programming
// based on this paper:
// http://mitarbeiter.hs-heilbronn.de/~herzberg/Publications/ICSOFT.2009.pdf
namespace igorw\concat;
class OpenQuotation {
var $words;
@igorw
igorw / mutation.php
Created May 5, 2014 18:28
Self-modifying quasi-quine. Try running it, then piping the output into PHP. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again. Then piping that output into PHP again.
<?php
$data = <<<'DATA'
$program = <<<PROGRAM
<?php
\$data = <<<'DATA'\n$data\nDATA;
$data
PROGRAM;
$n = 0;
if ($n >= 5) {
@igorw
igorw / moar-ukanren.php
Created April 29, 2014 08:49
More fun with PHPµKanren!
<?php
require 'vendor/autoload.php';
use MicroKanren\Core as µ;
function membero($x, $l) {
return µ\disjPlus(
µ\fresh(function ($tail) use ($x, $l) {
return µ\eq($l, µ\cons($x, $tail));
<?php
require 'vendor/autoload.php';
use MicroKanren\Core as µ;
$goal = µ\callFresh(function ($q) {
return µ\disj(
µ\eq($q, 'foo'),
µ\eq($q, 'lulz')
@igorw
igorw / pq.clj
Created April 22, 2014 08:29
pq system from Douglas Hofstadter's Gödel, Escher, Bach. Implemented in core.logic.
(ns pq.core
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
; pq system
; formal string rewriting system representing addition
; from chapter II of Gödel, Escher, Bach by Douglas Hofstadter
(defn axiomo
[a b c]
@igorw
igorw / mu.clj
Created April 17, 2014 21:04
MU puzzle from Douglas Hofstadter's Gödel, Escher, Bach. Implemented in core.logic.
(ns mu.core
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn i
[in out]
(conde [(== in [:I])
(== out [:I :U])]
[(fresh [in-head out-head]
(== in-head out-head)
git init a && cd a && touch hi && git add . && git commit -am 'hi a' && cd ..
git clone --bare a b
git clone b c && cd c && touch hi-from-c && git add . && git commit -am 'hi from c' && git push && cd ..
cd a && git remote add origin ../b && git pull origin master && ls && git log && cd ..
(ns coins.core
(:refer-clojure :exclude [==])
(:use clojure.core.logic)
(:require [clojure.core.logic.fd :as fd]))
; find possible coin configurations
;
; $coins = [2, 3, 5, 7, 9];
; $a + ($b * pow($c, 2)) + pow($d, 3) - $e
(ns turel.core
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn not-membero
[x l]
(conde [(emptyo l)]
[(fresh [head tail]
(conso head tail l)
(!= head x)