Created
November 25, 2013 19:35
-
-
Save shanecelis/7647366 to your computer and use it in GitHub Desktop.
An attempt at making the source code for procedures easy to track down at runtime. Useful for Emacsy when aping the self-documenting system in Emacs.
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
;; define-with-source.scm | |
;; | |
;; An attempt at making the source code for procedures easy to track | |
;; down at runtime. Useful for Emacsy when aping the self-documenting | |
;; system in Emacs. | |
;; | |
;; Shane Celis | |
(define-module (define-with-source) | |
#:use-module (ice-9 optargs) | |
#:export-syntax (define-with-source-properties | |
define*-with-source-properties)) | |
(define-syntax add-source-properties | |
(lambda (x) | |
(let ((source-props (syntax-source x))) | |
(syntax-case x () | |
((add-source-properties define-kind (name . formals) . body) | |
#`(begin | |
(define-kind (name . formals) . body) | |
(set-procedure-property! name 'line #,(assq-ref source-props 'line)) | |
(set-procedure-property! name 'column #,(assq-ref source-props 'column)) | |
(set-procedure-property! name 'filename #,(assq-ref source-props 'filename)))))))) | |
(define-syntax-rule (define-with-source-properties . args) | |
"Defines a procedure and adds the line, column, and filename | |
properties from syntax-properties to the procedure's properties." | |
(add-source-properties define . args)) | |
(define-syntax-rule (define*-with-source-properties . args) | |
"Defines a procedure and adds the line, column, and filename | |
properties from syntax-properties to the procedure's properties." | |
(add-source-properties define* . args)) | |
#;(define*-with-source-properties (f x) | |
(+ x 1)) | |
#;(display (procedure-properties f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment