Clojure Example Functions                        ilegra - LDCBy Jackson dos Santos
frequenciesuser => (frequencies (1 2 3)){1 1, 2 1, 3 1}
gensymuser => (gensym "Blastoise")Blastoise342user=> (gensym)G__345
memfnuser=> (map (memfn charAt i) ["fred" "ethel" "lucy"] [1 2 3])(r h y)user=>(map #(.charAt %1 %2) ["fred" "ethel" "lucy...
bank-transfer(defn bank-withdraw[bank-account value-to-withdraw]  (dosync    (ref-set bank-account (assoc @bank-account :v...
bank-transfer(deftest test-bank-transfer  (def client1 (ref (struct bank-account "Blastoise" 151)))  (def client2 (ref (st...
Java and Clojure IntegrationRT.loadResourceScript("cartax.clj");Var carType = RT.var("cartax", "car");return carType.get();
Java and Clojure IntegrationRT.loadResourceScript("cartax.clj");Var carType = RT.var("cartax", "car");return carType.get();
Java and Clojure IntegrationVar structMap = RT.var("clojure.core", "struct-map");return structMap.invoke(carStruct,getStru...
Java and Clojure Integrationtry {        Var t = RT.var("cartax", "verify_car_speed");        return t.invoke(carStruct);}...
Java and Clojure Integrationtry {        RT.loadResourceScript("cartax.clj");        Object car = buildCar(getCarReference...
4Clojure Problems Solved
4Clojure Problem
4Clojure Problem
Upcoming SlideShare
Loading in...5
×

Clojure functions 4

474

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
474
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Clojure functions 4

  1. 1. Clojure Example Functions ilegra - LDCBy Jackson dos Santos
  2. 2. frequenciesuser => (frequencies (1 2 3)){1 1, 2 1, 3 1}
  3. 3. gensymuser => (gensym "Blastoise")Blastoise342user=> (gensym)G__345
  4. 4. memfnuser=> (map (memfn charAt i) ["fred" "ethel" "lucy"] [1 2 3])(r h y)user=>(map #(.charAt %1 %2) ["fred" "ethel" "lucy"] [1 2 3])(r h y)
  5. 5. bank-transfer(defn bank-withdraw[bank-account value-to-withdraw] (dosync (ref-set bank-account (assoc @bank-account :value (- (get @bank-account :value) value-to-withdraw))) ))(defn bank-deposit [bank-account value-to-deposit] (dosync (ref-set bank-account (assoc @bank-account :value (+ (get @bank-account :value) value-to-deposit))) )(defn bank-transfer[account-to-debit account-to-credit value] (bank-deposit account-to-credit value) (bank-withdraw account-to-debit value))
  6. 6. bank-transfer(deftest test-bank-transfer (def client1 (ref (struct bank-account "Blastoise" 151))) (def client2 (ref (struct bank-account "Pikachu" 1500))) (bank-transfer client2 client1 132.98M) (is (= 283.98M (get @client1 :value))) (is (= 1367.02M (get @client2 :value))))
  7. 7. Java and Clojure IntegrationRT.loadResourceScript("cartax.clj");Var carType = RT.var("cartax", "car");return carType.get();
  8. 8. Java and Clojure IntegrationRT.loadResourceScript("cartax.clj");Var carType = RT.var("cartax", "car");return carType.get();
  9. 9. Java and Clojure IntegrationVar structMap = RT.var("clojure.core", "struct-map");return structMap.invoke(carStruct,getStructMapKeyVal("owner-name"), ownerName,getStructMapKeyVal("car-type"), carType,getStructMapKeyVal("cur-speed"), curSpeed,getStructMapKeyVal("licence-plate"), licencePlate)(struct-map car :owner-name “valor” :car-type “valor” :cur-speed valor :licence-plate “valor”)
  10. 10. Java and Clojure Integrationtry { Var t = RT.var("cartax", "verify_car_speed"); return t.invoke(carStruct);} catch (Exception e) { throw new RuntimeException(e);}
  11. 11. Java and Clojure Integrationtry { RT.loadResourceScript("cartax.clj"); Object car = buildCar(getCarReference(), "Jackson", "Fuca", 101, "AAAA"); Object verifiedCar = verifyCarSpeed(car); System.out.println(verifiedCar);} catch (Exception e) { throw new RuntimeException(e);}
  12. 12. 4Clojure Problems Solved
  13. 13. 4Clojure Problem
  14. 14. 4Clojure Problem
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×