Created
March 10, 2012 20:16
-
-
Save axiixc/2012940 to your computer and use it in GitHub Desktop.
Automatically reload files loaded using (rl-load <filename>)
This file contains hidden or 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
;;; James Savage -- http://axiixc.com | |
;;; Easy file reloading for scheme, written because I needed it. | |
;;; The list of all reloadable files | |
(define rl-files (list)) | |
(define rl-last-file '()) | |
;;; Clear any reloadable files | |
(define rl-clear (lambda () | |
(set! rl-files (list)) | |
(set! rl-last-file '()))) | |
;;; Reload all reloadable files | |
(define rl (lambda () | |
(letrec ([helper (lambda (ls) | |
(unless (null? ls) | |
(printf "~a ~a\n" #\x21BB (car ls)) | |
(load (car ls)) | |
(helper (cdr ls))))]) | |
(if (null? rl-files) | |
(printf "~a No files loaded\n" #\x2717) | |
(helper rl-files))))) | |
;;; Reload last loaded reloadable file | |
(define rll (lambda () | |
(if (null? rl-last-file) | |
(printf "~a No files loaded\n" #\x2717) | |
(begin | |
(printf "~a ~a\n" #\x21BB rl-last-file) | |
(load rl-last-file))))) | |
;;; Load a file and add it to the reloadable list | |
(define rl-load (lambda (file) | |
(letrec ([in? (lambda (needle list) | |
(cond | |
((null? list) #f) | |
((string=? needle (car list)) #t) | |
(else (in? needle (cdr list)))))]) | |
(load file) | |
(set! rl-last-file file) | |
(unless (in? file rl-files) | |
(set! rl-files (cons file rl-files)))) | |
(void))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment