rcf icon indicating copy to clipboard operation
rcf copied to clipboard

idea: should unify results act as memory variables saved to test env?

Open dustingetz opened this issue 4 years ago • 1 comments

(tests
  (PlaidClient (-> (env!) (select-keys [:plaid/client-id :plaid/secret])))
  := ?plaid)

(tests
  ((create-sandbox-token ?plaid "ins_129571") ! !)
  % := {:public_token ?token :request_id _}
  
  (println ?plaid ?token))

dustingetz avatar Dec 05 '21 18:12 dustingetz

This example is just begging for memory variables to destructure on client/server

(ns user.photon_compiler
  (:require [hyperfiddle.photon :as p]
            [hyperfiddle.photon-impl.compiler :refer [analyze]]
            [hyperfiddle.photon-impl.runtime :as r :refer [emit]]
            [hyperfiddle.rcf :refer [tests]]))

(tests

  (analyze {} '(p/fn [n]
                 (let [x (+ n 2)]
                   (p/fn [y]
                     (+ y x)))))

  ; tuple of [client, server]
  := [[:constant
       [:pub
        [:node 0]
        [:pub
         [:apply [:global :clojure.core/+] [:sub 1] [:literal 2]]
         [:constant [:pub [:node 0] [:apply [:global :clojure.core/+] [:sub 1] [:sub 2]]]]]]]
      ; this is a nil server program
      [:target [:target [:nop] [:nop]] [:literal nil]]]

  (def client (first *1))
  (def server (second *2))

  (emit (comp symbol str) client) :=
  `(r/peer
     1 0 0 0 0 0 0
     (clojure.core/fn [~'nodes]
       (r/steady
         (r/constant
           0 0 0 0 2 0 0
           (clojure.core/fn [~'nodes]
             (clojure.core/let [~'pub0 (r/signal 0 (clojure.core/nth ~'nodes 0))]
               (clojure.core/let [~'pub1 (r/signal 1 (r/latest-apply (r/steady clojure.core/+) ~'pub0 (r/steady (quote 2))))]
                 (r/steady
                   (r/constant
                     0 0 0 0 1 0 0
                     (clojure.core/fn [~'nodes]
                       (clojure.core/let [~'pub2 (r/signal 0 (clojure.core/nth ~'nodes 0))]
                         (r/latest-apply (r/steady clojure.core/+) ~'pub2 ~'pub1))))))))))))

  ; this is a noop server, our current implementation produces clients and servers with matching closure structures
  ; so the closure IDs always align
  (emit (comp symbol str) server) :=
  `(r/peer
     0 0 1 0 0 0 0
     (clojure.core/fn [~'nodes]
       (do
         (r/target
           0 0 1 0 0 0 0
           (clojure.core/fn [~'nodes]
             (do (r/target
                   0 0 0 0 0 0 0
                   (clojure.core/fn [~'nodes]
                     nil)) nil)))
         (r/steady (quote nil)))))
  )

dustingetz avatar May 11 '22 19:05 dustingetz