factor/library/tools/word-tools.factor

59 lines
1.5 KiB
Factor
Raw Normal View History

2006-03-25 01:06:52 -05:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: tools
USING: arrays definitions hashtables help tools io kernel
2006-09-16 17:11:55 -04:00
math namespaces prettyprint sequences strings styles words
generic completion ;
2005-03-10 17:57:22 -05:00
2006-09-16 17:11:55 -04:00
: word-outliner ( seq -- )
natural-sort [
[ synopsis ] keep dup [ see ] curry
write-outliner terpri
2006-09-16 17:11:55 -04:00
] each ;
: method-usage ( word generic -- methods )
tuck methods
[ second flatten memq? ] subset-with
[ first ] map
[ swap 2array ] map-with ;
: usage. ( word -- )
2006-09-16 17:11:55 -04:00
dup usage dup
[ generic? not ] subset
"Words calling " write pick pprint ":" print
word-outliner
"Methods calling " write over pprint ":" print
[ generic? ] subset
[ method-usage word-outliner ] each-with ;
2006-08-15 16:29:35 -04:00
: annotate ( word quot -- )
2005-08-23 15:50:32 -04:00
over >r >r dup word-def r> call r> swap define-compound ;
2005-04-01 12:42:14 -05:00
inline
2005-03-10 17:57:22 -05:00
2006-03-18 01:57:57 -05:00
: watch-msg ( word prefix -- ) write word-name print .s flush ;
2005-09-14 00:37:50 -04:00
2005-04-14 19:37:13 -04:00
: (watch) ( word def -- def )
2005-08-08 15:21:14 -04:00
[
2005-09-14 00:37:50 -04:00
swap literalize
dup , "===> Entering: " , \ watch-msg ,
swap %
, "===> Leaving: " , \ watch-msg ,
2005-08-25 15:27:38 -04:00
] [ ] make ;
2005-03-10 17:57:22 -05:00
2006-03-25 01:06:52 -05:00
: watch ( word -- ) [ (watch) ] annotate ;
2005-03-10 17:57:22 -05:00
2005-08-24 21:52:10 -04:00
: profile ( word -- )
2006-08-12 16:57:49 -04:00
[
swap [ global [ inc ] bind ] curry swap append
] annotate ;
: word-completion. ( pair -- )
first2 over summary completion>string swap write-object ;
2006-08-12 16:57:49 -04:00
: word-completions ( str words -- seq )
[ word-name ] swap completions ;
2006-08-12 16:57:49 -04:00
: apropos ( str -- )
all-words word-completions
[ word-completion. terpri ] each ;