Created
December 18, 2020 05:35
-
-
Save sritchie/6b048e314a481c00fa420200893231f2 to your computer and use it in GitHub Desktop.
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
(ns sicmutils.sci | |
(:require [sicmutils.env :as env] | |
[sci.core :as sci])) | |
(defn ns-bindings | |
"Returns a pair of | |
- `(ns-publics sym)` fn entries | |
- `(ns-publics sym)` macro entries" | |
[sym] | |
(let [env-m (ns-publics sym) | |
macro? (comp :macro meta val) | |
{fns nil macros true} (group-by macro? env-m)] | |
[(into {} fns) (into {} macros)])) | |
(let [[fns macros] (ns-bindings 'sicmutils.env)] | |
(def publics fns) | |
(def public-macros (dissoc macros 'bootstrap-repl!))) | |
(let [bindings (-> (into {} (map (fn [[k v]] [k @v]) publics)) | |
;; required because the macro doesn't work yet! | |
(assoc 'literal-function | |
sicmutils.abstract.function/literal-function))] | |
(->> (sci/eval-string | |
"(let [f (literal-function 'f)] | |
(((exp D) f) 't))" | |
{:bindings bindings}) | |
(env/seq:print 5))) | |
;; (f t) | |
;; ((D f) t) | |
;; (* 1/2 (((expt D 2) f) t)) | |
;; (* 1/6 (((expt D 3) f) t)) | |
;; (* 1/24 (((expt D 4) f) t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment