Skip to content

Instantly share code, notes, and snippets.

@joyofclojure
joyofclojure / gist:2304384
Created April 4, 2012 18:14 — forked from cgrand/gist:2302625
fair conjunction notes
Streams were equipped with plus and bind, I removed bind and added join and narrow.
I also added yield which returns the yielded substitution map for the stream (if any)
and step which advances teh computation (was: calling the thunk).
join, like plus, interleaves execution of its two streams. As soon as one yields, the
yielded value is used to narrow the search space of the other stream.
For any stream A, we have:
A = (plus (yield A) (step A))
@joyofclojure
joyofclojure / befaro.py
Created August 28, 2011 01:01
before and around in python
## {{{ http://code.activestate.com/recipes/577859/ (r1)
#!/usr/bin/env python
#
# Copyright (c) 2011 Jan Kaliszewski (zuo). All rights reserved.
# Licensed under the MIT License.
#
# Python 2.5+/3.x-compatibile.
#
# The newest version of this module should be downloadable from:
# https://github.com/zuo/Zuo-s-Recipes-and-Drafts/blob/master/auxmethods.py
;; from the great http://arcanesentiment.blogspot.com/2011/08/anaphoric-macro-defining-macro.html
(defmacro defanaphoric (name original &key settable)
"Define NAME as a macro like ORIGINAL, but binding IT to the result of the first argument.
If SETTABLE is true, IT will be a symbol-macro which can be set with SETF."
(let ((whole (gensym "WHOLE"))
(arglist (swank-backend:arglist original)))
`(defmacro ,name (&whole ,whole ,@arglist)
,(format nil "Like ~S, except binds the result of ~S to IT (via ~S) for the scope of the ~A.~A"
original
@joyofclojure
joyofclojure / mrisc.rb
Created July 7, 2011 12:31 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
split(leaf,_,leaf,leaf).
split(bst(L,A,R),X,L1,bst(L2,A,R)) :- A > X, split(L,X,L1,L2).
split(bst(L,A,R),X,bst(L,A,R1),R2) :- A < X, split(R,X,R1,R2).
insert(bst(L,A,R),X,bst(LX,A,R)) :- A > X, insert(L,X,LX).
insert(bst(L,A,R),X,bst(L,A,RX)) :- A < X, insert(R,X,RX).
insert(T,X,bst(L,X,R)) :- split(T,X,L,R).
@joyofclojure
joyofclojure / insert-peekr-poker.js
Created April 20, 2011 12:15
the start of a js console. initial version by oliver steele
function insertInlineConsole() {
try {InlineConsole.addConsole()}
catch (e) {
var timeout = arguments.callee.timeout;
if (!timeout)
timeout = arguments.callee.timeout = new Date().getTime() + 10*1000;
if (timeout > new Date().getTime())
setTimeout("insertInlineConsole()", 100);
return;
}