Rebol Programming/types-of

USAGE:

edit
TYPES-OF value 

DESCRIPTION:

edit

Returns a copy of the types of a function.

TYPES-OF is a function value.

ARGUMENTS

edit
  • value -- (Type: any)

SOURCE CODE

edit
types-of: func [
    "Returns a copy of the types of a function." 
    value /local 
    valtype 
    reftype 
    result 
    types
][
    valtype: [none! logic! integer! decimal! money! char! pair! tuple! time! date! string! binary! file! email! url! tag! issue! bitset! image! block! paren! path! set-path! lit-path! datatype! word! set-word! get-word! lit-word! refinement! native! action! routine! op! function! object! port! event! struct! library! hash! list! symbol!] 
    reftype: [none! logic!] 
    case [
        object? :value [cause-error 'script 'invalid-arg 'types] 
        any-function? :value [
            result: copy [] 
            types: none 
            parse third :value [any [to any-word! [
                        [word! | lit-word! | get-word!] [
                            set types block! (
                                types: copy types 
                                while [not tail? types] [
                                    switch/default to-word first types [
                                        any-type! [types: change/part types to-typeset any-type! 1] 
                                        any-block! [types: change/part types to-typeset any-block! 1] 
                                        any-function! [types: change/part types to-typeset any-function! 1] 
                                        any-string! [types: change/part types to-typeset any-string! 1] 
                                        any-word! [types: change/part types to-typeset any-word! 1] 
                                        series! [types: change/part types to-typeset series! 1] 
                                        number! [types: change/part types to-typeset number! 1]
                                    ] [
                                        types: next types
                                    ]
                                ] 
                                insert/only tail result head types
                            ) | (
                                insert/only tail result reduce valtype
                            )
                        ] | 
                        refinement! (
                            insert/only tail result reduce reftype
                        ) | 
                        skip
                    ]]] 
            result
        ] 
        'else [cause-error 'script 'cannot-use reduce ['reflect type? :value]]
    ]
]