[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] Hello, world? (#158

Joel VanderWerf

3/3/2008 5:35:00 AM

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

1 Answer

Bill Kelly

3/3/2008 9:25:00 AM

0


From: "Joel VanderWerf" <vjoel@path.berkeley.edu>
>
> 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 .... :D


Regards,

Bill