On Mon, Dec 12, 2011 at 10:54 AM, Razvan Rotaru <razvan.rot...@gmail.com> wrote: > Hi, > > I read that there's no such thing as lisp-like multiple values return > in clojure. We can use vectors, and the destructuring feature helps > also. > > However, for what I'm trying to do I need to emulate somehow the > following behavior: > - function returns a value which is a java instance (not possible to > change here, or at least not from what I see - it needs to be a java > instance) > - i need to be able to call some function which gets some values that > are not part of the java class > > My first intuition was "extend the base class" (thinking as a Java > programmer). But this is not possible. Not with proxy (which does not > allow new fields) and not with reify (which does not extend classes). > > So I'm thinking of using defrecords with protocols, where one slot > would be my java instance, and the rest would be my additional fields. > However I have a problem. Whenever my record value is used, I need to > use the java instance (sort of as a default field). > > For example: > > (defrecord myrecord [java-field myfield1 myfield2]) > > (def q (myrecord. java-intance "foo" "bar")) > > And then evaluation of q should be equivalent of (:java-field q). > This is nonsense, I know but I need some way to get around this. Any > idea would be greatly appreciated. > > (What I need is basically a workaround for the lisp-style multiple > values: in the default context, my value is evaluated to the java > instance, and with some special context I can get the values of other > fields as well.). > > Thanks, > Razvan >
(declare ^:dynamic *r2*) (defn function-with-two-return-values [x] (set! *r2* (dec x)) (inc x)) (binding [*r2* nil] (prn (function-with-two-return-values 1)) (prn *r2*)) > -- > 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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