[ANN] iroh 0.1.9 - class reflection and exploration

95 views
Skip to first unread message

zcaudate

unread,
Apr 10, 2014, 6:33:09 PM4/10/14
to clo...@googlegroups.com
A library for hacking and exploring the jvm:

Whats New

0.1.9

  • .> macro now supports both .accessors and :accessor calls
  • delegate added for better object support

0.1.6

Changed syntax:

  • .$ to .> (threading macro)
  • .> to .%> (display class hierachy)
  • Added .% (display class info)
  • Now .?.% and .%> works both on classes and instances

Installation

Add to project.clj dependencies:

[im.chit/iroh "0.1.9"]

For working in the repl or emacs, inject the core functionality into your clojure.core namespace using vinyasa by adding the following to your ~/.lein/profiles.clj file:

{:user {:dependencies [[im.chit/iroh "0.1.8"]
                       [im.chit/vinyasa "0.2.0"]]
         :injections [(require 'vinyasa.inject)
                      ....

                      (vinyasa.inject/inject 'clojure.core
                        '[[iroh.core delegate >ns >var .> .? .* .% .%>]])

                      ....]}}

------


delegate
 - Transparent Bean

Delegate does what bean does but it actually allows field access to the underlying object. This way, one can set and get values from the object :

(def a "hello")
a  ;;=> "hello" 

(def >a (delegate a))
>a ;;=> <java.lang.String@99162322 {:hash 99162322, :hash32 0, :value #<char[] [C@202cf33f>}>

@>a          ;;=> {:hash 99162322, :hash32 0, :value #<char[] [C@202cf33f>}
(keys >a)    ;;=> (:value :hash :hash32)
(>a :hash)   ;;=> 99162322
(:hash32 >a) ;;=> 0  
(>a :value (char-array "world")) ;;=> "world"

a ;;=> "world" (But I thought string where immutable!)


.>
 - Threading

A shorthand way of accessing private field is done by using .>:

(def a "hello")
(.> a :value) ;=> #<char[] [C@753f827a>
(.> a (:value (char-array "world")))
a ;;=> "world"


----



More on the website - https://github.com/zcaudate/iroh

zcaudate

unread,
Apr 10, 2014, 11:57:04 PM4/10/14
to clo...@googlegroups.com
Please use 0.1.10 update. clojure 1.6 does not load clojure.walk and clojure.set automatically anymore.

Moritz Ulrich

unread,
Apr 13, 2014, 3:17:24 PM4/13/14
to clojure
A simple repl-targeted library to introspect classes might prove
useful, but is there any reason to use such a short syntax for
everything? I'll surely have problems remembering the symbols.

On Fri, Apr 11, 2014 at 5:57 AM, zcaudate <z...@caudate.me> wrote:
> Please use 0.1.10 update. clojure 1.6 does not load clojure.walk and
> clojure.set automatically anymore.
>
> --
> 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/d/optout.

Chris Zheng

unread,
Apr 13, 2014, 4:04:02 PM4/13/14
to clo...@googlegroups.com
It's short because i hate typing... And it's meant to be 'intuitive' so that clojure users would find it relatively straight forward to pick up. The only unintuitive bit would be the .% and .%> for class information and class hierarchy. The thing is, when combined with the threading macro, all the functions are very powerful tools at the repl:

(.> 123 .%>) get class hierarchy
(.> 123 .?) get all methods
(.> 123 (.? :name)) get method name
(.> 123 .toString (.? :name)) get method names of (.toString 123)

Giveit a go! And if you have any suggestions for short names, please let me know.
> 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/YEeEMYmjfPM/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