Just FYI,

js/object.a.b.c -- 15 chars
(set! js/object.a.b.c 10) -- 25 chars

This assumes object lives in current JS scope (of course so does the
JS 12 char version).

Also, aget is variadic, so

(aget object "a" "b" "c")

works fine in released versions of ClojureScript (that's 25 chars and
looks up object according to CLJS scoping rules; with David's patch,
setting to 10 is 3 chars more).

Notational preferences are a separate matter, of course. I imagine ?/!
may look pretty nice in code heavy on getting/setting nested JS
properties.

ClojureScript's set! also currently supports

(set! obj -prop val)

syntax (not supported by Clojure). The intention behind introducing
that was to enable the use of set! in place of aset in forms such as

(doto foo
  (set! "a" 1) ; could also use aset
  (set! "b" 2))

This also supports

(set! obj -prop.foo.bar val)

for nested props. There's no

(set! obj -prop -foo -bar val)

syntax, though.

Cheers,
Michał


On 12 May 2013 11:37, zcaudate <[email protected]> wrote:
> This is a quick and dirty release for interested parties. I found it very
> useful when working with angularjs. The syntax should not change that much
> but there will be more documentation in the future. I would love to have
> some input into additional features that could be added.
>
> Excerpt from Github: https://github.com/zcaudate/purnam
>
> Installation
>
> In your project file, add
>
> [purnam "0.0.9"]
>
> Why?
>
> Because the javascript dot-notation is awesome and the
> javascript/clojurescript interop (aget aset, .<fn> and .-<prop>accessors)
> make for really ugly code. Using the language-extension macros,
> clojurescript becomes more than twice as concise when working with existing
> javascript libraries (I'm mainly working with angularjs).
>
> So the use case can be seen below:
>
> Getters:
>
> ## javascript (12 keystrokes):
> object.a.b.c
>
> ## clojurescript (45 keystrokes):
> (-> object
>   (aget "a")
>   (aget "b")
>   (aget "c"))
>
> ## clojurescript + purnam (16 keystrokes):
> (? object.a.b.c)
>
> Setters:
>
> ## javascript (17 keystrokes):
> object.a.b.c = 10
>
> ## clojurescript (48 keystrokes):
> (-> object
>   (aget "a")
>   (aget "b")
>   (aset "c" 10))
>
> ## clojurescript + purnam (19 keystrokes):
> (! object.a.b.c 10)
>
> Functions:
>
> These are really bad examples of code but its what usually happens when
> working with existing javascript libraries. Using the dot-notation can save
> alot of screen and head space:
>
> ## javascript (~100 chars):
> var bad_code = function(obj, val){
>   obj.inner.number = 10;
>   val.inner.count = obj.inner.count + 10;}
>
> ## clojurescript (~180 chars):
> (defn bad-code [obj val]
>   (-> obj (aget "inner") (aset "number" 10))
>   (-> val
>       (aget "inner")
>       (aset "count"
>             (+ 10 (-> obj (aget "inner") (aget "count")))))
>   nil)
>
> ## clojurescript + purnam (~110 chars):
> (def.n bad-code [obj val]
>   (! obj.inner.number 10)
>   (! val.inner.count
>      (+ 10 obj.inner.count))
>   nil)
>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to