Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Created November 25, 2013 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecelis/7647366 to your computer and use it in GitHub Desktop.
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.
;; 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