# FIXME: easier to use tasks + shallow binding constructs # some convenient words to fake objects/closures using variables and # lists # there are no true dynamic closures in pf for the simple reason that # it's hard to do correctly dynamically without a garbage collector. # the idea is this: object state is saved in a list. methods action on # an object will set the current state to a couple of global # variables, which will be restored back after we're done. please note # that this is not re-entrant, and is really only good for emulating # closures (objects with a single method 'doit'), not objects with # methods that call each other. # the syntax is: # context # (x y) context [[[ ]]] # : doit [[[ x @ y @ + x ! ]]] ; : enter-context >r unpack r> { execute ! } for-each ; : leave-context list:size >r { execute @ } for-each r> pack ; : link-context >r >r >r r { undef swap link-variable! } for-each # create variables r> ' find map # get list of XTs dup reverse swap # leave uses the reversed list ' enter-context r> link-curried ' leave-context r> link-curried ; "( list enter leave -- )\tCreate context load/save words for variables contained in list." doc : context read read link-context ;