1~~~ 2'/Users/yoneda/retro/package/File.retro d:create data 3~~~ 4 5`file:load` includes a file and registers the file name into the dictionary. 6With it, the words in the file become viewable. 7 8Put file name into dictionary. 9 10~~~ 11{{ 12 :load:try (s-) dup file:exists? 13 [ include ] [ 'file__ s:prepend '__not_found s:append s:abort ] choose ; 14---reveal--- 15 :file:load (s-) dup d:lookup n:-zero? 16 [ 'file:load_:__ s:prepend '__already_loaded s:append s:abort ] 17 [ dup d:create data load:try ] choose ; 18 :file:load.retro (s-) '.retro s:append file:load ; 19}} 20~~~ 21 22Given a word, find the file in which the word was defined. 23Works imperfectly, but useful. 24 25~~~ 26 RETRO (defined_in_Init.retro) 'source/retro.forth s:append 27'SOURCE/RETRO s:const 28{{ 29 'FileName var 'FileID var 'Size var 'Word var 'Line var 30 :word (s-) #0 !Word dup d:lookup dup n:zero? 31 [ drop 'word_%s_not_found s:format s:abort ] [ !Word drop ] choose ; 32 :word-name (-a) @Word d:name ; 33 :retro? (a-f) d:name '.retro s:ends-with? ; 34 :search (a-a)_a='.retro'_found__or__0=not 35 [ fetch dup retro? not over #0 -eq? and ] while ; 36 :file (-)_assumes_@Word_is_not_zero 37 @Word d:link search dup n:zero? 38 [ drop SOURCE/RETRO ] [ d:name ] choose !FileName ; 39 :count-lines (-) #1 !Line 40 (open @FileName file:open-for-reading !FileID !Size ) 41 [ @FileID file:read-line word-name s:contains-string? 42 dup [ &Line v:inc ] -if not (-eof? @FileID file:tell @Size lt? ) and ] 43 while (close @FileID file:close ) ; 44 :pre (a-f) word file ; 45---reveal--- 46 :d:file (s-) pre @FileName s:put nl ; 47 :d:view (s-) pre count-lines @FileName @Line 48 'ne_--read-only_+%n_%s s:format unix:system ; 49 :d:edit (s-) pre count-lines @FileName @Line 50 'ne_+%n_%s s:format unix:system ; 51}} 52~~~ 53 54## BUGS 55 56The search fails when a word has been defined in a file that was 57not `file:load`ed but `include`d , or 58when the word has been typed in from the console. 59In particular, words in files `include`d before `Load.retro` 60will not be found correctly.. 61 62Also, words defined in Rx such as 63`push`, `pop`, `drop`, `swap`, and `dup` are not found. 64 65