Re: Hello, world? (#158)

Going back to the original…

require ‘ostruct’

class BProgram
class Context < OpenStruct
def extrn(*)
end

 def putchar char
   print char.gsub(/\*n/) {"\n"}
 end

end

def self.run_in_ruby(&block)
new(&block).run
end

def initialize(&block)
@ctx = Context.new
instance_eval(&block)
end

def run
@ctx.instance_eval(&@main)
end

def main(&block)
@main = block
end

def method_missing(name, arg)
@ctx.send("#{name}=", arg)
end
end

BProgram.run_in_ruby {
main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar©; putchar(’!*n’);
}

a ‘hell’;
b ‘o, w’;
c ‘orld’;
}

From: “Joel VanderWerf” [email protected]

}
Hahaha…! Very nice

Nice use of OpenStruct…

Anyone know Mr. Kernighan well enough to send him this?
/me imagines he might get a kick out of it … :smiley:

Regards,

Bill