Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

help object!/func

 [1/3] from: rchristiansen:pop:isdfa:sei-it at: 5-Jan-2001 11:13


Is there any way to use 'help on a function which is a value in an object! datatype? Using 'help only tells me the function is a path of the object!
>> test: make object! [
[ test-function: func [][ [ print "test" [ ] [ ]
>> test/test-function
test
>> help test/test-function
test/test-function is a path -Ryan

 [2/3] from: al::bri::xtra::co::nz at: 6-Jan-2001 7:43


Ryan wrote:
> Is there any way to use 'help on a function which is a value in an object!
datatype? What you need is Nenad Rakocevic's modifications to 'help. It's posted after my .sig with my own small modifications. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/ -><- 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.2 History: [ 1.0.2 5/Jan/2001 {Change 'func /local to 'func.} 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!] ][ 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!]] [ 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] attrs: rtype: refmode: none 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/3] from: rchristiansen:pop:isdfa:sei-it at: 5-Jan-2001 13:06


Thanks. This version of 'help is invaluable. http://members.nbci.com/AndrewMartin/Rebol/Patches/help.r