> Lett Luke Graham <spoooq / gmail.com>
> Aihe: can anyone verify this code as correct?
> 
>  class Object
>     def choices(choicelist)
> 	if (!Class.class_variables.include? "@@cont")
> 		@@cont = []
> 	end

You can use '@@cont ||= []'.

> 	choicelist.each { |choice|
> 		callcc { |cc|
> 			@@cont << cc
> 			return choice
> 		}
> 	}
> 	nil
>   end

Continuation returns after the block, either with the value of the
block or the parameter to #call, and it stores its execution context. 
Here you're returning in the middle of a loop, so I'm thinking each
#call will cause the remaining 'choicelist' to be iterated over again,
so the actual return value is going to be 'choicelist'.

>   def condition(cond)
>     return if (self.class == NilClass?)
>     @@cont.pop.call if !cond.call
>   end
>  end

You're attempting to loop until the condition is true? If I'm
understanding correctly you're trying to find the first values that 
fill all the conditions set forth?

>   class NilClass?
>    def method_missing(methId, *args)
>       return false
>    end
>  end
> 
> 
>  foo = choices(1..100)
>  bar = choices(1..100) 

choices() returns nil, no?

>  condition(lambda{foo == (bar * 3)})
>  condition(lambda{bar > 10})
>  condition(lambda{(bar % 2) == 0})
>  puts foo
>  puts bar
>
> Thanks for your help.

What are you trying to do, exactly? I'm sure there's an easier way if
you just want to compose conditionals like this; or are you trying to
get a handle on how callcc works? In the former case, you'd probably 
want to try something with blocks instead... callcc is really just a
glorified goto.

E