func within an object
[1/4] from: grantwparks::yahoo::com at: 21-Dec-2000 20:30
I defined a func within an object, and unlike a func at the global context,
help will only tell me it's a path. Is there a way to get this help?
TIA
[2/4] from: al:bri:xtra at: 22-Dec-2000 16:52
> I defined a func within an object, and unlike a func at the global
context, help will only tell me it's a path. Is there a way to get this
help?
Yes, by redefining the 'help word to deal with this. This version of 'help
was written by:
Author: "Nenad Rakocevic"
Email: [dockimbel--free--fr]
and slightly rewritten by me to suit me.
BTW, Nenad if you're reading this, could we have a URL where this version of
help is at?
I hope that helps!
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
-><-
-- Attached file included as plaintext by Listar --
-- File: help.r
Rebol [
Title: "Extended Help"
Author: "Nenad Rakocevic"
Email: [dockimbel--free--fr]
Date: 09-Oct-2000
File: %help.r
Home: http://members.nbci.com/AndrewMartin/Rebol/Patches/
Name: 'Extended-Help
Patch: 'Extended-Help
Version: 1.0.1
History: [
1.0.1 09-Oct-2000
{ - native! and action! values were wrongly reported in WORDS instead
of FUNCTIONS. Fixed.
- Unset! datatype wasn't handled correctly in 'list-obj. Fixed with
'get/any instead of 'get.}
1.0.0 06-Oct-2000
{ First release !}
]
Purpose: {Extension of the 'help command for better object! support}
Comment: {
Try this on the command line:
a: make object! [
c: func ["print a message"][ print "I'm c in a!" ]
b: make object! [
d: func ["read a web page" link [url!]][ print read link ]
e: 5
]
]
help a
help a/c
help a/b
help a/b/d
help a/b/e
you can also try browsing the system object with :
help system ; then try help on the given words, sub-objects and functions
Enjoy it !
}
Category: 'general
]
help: func [
"Prints information about words and values."
'word [any-type!]
/local value args item name refmode types attrs rtype in-obj saved-value saved-word list-obj
][
if unset? get/any 'word [
print trim/auto {
^-^-^-^-The help function provides a simple way to get
^-^-^-^-information about words and values. To use it
^-^-^-^-supply a word or value as its argument:
^-^-^-^-
^-^-^-^-^-help insert
^-^-^-^-^-help find
^-^-^-^-To view all words that match a pattern:
^-^-^-^-^-help "path"
^-^-^-^-^-help to-
^-^-^-^-To view all words of a specified datatype:
^-^-^-^-^-help native!
^-^-^-^-^-help datatype!
^-^-^-^-There is also word completion from the command
^-^-^-^-line. Type a few chars and press TAB to complete
^-^-^-^-the word. If nothing happens, there is more than
^-^-^-^-one word that matches. Enough chars are needed
^-^-^-^-to uniquely identify the word.
^-^-^-^-Other useful functions:
^-^-^-^-^-about - for general info
^-^-^-^-^-usage - for the command line arguments
^-^-^-^-^-license - for the terms of user license
^-^-^-^-^-source func - print source for given function
^-^-^-^-^-upgrade - updates your copy of REBOL
^-^-^-^-
^-^-^-^-For more information, see the user guides.
^-^-^-}
exit
]
if all [word? :word not value? :word] [word: mold :word]
if any [string? :word all [word? :word datatype? get :word]] [
types: copy []
attrs: second system/words
foreach item first system/words [
value: copy " "
change value :item
if all [not unset? first attrs
any [
all [string? :word find value word]
all [not string? :word datatype? get :word (get :word) = type? first attrs]
]
] [
repend value [" (" type? first attrs ")"]
append types value
]
attrs: next attrs
]
sort types
if not empty? types [
print "Found these words:"
foreach item types [print [tab item]]
exit
]
print ["No information on" word "(word has no value)"]
exit
]
type-name: func [value] [
value: mold type? :value
clear back tail value
join either find "aeiou" first value ["an "] ["a "] value
]
list-obj: func [obj [object!] /local list-w list-so list-f size-w size-f item fun l-fun
desc type][
print ["OBJECT:" :word]
list-w: copy []
list-so: copy []
list-f: copy []
size-w: size-f: 0
foreach item sort next first obj [
fun: :item
either any-function? get/any in obj :fun [
type: function!
][
type: type? get/any in obj :fun
]
l-fun: length? mold fun
switch/default mold type [
"object!" [append list-so fun]
"function!" [
append list-f fun
if l-fun > size-f [size-f: l-fun]
]
][
append list-w fun
if l-fun > size-w [size-w: l-fun]
]
]
print "^/WORDS:"
either empty? list-w [
print "^-(none)"
][
foreach fun list-w [
prin [tab mold fun ]
repeat item size-w - (length? mold fun) [prin " "]
print rejoin [tab "-- (Type: " type? get/any in obj :fun ")"]
]
]
print "^/SUB-OBJECTS:"
either empty? list-so [
print "^-(none)"
][
foreach fun list-so [print [tab mold fun ]]
]
print "^/FUNCTIONS:"
either empty? list-f [
print "^-(none)"
][
foreach fun list-f [
prin [tab mold fun ]
repeat item size-f - (length? mold fun) [prin " "]
either string? desc: pick third get/any in obj :fun 1 [
print rejoin [tab "-- " desc]
][
print "^--- (undocumented)"
]
]
]
]
either equal? type? :word path! [
saved-word: :word
value: to-lit-path :word
in-obj: append copy [get in] reduce [copy/part value (length? value) - 1 word: to-lit-word
last value]
if error? try [saved-value: value: do in-obj][
print "Error: this is not a valid path !"
exit
]
if equal? type? :value object! [
list-obj :value
exit
]
][
in-obj: none
if not word? :word [
print [mold :word "is" type-name :word]
exit
]
value: get word
if object? :value [
list-obj value
exit
]
]
if not any-function? :value [
print [uppercase mold word "is" type-name :value "of value:" mold :value]
exit
]
args: third :value
prin "USAGE:^/^-"
if not op? :value [prin append uppercase mold word " "]
while [not tail? args] [
item: first args
if :item = /local [break]
if any [all [any-word? :item not set-word? :item] refinement? :item] [
prin append mold :item " "
if op? :value [prin append uppercase mold word " " value: none]
]
args: next args
]
print ""
args: head args
either none? in-obj [value: get word][value: :saved-value]
print "^/DESCRIPTION:"
either string? pick args 1 [
print [tab first args newline tab uppercase mold word "is" type-name :value "value."]
args: next args
] [
print "^-(undocumented)"
]
if block? pick args 1 [
attrs: first args
args: next args
]
if tail? args [exit]
while [not tail? args] [
item: first args
args: next args
if :item = /local [break]
either not refinement? :item [
all [set-word? :item :item = first [return:] block? first args rtype: first args]
if none? refmode [
print "^/ARGUMENTS:"
refmode: 'args
]
] [
if refmode <> 'refs [
print "^/REFINEMENTS:"
refmode: 'refs
]
]
either refinement? :item [
prin [tab mold item]
if string? pick args 1 [prin [" --" first args] args: next args]
print ""
] [
if all [any-word? :item not set-word? :item] [
if refmode = 'refs [prin tab]
prin [tab :item "-- "]
types: if block? pick args 1 [args: next args first back args]
if string? pick args 1 [prin [first args ""] args: next args]
if not types [types: 'any]
prin rejoin ["(Type: " types ")"]
print ""
]
]
]
if rtype [print ["^/RETURNS:^/^-" rtype]]
if attrs [
print "^/(SPECIAL ATTRIBUTES)"
while [not tail? attrs] [
value: first attrs
attrs: next attrs
if any-word? value [
prin [tab value]
if string? pick attrs 1 [
prin [" -- " first attrs]
attrs: next attrs
]
print ""
]
]
]
exit
]
[3/4] from: dockimbel:free at: 22-Dec-2000 19:37
Andrew Martin a écrit :
> > I defined a func within an object, and unlike a func at the global
> context, help will only tell me it's a path. Is there a way to get this
<<quoted lines omitted: 6>>
> BTW, Nenad if you're reading this, could we have a URL where this version of
> help is at?
Sure ! at http://rebol.free.fr/help.r
My reb site is under construction. It will be availble in a few days and will
include this script.
DK.
[4/4] from: grantwparks::yahoo at: 22-Dec-2000 15:53
Thanks much to you and Andrew!
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted