# some CAT inspired higher order functions. (when i say CAT, i mean # my pet language, which is largely the same as Joy by Manfred von # Thun: http://www.latrobe.edu.au/philosophy/phimvt/joy.html ) # the words '{' and '}' are used to create quoted programs in the # sense of CAT. they can only be used in compiled code. # one of the big critiques of forth is that it is 'almost # functional'. in low level languages there are some constructs like # if ... else ... then, which are implemented as macros for reasons of # efficiency. however, it is possible to define some equivalent higher # order functions to fulfil the same role, and to promote the writing # of 'cleaner' programs. (adhering more to the CAT ideal of a # functional programming language based on composition of functions). : choose >r >r if rswap then rdrop r> ; "( ? item-true item-false -- item )\tReturen item based on flag." doc : ifte choose execute ;; "( ? xt-true xt-false -- )\tExecute branch based on flag." doc : duck >r execute r> ; "( xt thing -- thing )\tRun xt saving/restoring thing." doc # NOTE: in order to get full benefit of this, quoted programs need to # be tail recursive. until i get to rewriting the VM, this is not # always possible.