[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accumulator



On Thu, 23 May 2002, Avi Bryant wrote:

> def compute_price
>   get_base_price() {|price|
>     if price > tax_threshold
>       get_tax(price) {|tax|
>          price += tax
>       }
>     end
>     do_something_with(price)
>   }
> end

Ack, that doesn't work - can you tell I'm more used to call/cc than to
CPS?

def compute_price
   get_base_price() {|price|
    if price > tax_threshold
      get_tax(price) {|tax|
        price += tax
	do_something_with(price)}
    else
       do_something_with(price)
    end}
end

And now can someone who's more used to CPS tell me how the above would
normally be expressed without duplicating the shared do_something_with
continuation?  Or am I just being muddled?

Avi