Advertisement
Guest User

kratid prototype

a guest
Sep 30th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns kratid.core
  2.   (:gen-class))
  3.  
  4. (defn call-B
  5.   "This is the other side, the worker application which gets input as edn encoded strings of source-code."
  6.   [mapper-fn-str reducer-fn-str data-source-fn-str]
  7.   (println (str "call b invoked with data: " data-source-fn-str " ---> map: "  mapper-fn-str " ---> reduce: " reducer-fn-str))
  8.   (let [data-list ((eval (clojure.edn/read-string data-source-fn-str)))
  9.         map-applied-list (map (eval (clojure.edn/read-string mapper-fn-str)) data-list)
  10.         reduced-result (reduce (eval (clojure.edn/read-string reducer-fn-str)) map-applied-list)]
  11.     ;; return eventual result as a list of one element, encoded as a string
  12.     (str (list reduced-result))))
  13.  
  14. (defn call-a-B
  15.   "Encodes all three forms as strings to be executed on the 'other side', invokes other-side"
  16.   [form-mapper form-reducer form-datasource]
  17.   (let [remote-call-result(call-B
  18.                            (str form-mapper)
  19.                            (str form-reducer)
  20.                            (str form-datasource))]
  21.     (clojure.edn/read-string remote-call-result)))
  22.  
  23. (defn app-A
  24.   "Emulates someone asking app-A for something useful, in this case to increase 1,2,3 and sum the result, returns 9"[]
  25.   (call-a-B
  26.    '(fn [x] (inc x))     ;; the mapper func
  27.    '(fn [a b] (+ a b))   ;; the reducer func
  28.    '(fn [] (range 1 4))  ;; the data producer func
  29.    ))
  30.  
  31. (defn -main
  32.   "This is something odd."
  33.   [& args]
  34.   (println (app-A)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement