Created
February 4, 2015 15:49
-
-
Save gregspurrier/8c514071fddf98dbcb3f to your computer and use it in GitHub Desktop.
A function to generate code that recreates the state of the current envrionment
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 construct-environment | |
Globals -> [do | (global-load-sequence Globals)]) | |
(define global-load-sequence | |
[] -> [] | |
[Name | Names] -> [[set Name (construct-value (value Name))] | |
| (global-load-sequence Names)]) | |
(define atom? | |
X -> (or (boolean? X) | |
(number? X) | |
(string? X) | |
(symbol? X))) | |
(define construct-value | |
Atom -> Atom where (atom? Atom) | |
[] -> [] | |
[Head | Tail] -> [cons (construct-value Head) (construct-value Tail)] | |
Vector -> (construct-vector Vector) where (vector? Vector) | |
(@p First Second) -> [@p (construct-value First) (construct-value Second)]) | |
(define construct-vector | |
Vector -> (let Size (limit Vector) | |
Name (gensym (protect Vec)) | |
LoadSeq (vector-load-sequence Vector Name Size []) | |
(if (= LoadSeq []) | |
[vector Size] | |
[let Name [vector Size] | |
[do | (append LoadSeq [Name])]]))) | |
(define vector-load-sequence | |
Vector Name 0 Accum -> Accum | |
Vector Name Index Accum | |
-> (let NewAccum | |
(trap-error | |
[[vector-> Name Index (construct-value (<-vector Vector Index))] | |
| Accum] | |
(/. _ Accum)) | |
(vector-load-sequence Vector Name (- Index 1) NewAccum))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment