Skip to content
angerangel edited this page Mar 19, 2013 · 1 revision

USAGE

   HELP 'word /doc

DESCRIPTION

Prints information about words and values.

HELP is a function value.

ARGUMENTS

  • word (any-type!)

REFINEMENTS

  • /doc -- Open web browser to related documentation.

#SOURCE

help: make function! [  [
    "Prints information about words and values."
    'word [any-type!]
    /doc "Open web browser to related documentation."
    /local value args item type-name types tmp print-args
][
    if unset? get/any 'word [
        print trim/auto {
^-^-^-Use HELP or ? to see built-in info:

^-^-^-^-help insert
^-^-^-^-? insert

^-^-^-To search within the system, use quotes:

^-^-^-^-? "insert"

^-^-^-To browse online web documents:

^-^-^-^-help/doc insert

^-^-^-To view words and values of a context or object:

^-^-^-^-? lib    - the runtime library
^-^-^-^-? self   - your user context
^-^-^-^-? system - the system object
^-^-^-^-? system/options - special settings

^-^-^-To see all words of a specific datatype:

^-^-^-^-? native!
^-^-^-^-? function!
^-^-^-^-? datatype!

^-^-^-Other debug functions:

^-^-^-^-docs - open browser to web documentation
^-^-^-^-?? - display a variable and its value
^-^-^-^-probe - print a value (molded)
^-^-^-^-source func - show source code of func
^-^-^-^-trace - trace evaluation steps
^-^-^-^-what - show a list of known functions
^-^-^-^-why? - explain more about last error (via web)

^-^-^-Other information:

^-^-^-^-chat - open DevBase developer forum/BBS
^-^-^-^-docs - open DocBase document wiki website
^-^-^-^-bugs - open CureCore bug database website
^-^-^-^-demo - run demo launcher (from rebol.com)
^-^-^-^-about - see general product info
^-^-^-^-upgrade - check for newer versions
^-^-^-^-changes - show changes for recent version
^-^-^-^-install - install (when applicable)
^-^-^-^-license - show user license
^-^-^-^-usage - program cmd line options
^-^-}
        exit
    ]
    if all [word? :word not value? :word] [word: mold :word]
    if all [
        doc
        word? :word
        any [any-function? get :word datatype? get :word]
    ] [
        item: form :word
        either any-function? get :word [
            foreach [a b] [
                "!" "-ex"
                "?" "-q"
                "*" "-mul"
                "+" "-plu"
                "/" "-div"
                "=" "-eq"
                "<" "-lt"
                ">" "-gt"
            ] [replace/all item a b]
            tmp: http://www.rebol.com/r3/docs/functions/
        ] [
            tmp: http://www.rebol.com/r3/docs/datatypes/
            remove back tail item
        ]
        browse join tmp [item ".html"]
    ]
    if any [string? :word all [word? :word datatype? get :word] ] [
        if all [word? :word datatype? get :word] [
            value: spec-of get :word
            print [
                mold :word "is a datatype" newline
                "It is defined as" either find "aeiou" first value/title ["an"] ["a"] value/title newline
                "It is of the general type" value/type newline
            ]
        ]
        if any [:word = 'unset! not value? :word] [exit]
        types: dump-obj/match lib :word
        sort types
        if not empty? types [
            print ["Found these related words:" newline types]
            exit
        ]
        if all [word? :word datatype? get :word] [
            print ["No values defined for" word]
            exit
        ]
        print ["No information on" word]
        exit
    ]
    type-name: func [value] [
        value: mold type? :value
        clear back tail value
        join either find "aeiou" first value ["an "] ["a "] value
    ]
    if not any [word? :word path? :word] [
        print [mold :word "is" type-name :word]
        exit
    ]
    either path? :word [
        if any [
            error? set/any 'value try [get :word]
            not value? 'value
        ] [
            print ["No information on" word "(path has no value)"]
            exit
        ]
    ] [
        value: get :word
    ]
    unless any-function? :value [
        prin [uppercase mold word "is" type-name :value "of value: "]
        print either any [object? value port? value] [print "" dump-obj value] [mold :value]
        exit
    ]
    prin "USAGE:^/^-"
    args: words-of :value
    clear find args /local
    either op? :value [
        print [args/1 word args/2]
    ] [
        print [uppercase mold word args]
    ]
    print ajoin [
        newline "DESCRIPTION:" newline
        tab any [title-of :value "(undocumented)"] newline
        tab uppercase mold word " is " type-name :value " value."
    ]
    unless args: find spec-of :value any-word! [exit]
    clear find args /local
    print-args: func [label list /extra /local str] [
        if empty? list [exit]
        print label
        foreach arg list [
            str: ajoin [tab arg/1]
            if all [extra word? arg/1] [insert str tab]
            if arg/2 [append append str " -- " arg/2]
            if all [arg/3 not refinement? arg/1] [
                repend str [" (" arg/3 ")"]
            ]
            print str
        ]
    ]
    use [argl refl ref b v] [
        argl: copy []
        refl: copy []
        ref: b: v: none
        parse args [
            any [string! | block!]
            any [
                set word [refinement! (ref: true) | any-word!]
                (append/only either ref [refl] [argl] b: reduce [word none none])
                any [set v block! (b/3: v) | set v string! (b/2: v)]
            ]
        ]
        print-args "^/ARGUMENTS:" argl
        print-args/extra "^/REFINEMENTS:" refl
    ]
    exit
] ]
Clone this wiki locally