module Endless def If(f) if(f) yield return EndlessIfTrue.new() else return EndlessIfFalse.new() end end def Unless(f) unless(f) yield return EndlessIfTrue.new() else return EndlessIfFalse.new() end end def Do() w = EndlessDo.new() callcc{|c| w.setCont(c)} yield return w end def Case(v) return EndlessCaseFalse.new(v) end end class EndlessIfTrue def Elsif(f) return EndlessIfTrue.new() end def Else() return EndlessIfTrue.new() end end class EndlessIfFalse def Elsif(f) if(f) yield return EndlessIfTrue.new() else return EndlessIfFalse.new() end end def Else() yield return EndlessIfTrue.new() end end class EndlessDo @cont = false def setCont(c) @cont = c end def While(f) if(f) @cont.call() end end def Until(f) unless(f) @cont.call() end end end class EndlessCaseTrue def When(f) return EndlessCaseTrue.new() end def Else() return EndlessCaseTrue.new() end end class EndlessCaseFalse @value = false def initialize(v) @value = v end def When(f) if (f.class() == Range && f.include?(@value)) yield return EndlessCaseTrue.new() elsif (f == @value) yield return EndlessCaseTrue.new() else return EndlessCaseFalse.new(@value) end end def Else() yield return EndlessCaseTrue.new() end end