(define-macro (bind-poly poly_sym implementation_sym . docstring)
(if (impc:ti:genericfunc-exists? implementation_sym)
(impc:compiler:print-compiler-error (string-append "bind-poly only accepts monomorphic functions, not " (symbol->string implementation_sym))))
(if (not (impc:ti:closure-or-nativefunc-exists? (symbol->string implementation_sym)))
(impc:compiler:print-missing-identifier-error implementation_sym 'closure))
(let ((type (impc:ti:get-closure-or-nativefunc-type (symbol->string implementation_sym))))
(if type
`(begin
(impc:ti:register-new-polyfunc ,(symbol->string poly_sym) ,(symbol->string implementation_sym) ',type ,(if (null? docstring) "" (car docstring)))
(impc:ti:create-scheme-wrapper (symbol->string ',implementation_sym))
(if (not (regex:match? ,(symbol->string implementation_sym) "(_adhoc_|_poly_)"))
(impc:compiler:print-polying-details-to-log "PolyFunc:"
,(symbol->string poly_sym)
,(symbol->string implementation_sym)
,(impc:ir:pretty-print-type type))))
`(impc:compiler:print-missing-identifier-error ',implementation_sym 'closure))))