Rebol 编程/types-of
外观
< Rebol 编程
TYPES-OF value
返回函数类型的副本。
TYPES-OF 是一个函数值。
- 值 -- (类型:任何)
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]]
]
]