factor/library/tools/word-tools.factor

44 lines
1.2 KiB
Factor
Raw Normal View History

! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: words
USING: generic inspector lists kernel namespaces
prettyprint io strings sequences math hashtables parser ;
2004-07-16 02:26:21 -04:00
: vocab-apropos ( substring vocab -- list )
2004-07-16 02:26:21 -04:00
#! Push a list of all words in a vocabulary whose names
#! contain a string.
2005-07-31 23:38:33 -04:00
words [ word-name subseq? ] subset-with ;
2004-07-16 02:26:21 -04:00
: vocab-apropos. ( substring vocab -- )
2004-07-16 02:26:21 -04:00
#! List all words in a vocabulary that contain a string.
tuck vocab-apropos dup [
2004-07-16 02:26:21 -04:00
"IN: " write swap print [.]
] [
2drop
] ifte ;
: apropos. ( substring -- )
2004-07-16 02:26:21 -04:00
#! List all words that contain a string.
vocabs [ vocab-apropos. ] each-with ;
2004-07-16 02:26:21 -04:00
: word-file ( word -- file )
"file" word-prop dup [
2005-05-18 16:26:22 -04:00
"resource:/" ?head [
resource-path swap path+
] when
] when ;
: reload ( word -- )
#! Reload the source file the word originated from.
2005-02-14 21:58:07 -05:00
word-file run-file ;
2005-04-10 18:58:30 -04:00
: implementors ( class -- list )
#! Find a list of generics that implement a method
#! specializing on this class.
[
"methods" word-prop [ dupd hash ] [ f ] ifte*
2005-04-22 00:22:36 -04:00
] word-subset nip ;
2005-04-10 18:58:30 -04:00
: classes ( -- list )
[ metaclass ] word-subset ;