What file is a name defined in?

 

#lang scheme
; What file is a name defined in?
;; definition-source : identifier -> (U symbol path)
;; Returns a symbol or path for the module that contains
;; the definition for a given name.
(define (definition-source id)
  (let ([binding (identifier-binding id)])
    (and (list? binding)
         (resolved-module-path-name
          (module-path-index-resolve (car binding))))))
(definition-source #'map)
 ; => #
(definition-source #'+)
; => #%kernel
; "The + procedure is defined in the built-in kernel module
; (it has no Scheme source file)."

(via PLT)

Leave a Reply

Your email address will not be published. Required fields are marked *