missionary

2020-12-19T16:58:28.003400Z

I am trying to make this test pass but it hangs, i am trying to zip a discrete signal with a continuous signal, how do i do it

(? (aggregate conj
       (m/sample vector
         (enumerate (range 3))
         (m/watch (atom :x))
       )))
  => [[0 :x] [1 :x] [2 :x]]

2020-12-19T17:09:16.004300Z

I think you swapped sample inputs

2020-12-19T17:11:26.004500Z

ahhh thank you

2020-12-19T18:22:04.004800Z

Is this deref well defined

(def r (atom nil))
  (def >a (m/watch r))
  (def >b (ap (println (?? >a)) 42))
  (reset! r 1)
  @(>b prn prn)
  => 42     ; and prints 1

2020-12-19T18:22:22.005100Z

what is the "right" way to sample the output value

2020-12-19T18:38:35.009200Z

deref is OK in this case because the result is immediately available, otherwise it's not recommended. how to sample the output value : there's no general answer, it depends how it's meant to be consumed. If you're just testing at the REPL what I usually do is (def it (flow #(prn :ready) #(prn :done))) and then @it each time :ready is printed, and (it) to cancel

2020-12-19T18:40:56.009600Z

thanks

2020-12-19T18:42:24.009800Z

n and t stand for notify and terminate?

2020-12-19T18:42:29.010Z

yes

2020-12-19T19:41:02.010800Z

this test passes

(tests
  "backpressure 3 w latest"
  (def !a (atom 0))
  (def >a (m/watch !a))
  (def >z (ap (?? >a)))
  (def !z (>z #(println :ready) #(println :done)))
  (reset! !a 1)
  @!z => 0
  @!z => 1
  )
this test fails with a crash, one line different - calls m/latest
(tests
  "backpressure 3 w latest"
  (def !a (atom 0))
  (def >a (m/watch !a))
  (def >z (m/latest identity (ap (?? >a))))
  (def !z (>z #(println :ready) #(println :done)))
  (reset! !a 1)
  @!z => 0
  @!z => 1           ; boom
  )

Execution error (ArrayIndexOutOfBoundsException) at missionary.impl.Latest/deref (Latest.java:88).
Index -1 out of bounds for length 1

2020-12-19T19:41:23.011200Z

is this a bug

2020-12-19T19:45:07.011900Z

I'm also surprised that I get 0 in both tests when reading !z the first time, i would expect it to sample the latest value immediately if I understand correctly the model

2020-12-19T19:57:31.013500Z

(m/latest identity flow) should not change the behavior of input, so bug it is

2020-12-19T19:59:52.014800Z

the first value is 0 because ap is discrete. To turn it into continuous you can disable backpressure and only keep latest values with (m/relieve {} flow)

2020-12-19T20:00:42.015300Z

ohhh i did not realize ap was discrete, that changes a lot, thanks

2020-12-19T20:01:01.015800Z

what is the {} function meaning here? I had used (defn skip [a b] b) with relieve

2020-12-19T20:01:20.016Z

oh, default value if not in map

2020-12-19T20:01:45.016200Z

yes

2020-12-19T20:01:58.016400Z

good one

2020-12-19T20:14:19.018500Z

I was thinking that with continuous signals the work was only done when asked for This test runs the println effects even though I did not sample

(tests
  "when does the work happen"
  (def !a (atom 0))
  (def >a (m/watch !a))
  (def >z (m/relieve {} (ap (println 'work1) (let [a (?? >a)] (println 'work2) a))))
  (def !z (>z #(println :ready) #(println :done)))
  (reset! !a 1)
  (reset! !a 2)
  ;@!z => 2
  )
work1
work2
:ready
work2
work2
So does that mean it will eagerly push inputs through?

2020-12-19T20:15:44.018800Z

perhaps I should not be mixing continuous and discrete

2020-12-19T20:18:30.019600Z

you can mix continuous and discrete, but the discrete parts will be run eagerly

2020-12-19T20:21:10.021500Z

you can only be fully lazy if you have continuous operators all the way down, watch latest signal!, ie the good old spreadsheet model

2020-12-19T20:21:43.021800Z

how do I (map inc) over a continuous signal

2020-12-19T20:21:53.022Z

latest

2020-12-19T20:26:42.022900Z

Oh ok so my crashing test was kind of bogus anyway because I was accidentally mixing discrete and continuous. Everything works fine if I keep it continuous only

2020-12-19T20:29:58.023900Z

It's still a bug, it should not crash

2020-12-19T20:30:32.024300Z

(ap (?? (f (?? >a)))) discrete bind

2020-12-19T20:30:36.024500Z

what is continuous bind

2020-12-19T20:31:42.024800Z

I'm not clear if it's possible to do actually

2020-12-19T20:33:13.025600Z

What should it do ?

2020-12-19T20:49:28.027Z

The continuous time bind confuses me right now, but the discrete time bind I would expect to pass this test: use a >control signal to toggle between signals >p and >q at runtime

(defn bind [>a f]
  (ap (?? (f (?? >a)))))

(tests
  "discrete bind"

  (def !p (atom 1))
  (def !q (atom 2))
  (def !control (atom :p))

  (def >p (m/watch !p))
  (def >q (m/watch !q))
  (def >control (m/watch !control))
  (def >cross (bind >control (fn [c]
                               (case c :p >p :q >q))))
  (def >z >cross #_(m/zip vector >p >q >cross))

  (def !z (>z #(println :ready) #(println :done)))

  @!z => 1

  (reset! !control :q)
  @!z => 2               ; nil

  )

2020-12-19T20:49:49.027300Z

Ignore the !! sorry

2020-12-19T21:08:33.028400Z

it's close to ?!

2020-12-19T21:09:09.028700Z

bed time here, I'll sleep on that

2020-12-19T21:17:03.029200Z

Changing bind to use ?! caused the above discrete test to pass

(defn bind [>a f]
  (ap (?? (f (?! >a)))))

2020-12-19T21:17:18.029600Z

that's a really interesting observation also