Commit 0446e5e9 authored by Christian Weilbach's avatar Christian Weilbach

Handle nil and introduce bound set of primitives.

parent 93da04a5
......@@ -25,6 +25,9 @@
(mapcat ns-publics runtime-namespaces)))))
(def ^:dynamic *bound*
(into *primitive-procedures* ['if 'let]))
(def empty-env {})
(def empty-graph {:V #{}
......@@ -54,6 +57,7 @@
[rho phi exp]
(cond (or (number? exp)
(nil? exp)
(string? exp)
(boolean? exp)
(keyword? exp))
......@@ -167,7 +171,7 @@
e (fixed-point-simplify e)
[rho {:keys [V A P Y]} E] (analyze rho phi e)
v (gensym "sample")
Z (free-vars E *primitive-procedures*)
Z (free-vars E *bound*)
F (list 'sample* (fixed-point-simplify E))]
{:V (conj V v)
......@@ -192,9 +196,9 @@
v (gensym "observe")
F1 (list 'observe* e obs)
F (fixed-point-simplify (list 'if phi F1 1))
Z (disj (free-vars e *primitive-procedures*) v)
Z (disj (free-vars e *bound*) v)
;; TODO check this assertion
_ (when (seq (set/intersection (free-vars E2 *primitive-procedures*) V))
_ (when (seq (set/intersection (free-vars E2 *bound*) V))
(throw (ex-info "Observation references random vars."
{:obs E2
:free (set/intersection (free-vars E2) V)})))
......@@ -11,25 +11,6 @@
[foppl-compiler.analyze :refer [analyze empty-env empty-graph]]
[ :refer [free-vars]]))
(def ^:dynamic *primitive-procedures*
"primitive procedures for Anglican semantics" ;; TODO check implications of this choice
(let [;; higher-order procedures cannot be primitive
exclude '#{loop
map reduce
filter keep keep-indexed remove
every? not-any? some
every-pred some-fn
comp juxt partial}
;; runtime namespaces
runtime-namespaces '[clojure.core anglican.runtime foppl-compiler.primitives]]
(set (keep (fn [[k v]]
(when (and (not (exclude k))
(fn? (var-get v)))
(mapcat ns-publics runtime-namespaces)))))
(defn invert-graph [G]
(reduce (fn [acc m] (merge-with set/union acc m))
......@@ -82,6 +82,7 @@
[W_0 b_0 W_1 b_1])))))))
(:require [ :refer :all]
[foppl-compiler.core :refer [*primitive-procedures*]]
[foppl-compiler.analyze :refer [*primitive-procedures*]]
[clojure.test :refer [deftest testing is]]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment