mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
add stuff for dumping code from memory into files
This commit is contained in:
parent
cc1709f30a
commit
648e5a9554
24
mad/dump.mad
Normal file
24
mad/dump.mad
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
;;
|
||||
;; Tools for dumping code from memory into files.
|
||||
;;
|
||||
;; Example usage:
|
||||
;; > (dumpEnv (env) "funcs.mad")
|
||||
;;
|
||||
;; This will write all function definitions from the current environment into file "funcs.mad".
|
||||
;;
|
||||
|
||||
;; Return the string for defining the given function
|
||||
(defn funcToStr (f name)
|
||||
(str (if (macro? f) "(defmacro " "(defn ")
|
||||
name " " (pstr (meta f "args")) " "
|
||||
(pstr (meta f "body")) ")"))
|
||||
|
||||
;; Write a hash-map of functions into a file
|
||||
(defn dumpFuncs (funcs filename)
|
||||
(let (fnStrings (map2 (fn (f name) (funcToStr f name)) (values funcs) (keys funcs)))
|
||||
(fput filename (apply join (str EOL EOL) fnStrings))))
|
||||
|
||||
;; Write all functions in the given environment to file
|
||||
(defn dumpEnv (e filename)
|
||||
(dumpFuncs (filterh fn? e) filename))
|
Loading…
Reference in New Issue
Block a user