[QUIZ] 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(c); putchar('!*n');
   }

   a 'hell';
   b 'o, w';
   c 'orld';
}

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

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

  a 'hell';
  b 'o, w';
  c 'orld';
}

Hahaha....! Very nice <grin>

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

···

From: "Joel VanderWerf" <vjoel@path.berkeley.edu>