This file contains 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
MACHINE_RULEBOOK = DTMRulebook.new([ | |
TMRule.new(:delete_next_bit, '0', :increment_counter, 'X', :left), # cross out 0 from input | |
TMRule.new(:delete_next_bit, '1', :increment_counter, 'X', :left), # cross out 1 from input | |
TMRule.new(:delete_next_bit, '_', :clean_up, '_', :left), # clean up the tape | |
TMRule.new(:delete_next_bit, 'X', :delete_next_bit, 'X', :right), # scan right | |
TMRule.new(:delete_next_bit, 'Z', :delete_next_bit, 'Z', :right), # scan right | |
TMRule.new(:increment_counter, '1', :increment_counter, 'Z', :left), # increment counter, carry the 1 | |
TMRule.new(:increment_counter, 'Z', :delete_next_bit, '1', :right), # increment counter | |
TMRule.new(:increment_counter, '_', :delete_next_bit, '1', :right), # increment counter (overflowed) |
This file contains 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 ruby | |
require 'nokogiri' | |
def highlight(document) | |
document.xpath('descendant::*[self::programlisting or self::screen][attribute::language]').each do |element| | |
tokens_and_types = tokenize(element.content, element[:language]) | |
next_token, next_type = tokens_and_types.shift | |
element.xpath('descendant::text()').each do |text| |
This file contains 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
-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][ |
This file contains 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
>> IF = -> b { b } | |
=> #<Proc:0x007fb4e4049cc8 (lambda)> | |
>> LEFT = -> p { p[-> x { -> y { x } } ] } | |
=> #<Proc:0x007fb4e403d680 (lambda)> | |
>> RIGHT = -> p { p[-> x { -> y { y } } ] } | |
=> #<Proc:0x007fb4e4028ff0 (lambda)> | |
>> IS_EMPTY = LEFT |
This file contains 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
class Printable < Module | |
def initialize(string) | |
super() | |
define_method :print do | |
puts string | |
end | |
end | |
end | |
>> class A; include Printable.new('Hello'); end |
NewerOlder