Last active
April 12, 2021 17:50
-
-
Save hiiamboris/5f85edba139fc88a5eb0ee9b7b30bc6b to your computer and use it in GitHub Desktop.
get arity of any word or path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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