require 'sloop' Account = sloop { self.balance = 0 def_deposit { |v| self.balance += v } def_withdraw { |v| self.balance -= v } def_inspect { "#(an account with $#{balance})" } } my_account = Account.clone puts my_account.inspect my_account.deposit 1000 puts my_account.inspect puts require 'spawn' adder = spawn { sum = 0 loop { recieve { |sender, msg, *args| case msg when :add then sum += args.first when :result then sender.reply sum end } } } 10.times { spawn { |process| adder.send :add, rand(10) } } p adder.syncmsg(:result) puts require 'solve' def parent?(a, b) Solve.forany({"David" => "John", "Jim" => "David", "Steve" => "Jim", "Nathan" => "Steve"}) do |child, father| (a == child) & (b == father) end end def parent?(a, b) ((a == "David") & (b == "John")) | ((a == "Jim") & (b == "David")) | ((a == "Steve") & (b == "Jim")) | ((a == "Nathan") & (b == "Steve")) end def anchestor?(a, b) z = Solve::Variable.new parent?(a, b) | parent?(a, z) & Then.do { anchestor?(z, b) } end child = Solve::Variable.new(:child) anchestor = Solve::Variable.new(:anchestor) solve((child == "Nathan") & anchestor?(child, anchestor)) { |r| p r }