# misc small utility words # some misc utility things # these need polywords, but not intcomp : 2dup over over ; : nip swap drop ; : dec 1 - ; : inc 1 + ; : zero? 0 = ; : null? null = ; : 2drop drop drop ; : 3drop drop drop drop ; : undef? type [read] undef scalar:= ; # : inplace # ; "( var xt -- )\tPerform inplace operation." doc : *! >r r @ * r> ! ; : ndrop for drop next ; : ndup for dup next ; : stack () swapdata ; : dropall stack drop ; : rdropall () postpone literal postpone swapreturn postpone drop ; immediate : .n 10 emit ; : .t 9 emit ; : .s 32 emit ; : .bool if "true" else "false" then print ; : cr .n ;; : tab .t ;; : i* # fixed point multiply postpone fixedpoint postpone >r postpone * postpone r> postpone << ; immediate "( a b -- a*b)\tFixed point multiply. Uses '*' and '<<'." doc : normal 2normal drop ; "( -- f)\tReturn a float drawn from a normal distribution with stdev = 1." doc : 3normal 2normal normal ; : trace 1 >trace execute 0 >trace .n .n ; "( xt -- )\tExecute xt with trace on." doc # redefining (augmenting) : old xt>ct execute ; immediate # compile the old word : new: read dup find swap link-word ] ; # redefine : default-constant read try find 2drop # if defined, leave it alone recover drop link-constant # else define constant endtry ; : case r> swap for follow next @ execute ; "( n -- )\tPass control to nth xt." doc : forever here lit, hole, ! postpone >r ; immediate # get controlling object of does> word : <'> xt>body @ ; : [super] postpone literal postpone @ ; immediate # repeat something n times, xt is executed with ( ..stuff.. ) : times # ( ..stuff.. xt n -- ) dup if 1 - >r >r r execute r> r> pass times then 2drop ; # math 1. atan 4. * constant pi : >rad [ pi 180. / ]L * ; # terminal : rst "reset" system drop ;