Version 1 of Accumulator Generator

Updated 2009-12-27 18:16:28 by pmarin

The Accumulator Generator is a ploblem used by Paul Graham to compare the relative power programming languages.

The Problem

package require TclOO
namespace import oo::*

proc foo n {
        set obj [object new]        
        objdefine $obj method init {_n} {my variable n; set n $_n}
        objdefine $obj method acc i {my variable n; incr n $i}
        $obj init $n
        list ::apply [list i [subst -novariables {[set obj] acc $i}]]
}
proc destroy_acc acc {
        [lindex $acc 1 1 0] destroy
}