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 / 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