     (vector? k) (get-var-and-flow has (get-in has [:objects (first k)]) (second k))
     :else (assert (or (nil? k) (keyword? k) (vector? k)) "Unrecognized variable lookup type")))
 
+(defn constant-from-expr [has ha c]
+  (cond
+    (number? c) c
+    (and (vector? c) (= (first c) :d)) (second (apply get-var-and-flow has ha (rest c)))
+    (vector? c) (first (get-var-and-flow has ha c))
+    (seq? c) (apply ({'+ + '- - '* * '/ /} (first c))
+                    (map #(constant-from-expr has ha %) (rest c)))))
+
 (defn simple-interval [has ha simple-guard]
   (let [rel (first simple-guard)
-        c (last simple-guard)
+        c (constant-from-expr has ha (last simple-guard))
+        _ (println "Constant" (last simple-guard) "is" c)
+        _ (println ":d :x is" (constant-from-expr has ha [:d :x]))
         v1k (second simple-guard)
         v2k (if (= (count simple-guard) 4) (third simple-guard) nil)
         [v10 v1f] (get-var-and-flow has ha v1k)


(defcard ha-data
         (fn [scene _owner]
           (let [a (get-in @scene [:objects :a])]
             (sab/html [:div
                        [:div "Required transitions:" (str (required-transitions a))]
                        [:div "Next required transition:" (str (:next-required-transition a))]
                        [:div "Optional transitions:" (str (optional-transitions a))]
                        [:div "Intervals:" (str (:optional-transitions a))]])))
         scene-a)

(defcard enter-trans
         (let [a (get-in (make-scene-a 16) [:objects :a])
               a (enter-state {:a a} a :right 0)]
           (:next-required-transition (enter-state {:a a} a :left 0))))

#_(defcard sample-time
           "What are the current values of the variables of object a?"

(defonce scene-a (atom {}))
(defonce last-time nil)

(defn goomba [id x y speed state others]
  (make-ha id                                               ;id
           {:x     x :y y                                   ;init
            :w     16 :h 16
            :state state}
           (make-state
             :right                                         ;name
             {:x speed}                                     ;flows
             ;edges
             ; x < 16 && x + dx*frame >= 16 --> x >= 16 - dx*frame
             (make-edge :left [[:lt :x 64] [:geq :x '(- 64 [:d :x])]] #{:required})
             ; x + 16 < x2 + dx2*frame && x + dx*frame + 16 >= x2 + dx2*frame
             ; x - x2 < -16 + dx2*frame && x - x2 >= dx2*frame - dx*frame - 16
             (map #(make-edge :left [[:lt :x [% :x] (list '+ -16 [:d % :x])]
                                     [:geq :x [% :x] (list '- [:d % :x] [:d :x] 16)]]
                              #{:required}) others))
           (make-state
             :left                                          ;name
             {:x (- speed)}                                 ;flows
             ;edges
             ; x > 8 && x + dx*frame <= 8 --> x <= 8 - dx*frame
             (make-edge :right [[:gt :x 8] [:leq :x '(- 8 [:d :x])]] #{:required})
             ; x > x2 + 16 + dx2 && x + dx*frame <= x2 + dx2*frame + 16 --> x - x2 > 16 + dx2 && x - x2 <= dx2*frame + 16 - dx*frame
             ; x - x2 > 16 + dx2
             (map #(make-edge :right [[:gt :x [% :x] (list '+ 16 [:d % :x])]
                                      [:leq :x [% :x] (list '+ [:d % :x] 16 (list '- [:d :x]))]]
                              #{:required}) others))))

(defn make-scene-a [x] (let [objects [(goomba :a x 8 8 :right #{:b}) (goomba :b (* x 4) 8 8 :left #{:a})]
                             obj-ids (map :id objects)
                             obj-dict (zipmap obj-ids objects)
                             ; got to let every HA enter its current (initial) state to set up state invariants like
