Building a vector of vector list

2011-06-08 Thread Mushfaque Chowdhury
Hi all

I'm trying to build a vector data structure that can be printed using
the core prn function.

Here's my test case


(defn ea-xmi [dname  packages]
  [:xmi {:version 2.1
 :nsuml http://schema.omg.org/spec/UML/2.1;
 :nsxmi http://schema.omg.org/spec/XMI/2.1;
 :customprofile http://www.sparxsystems.com/profiles/
thecustomprofile/1.0}
   (map #(eval %) packages)])

(defn ea-document [dname  packages]
  [:Documentation {:exporter Enterprise Architect :exporterVersion
6.5}]
  [:Model {:type uml:Model :name (str/join [dname
_Model]) :visibility public}])

And this is how I want to call it:- (this I dont want to change - it's
the dsl)

(def output
  (ea-xmi Oil
(ea-document Fundamental)))

What I get as the output is:-
[:xmi {:version 2.1, :nsuml http://schema.omg.org/spec/UML/2.1, :nsxmi
http://sc
hema.omg.org/spec/XMI/2.1, :customprofile http://www.sparxsystems.com/profiles/t
hecustomprofile/1.0} ([:Model {:type uml:Model, :name
Fundamental_Model, :visibi
lity public}])]


Whereas I would want:-

[:xmi {:version 2.1, :nsuml http://schema.omg.org/spec/UML/2.1, :nsxmi
http://schema.omg.org/spec/XMI/2.1, :customprofile
http://www.sparxsystems.com/profiles/thecustomprofile/1.0} [:Model
{:type uml:Model, :name Fundamental_Model, :visibility public}]]

The difference is minimal, just the additional () around the second
vector. Why is this and how do I remove it (at construction time). I'm
guessing it's how I call eval within map, but I've tried identity and
apply and still can't get it right. Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Building a vector of vector list

2011-06-08 Thread Mushfaque Chowdhury
Thanks Meikel

I'm hoping that the into function is not going to make things
inefficient but I'll give it a go.

I also agree, eval is not what I want, because it does feel wrong.
Something tells me that I should be using apply, but I've not yet
figured out why/how.

Ronnie

On Jun 8, 2:07 pm, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 you just need a slight change in your ea-xmi function.

 (defn ea-xmi
   [dname  packages]
   (into [:xmi {:version 2.1
                :nsuml http://schema.omg.org/spec/UML/2.1;
                :nsxmi http://schema.omg.org/spec/XMI/2.1;
                :customprofile
 http://www.sparxsystems.com/profiles/thecustomprofile/1.0}]
         (map #(eval %) packages)))

 Note, that I am one of the eval-is-not-what-you-want advocates. So... The
 eval there is almost surely not what you want.

 Sincerely
 Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Building a vector of vector list

2011-06-08 Thread Mushfaque Chowdhury
Ahh yes, this works (with apply):-

(defn ea-xmi [dname  packages]
   (into [:xmi {:version 2.1
 :nsuml http://schema.omg.org/spec/UML/2.1;
 :nsxmi http://schema.omg.org/spec/XMI/2.1;
 :customprofile http://www.sparxsystems.com/profiles/
thecustomprofile/1.0}]
 (apply identity packages)))

What I want is just to call each function defined in 'packages'.
Basically evaluate the list of HigherOrderFunctions specified in
'packages'

If anyone can suggest something even cleaner, that would be great.

Ronnie
On Jun 8, 3:01 pm, Mushfaque Chowdhury mushfaque.chowdh...@gmail.com
wrote:
 Thanks Meikel

 I'm hoping that the into function is not going to make things
 inefficient but I'll give it a go.

 I also agree, eval is not what I want, because it does feel wrong.
 Something tells me that I should be using apply, but I've not yet
 figured out why/how.

 Ronnie

 On Jun 8, 2:07 pm, Meikel Brandmeyer m...@kotka.de wrote:







  Hi,

  you just need a slight change in your ea-xmi function.

  (defn ea-xmi
    [dname  packages]
    (into [:xmi {:version 2.1
                 :nsuml http://schema.omg.org/spec/UML/2.1;
                 :nsxmi http://schema.omg.org/spec/XMI/2.1;
                 :customprofile
  http://www.sparxsystems.com/profiles/thecustomprofile/1.0}]
          (map #(eval %) packages)))

  Note, that I am one of the eval-is-not-what-you-want advocates. So... The
  eval there is almost surely not what you want.

  Sincerely
  Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Example to introspect a class

2011-04-03 Thread Mushfaque Chowdhury
Thank you

I'm still learning all the different forms so this is very helpful.



On Apr 1, 10:13 pm, Ken Wesson kwess...@gmail.com wrote:
 On Fri, Apr 1, 2011 at 10:56 AM, Mushfaque Chowdhury









 mushfaque.chowdh...@googlemail.com wrote:
  Hi

  I'm trying to solve a introspection problem of the following type

  (def Region {'fields '((datatype x) (datatype y))})

  (def Country {'fields '((int x) (double y {reference `Region}))})

  I'd like to introspect the fields from Country and see {reference
  Region} replaced by (reference ((datatype x) (datatype y)))

  I can get as far as seeing this

  ((nth (nth (Country 'fields) 1) 2) 'reference)
  which gives
  (quote com.test.Common/Region)

  which is sort of close, but how do I now look at it's fields?

 First of all, that's not actually a class, it's a var.

 Second, does it actually need to be quoted a second level?

 Third, (second '(quote com.test.Common/Region)) will be the symbol
 com.test.Common/Region, and if you get that symbol into a local named
 foo, (ns-resolve *ns* foo) ought to yield up a Var object.

 And (@that-var 'fiels} then ought to cough up '((datatype x) (datatype y)).

 Indeed:

 user= (def Region {'fields '((datatype x) (datatype y))})
 #'user/Region

 user= (def Country {'fields '((int x) (double y {reference `Region}))})
 #'user/Country

 user= (@(ns-resolve (find-ns 'user) (nth ((nth (nth (Country 'fields)
 1) 2) 'reference) 1)) 'fields)
 ((datatype x)
  (datatype y))

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Example to introspect a class

2011-04-01 Thread Mushfaque Chowdhury
Hi

I'm trying to solve a introspection problem of the following type

(def Region {'fields '((datatype x) (datatype y))})

(def Country {'fields '((int x) (double y {reference `Region}))})

I'd like to introspect the fields from Country and see {reference
Region} replaced by (reference ((datatype x) (datatype y)))

I can get as far as seeing this

((nth (nth (Country 'fields) 1) 2) 'reference)
which gives
(quote com.test.Common/Region)

which is sort of close, but how do I now look at it's fields?

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en