Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
Last active April 12, 2021 17:50
Show Gist options
  • Save hiiamboris/5f85edba139fc88a5eb0ee9b7b30bc6b to your computer and use it in GitHub Desktop.
Save hiiamboris/5f85edba139fc88a5eb0ee9b7b30bc6b to your computer and use it in GitHub Desktop.
get arity of any word or path
arity?: func [p [word! path!] /local p2] [
either word? p [
preprocessor/func-arity? spec-of get :p
][
; path format: obj1/obj2.../func/ref1/ref2...
; have to find a point where in that path a function starts
; i.e. p2: obj1/obj2.../func
; and the call itself is: func/ref1/ref2...
p2: as path! clear [] ; reuse the same block over and over again
until [
append p2 pick p 1 + length? p2
; stupid get won't accept paths of single length like [change], have to work around
any-function? get either 1 = length? p2 [p2/1][p2]
]
preprocessor/func-arity?/with (spec-of get either 1 = length? p2 [p2/1][p2]) (at p length? p2)
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment