Skip to content

Instantly share code, notes, and snippets.

@axiixc
Created March 10, 2012 20:16
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 axiixc/2012940 to your computer and use it in GitHub Desktop.
Save axiixc/2012940 to your computer and use it in GitHub Desktop.
Automatically reload files loaded using (rl-load <filename>)
;;; 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