[ANN] - purnam 0.4.3 released - Javascript Language Extensions for Clojurescript

193 views
Skip to first unread message

zcaudate

unread,
Mar 1, 2014, 8:11:44 AM3/1/14
to clo...@googlegroups.com

purnam

Javascript Language Extensions for Clojurescript

Build Status

Usage

In your project file, add

[im.chit/purnam "0.4.3"]

Documention

Examples

Related Projects

Mailing List

A Google Group for purnam has been setup here. Comments, Questions, Feedback, Contributions are most definitely welcome!

History

In its earliest incarnation, purnam was more or less a set of scattered ideas about how to play nicely with existing javascript libraries using clojurescript. What initially started off as experimental language extensions for working with clojurescript and angularjs has matured into a synergistic set of libraries and workflows for crafting clojurescript applications (now decoupled from angularjs)

The original purnam library was way too big. It has now been broken up into more reasonably sized pieces. The core functionality of purnam have been seperated into independent libraries so that developers can have a choice about including one or all of them inside their projects.

  • purnam.core provides macros for better and more intuitive javascript interop.
  • purnam.test provides macros for testing with the karma test runner.
  • purnam.native provides utility function and clojure protocol support for native arrays and objects.

Support for angular.js was a major reason that purnam became a popular choice for frontend development. From a functional point of view however, the language extensions could be completely decoupled from angularjs support and so purnam.angular has been renamed to gyr.

As the purnam style syntax could be extended to meteorjsreactjs as well as the thousands of javascript libaries out there, decoupling the code-walking component purnam.common from the main project took the most of the time in the redesign. Hopefully, this library will enable other developers to write their own purnam-flavored macros.

Lastly, purnam.category namespace has been moved to brahmin. I started looking at category theory after a conversation with Logan Campbell about conditional restarts for asynchronous calls. Despite porting fluokitten to clojurescript, I still don't understand what a Monad is. So it is a highly experimental (but very fun) project.

Quick Start

Functions
// javascript
function square(x){
  return {value: x.value * x.value};
}
;; clojurescript + purnam
(def.n square [x]
  (obj :value (* x.value x.value)))

;; or
(def*n square [x]
  {:value (* x.value x.value)})

;; clojurescript
(defn square [x]
  (let [o (js-obj)
        v (aget x "value")]
    (aset o "value" (* v v)))
    o)
Objects
// javascript
var user = {id: 0 
            account: {username: "user"
                      password: "pass"}}
;; clojurescript + purnam
(def user (obj :id 0 
               :account {:username "user"
                         :password "pass"}))
;; or

(def* user {:id 0 
            :account {:username "user"
                      :password "pass"})})
;; clojurescript
(def user
  (let [acc (js-obj)
        user (js-obj)]
    (aset acc "username" "user")
    (aset acc "password" "pass")
    (aset user "account" acc)
    (aset user "id" 0)
    user)) 

;; clojurescript using clj->js (slower)
(def user 
  (clj->js {:id 0 
            :account {:username "user"
                      :password "pass"})})
Clojure Protocols
(seq (js* "[1, 2, 3, 4]")) 
=> '(1 2 3 4)

(seq (js* "{a:1, b:2}"))
=> '(["a" 1] ["b" 2]) 
Midje Style Testing
(fact [[{:doc "an example test description"
         :globals [ka "a"
                   kb "b"]
         :vars [o (obj :a 1 :b 2 :c 3)]}]]

 "dot notation for native objects"
 o.a => 1
 (+ o.a o.b o.c) => 6

 "support for both native and cljs comparisons"
 o => (obj :a 1 :b 2 :c 3)
 [1 2 3 4] => [1 2 3 4]

 "support for function comparison"
  2 => even?
  3 => (comp not even?)

 "globals"
  o.|ka| => 1
  (+ o.|ka| o.|kb|) => 3

  "vars are allowed to be rebound"
  (! o (arr [1 2 3]
            [4 5 6]
            [7 8 9]))

  (- o.2.2 o.0.0) => 8)

License

Copyright © 2014 Chris Zheng

Distributed under the The MIT License.

zcaudate

unread,
Mar 1, 2014, 4:22:28 PM3/1/14
to clo...@googlegroups.com
I'm also looking for collaborators as it is getting to a stage where I'm having trouble managing it by myself.

 if anybody is interested. Please send me a message

Chris

Mark Mandel

unread,
Mar 2, 2014, 3:49:08 PM3/2/14
to clojure
Awesome. 

Glad to have this complete. I had some pending pull requests I wanted to drop in.

Mark


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast

Chris Zheng

unread,
Mar 2, 2014, 7:51:46 PM3/2/14
to clo...@googlegroups.com
Looking forward to it!
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/vQqvs9cBB78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages