question about clojure.lang.LazySeq.toString()
Hi, I'm curious, why doesn't toString of clojure.lang.LazySeq return the entire sequence as a String, and returns the Java pointer instead? I find it annoying when I do this: user (str (map + [1 2 3])) clojure.lang.LazySeq@7861 What's the reason behind this decision? Shouldn't toString trigger the evaluation of the sequence? Doesn't it do that for other values, like numbers and vectors? Is there an alternative to the code above (preferably simple and elegant), which will return the etire sequence? Thanks, Răzvan -- -- 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 --- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: mixins/multiple inheritance
Thanks, This works, but there's a problem: the labeledtextfield is not a textfield anymore, it's a label. Therefore it does not behave like a textfield (which implements other protocols as well). I need multiple inheritance, in one way or another. I've been trying to find a way to implement with multimethods. For example, if label was a mixin, then it means I could do something like this: (def textfield (new TextField Foo) (def labeledtextfield (new (mix TextField Label) Name Foo)) (render textfield) ;= [Foo] (render labeledtextfield) ;= Name: [Foo] Oh, and I'd like to stay away from macros, if possible. :) Razvan On Feb 6, 12:20 pm, Matthias Diehn Ingesman matdi...@gmail.com wrote: It sounds a little like the decorator pattern would do the trick for you in this case - am I missing something? In case I am not, I have given it a shot using records and protocols: (defrecord TextField [text]) (defrecord DatetimePicker [datetimes]) (defrecord Label [text widget]) (defprotocol Renderable (render [this])) (extend-protocol Renderable TextField (render [this] (str [ (:text this) ])) DatetimePicker (render [this] (apply str (:datetimes this))) Label (render [this] (str (:text this) : (render (:widget this) (comment (def textfield (TextField. Foo)) (def datetimepicker (DatetimePicker. [:yesterday :today :tomorrow])) (def labeledtextfield (Label. Name textfield)) (def labeleddatetimepicker (Label. Date datetimepicker)) (render textfield) ;= [Foo] (render datetimepicker) ;= :yesterday:today:tomorrow (render labeledtextfield) ;= Name: [Foo] (render labeleddatetimepicker) ;= Date: :yesterday:today:tomorrow ) 1/ is handled by the Renderable implementation for Label calling the Renderable implementation on whatever widget it decorates with a label. 2/ is handled by having the Label decorator widget as a record. Regards, Matthias -- 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
mixins/multiple inheritance
Hi, I found some posts about this topic, but they did not clarify things in my head well enough, so I have to start my own... :) I'm basically craving for multiple inheritance or mixins, at least with my current way of thinking. I haven't really gone deep enough with multimethods or protocols, so I might be a little off track by looking for multiple inheritance. Let's take an example: I want to implement some gui widgets, so there's a main method render which draws the widget on the screen. I want to have two types: - Textfield - Datetimepicker Each can be mixed with the Label widget, so that we have: - LabelledTextfield - LabelledDatetimepicker So, two challenges occur: 1/ the render method for Label needs to call the render method for it's mixed widget (either Textfield or Datetimepicker) - let's assume that labels are rendered around the actual widget, so that we have a simple way to mix the implementations of render method 2/ the Label widget comes with its own data (the label text) For the second thing, I think it will work with defrecords, since the label can be a map entry which can be stored in the actual widget, even if it's not mixed with Label. I still want to point this out in case there are other ways of achieving this. How can I achieve 1? Are there alternatives for 2? Thanks for reading, Razvan -- 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
filter out null values
Hi, What's the clojure way to filter out null values from a sequence? I have following code: (filter identity (map myfun myseq)) Is there a better/faster way? Thanks, Razvan -- 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: proxy with dynamic
Yes, it's more clear now. Thanks. -- 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
weird quote/unquote usage
Hi, Consider following code: (defprotocol WithOptions (getOptions [this] All options) (getOption [this option] One option)) (defn- gen-proxy [klass opts] `(proxy [~klass WithOptions] [] (getOptions [~'_] ~opts) (getOption [~'this x#] ((getOptions ~'this) x# The gen-proxy functions is a helper which is used in macros. The code works, as far as I can tell, but there's one thing that intrigues me: the usage of unquote/quote is necessary (~'_ and ~'this). I assume it has something to do with macros qualifying symbols with the current namespace. I am yet to fully understand the mechanism here, but my question for the moment is whether this kind of construct is idiomatic in clojure. Or is there another way to introduce symbols in macros? Thanks, Razvan -- 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: proxy with dynamic
On Dec 25, 12:01 pm, Alan Malloy a...@malloys.org wrote: Presumably you just tried it and found it doesn't work, so I'm not sure what more you're looking for here. How would you even fill in the body of the proxy? I don't know what class this is, but I know exactly what methods I need to override? Probably you need to rethink some things to get a design that doesn't require something so magical, but eval is always available to you if you have some reason to believe you require magic. Yes, eval. I forgot about it. Eval is something I categorized as dangerous in my mind a long time ago, and decided never to use it. It seems that I also erased it from my memory. :) My expectation here is that proxy expects a value which for the base class, which is a java class (an instance of java.lang.Class), and I'd like to pass this value as a function parameter. From design point of view, my proxy contruct tries to add an interface to a class. (Like a mixin). The interface is always the same (and therefore the methods), but the class can be anything, and i'd like to have it as a parameter to the function. Macros work fine, but I want to try to have it as a function. Razvan -- 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: proxy with dynamic
On Dec 25, 1:17 pm, Meikel Brandmeyer m...@kotka.de wrote: Hi, Wiring to classes happens in the bytecode and hence have to be known at compile time. You either have to use eval or refrain from doing things at runtime. Is the class transferred into your program at runtime without knowing it up-front? If not, macros should sufficient. Sincerely Meikel I'm not sure I understand your question. The class is known, but it's transfered as an instance of java.lang.Class. I also don't quite understand your argument. Clojure creates classes dynamically (e.g. deftype), so why not create a proxy dynamically? Razvan -- 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: weird quote/unquote usage
Thanks. Razvan -- 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: multiple return values
On Dec 23, 5:08 am, Alan Malloy a...@malloys.org wrote: It turns out even this is not true, becauseproxyuses some kind of deep JVM magic called (appropriately)ProxyClasses. So every time you write (proxy[Object] (...anything at all...)), you get an instance of the same class, initialized with a different map of function pointers. That is, for any superclass and set of interfaces, exactly oneproxy class exists (possibly one per namespace?), of which all suchproxy objects are instances. This sounds good. Thanks. -- 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: multiple return values
On Dec 14, 5:33 pm, Tom Faulhaber tomfaulha...@gmail.com wrote: Razvan, I believe that proxy actually only creates a new class per call site, not per instance. However, I can't completely swear to this. Anyone with more detailed knowledge than I have want to comment? Assuming I'm right,, you should be fine to have lots of instances. HTH, Tom What do you mean by site? For example, how is it when I'm creating my proxy inside a macro? (and assuming this macro is called many times) (defmacro [a-class] (proxy (a-class) )) Razvan -- 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
unquote-splicing when calling macro
Hi, This may sound a bit weird, but can I unquote-splice something when calling a macro. Here's an attempt to do this with hiccup: (defn get-header [[:link {:type text/css ...}] [:script {:type text/javascript ...}]]) (html [:head (get-header) ...] [:body ...]) The result of get-header needs to spliced into the rest of the structure for the html macro to work. Thanks, Razvan -- 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: unquote-splicing when calling macro
Great. Thanks. On Dec 17, 6:08 pm, Baishampayan Ghose b.gh...@gmail.com wrote: This may sound a bit weird, but can I unquote-splice something when calling a macro. Here's an attempt to do this with hiccup: (defn get-header [[:link {:type text/css ...}] [:script {:type text/javascript ...}]]) (html [:head (get-header) ...] [:body ...]) The result of get-header needs to spliced into the rest of the structure for the html macro to work. You can use either `apply` or `into` here - (apply vector :head (get-header)) (into [:head] (get-header)) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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: unquote-splicing when calling macro
I just found out that it also works like this: (defn get-header (list [:link {:type text/css ...}] [:script {:type text/javascript ...}]]) (html [:head (get-header) ...] [:body ...]) They key here is not to return a vector. If the html macro encounters another kind of sequence, it does the splicing that I want. Razvan On Dec 17, 6:32 pm, Razvan Rotaru razvan.rot...@gmail.com wrote: Great. Thanks. On Dec 17, 6:08 pm, Baishampayan Ghose b.gh...@gmail.com wrote: This may sound a bit weird, but can I unquote-splice something when calling a macro. Here's an attempt to do this with hiccup: (defn get-header [[:link {:type text/css ...}] [:script {:type text/javascript ...}]]) (html [:head (get-header) ...] [:body ...]) The result of get-header needs to spliced into the rest of the structure for the html macro to work. You can use either `apply` or `into` here - (apply vector :head (get-header)) (into [:head] (get-header)) Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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: multiple return values
Thanks. On Dec 14, 8:30 pm, Alan Malloy a...@malloys.org wrote: Correct, just like closures and reifies. On Dec 14, 7:33 am, Tom Faulhaber tomfaulha...@gmail.com wrote: Razvan, I believe that proxy actually only creates a new class per call site, not per instance. However, I can't completely swear to this. Anyone with more detailed knowledge than I have want to comment? Assuming I'm right,, you should be fine to have lots of instances. HTH, Tom On Dec 13, 10:47 am, Razvan Rotaru razvan.rot...@gmail.com wrote: Thanks Tom. Using proxy like this could work. But i'm worried about one thing.What happens if I have many instances? With proxy there's a new class with each instance. Could I run out of permgen space? On Dec 13, 9:38 am, Tom Faulhaber tomfaulha...@gmail.com wrote: Razvan, I think that you can implement your idea of extending the class with proxy in the following way (originally suggested to me by Rich Hickey Chris Houser for use with the pretty printer): (let [extra-fields (ref {:field1 extra-value1, :field2 extra-value2}] (proxy [Writer IDeref] (deref [] extra-fields) (write [x] ...) other funcs)) You don't need to make the extra-values item a ref if you will set the values immutably at create time. You can see the full example of this athttps://github.com/clojure/clojure/blob/1f11ca3ef9cd0585abfbe4a9e7609... The rest of that module is an abomination that was written when I was still under the influence of CLOS O-O. Hope that helps, Tom On Dec 12, 5:10 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote: - 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 You should approach such a need with great trepidation: [org.jboss.netty/netty 3.2.7.Final] (import 'org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap) (def ^:private asides (ConcurrentIdentityWeakKeyHashMap.)) (defn function-with-two-return-values [...] (let [retval ...] (.put asides retval extra-data) retval)) (let [x (function-with-two-return-values ...)] (prn x) (prn (.get asides x))) -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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
letrec
Hi, Is there a reliable implementation of letrec in clojure? Anybody using it? I have found a post from 2008, with an implementation which I don't understand (and it's said to be slow), and which I don't know whether to trust.(It's also supposed to be slow). Thanks, Razvan -- 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: letrec
I don't quite understand why people are saying this. Anyway, It's not enough for me. On Dec 14, 9:13 pm, Kevin Downey redc...@gmail.com wrote: lazy-seq and letfn should cover anything you would need letrec for On Wed, Dec 14, 2011 at 11:09 AM, Razvan Rotaru razvan.rot...@gmail.com wrote: Hi, Is there a reliable implementation of letrec in clojure? Anybody using it? I have found a post from 2008, with an implementation which I don't understand (and it's said to be slow), and which I don't know whether to trust.(It's also supposed to be slow). Thanks, Razvan -- 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
Re: letrec
letfn defines functions. I'm just defining some values. The values contain anonymous functions which need to refer to other values.I know there are workarounds for this, but this means I must change the interface. Razvan On Dec 14, 9:56 pm, David Nolen dnolen.li...@gmail.com wrote: On Wed, Dec 14, 2011 at 2:53 PM, Razvan Rotaru razvan.rot...@gmail.comwrote: I don't quite understand why people are saying this. Anyway, It's not enough for me. What can't you solve your problem with what was suggested? David -- 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: letrec
Yes. Assuming I have following macros: (button :id b1 :listener #(...)) = (let [b1 (new JButton)] ...) (panel [:id p1] (button :id b1 ...) (button :id b2 ...)) = (let [p1 (new JPanel) b1 (button :id b1 ...) b2 (button :id b2 ...)] ...) How to make the listener in b1 refer to b2? Razvan On Dec 14, 11:09 pm, David Nolen dnolen.li...@gmail.com wrote: Do you have a minimal example of what you are trying to do? On Wed, Dec 14, 2011 at 3:53 PM, Razvan Rotaru razvan.rot...@gmail.comwrote: letfn defines functions. I'm just defining some values. The values contain anonymous functions which need to refer to other values.I know there are workarounds for this, but this means I must change the interface. Razvan On Dec 14, 9:56 pm, David Nolen dnolen.li...@gmail.com wrote: On Wed, Dec 14, 2011 at 2:53 PM, Razvan Rotaru razvan.rot...@gmail.com wrote: I don't quite understand why people are saying this. Anyway, It's not enough for me. What can't you solve your problem with what was suggested? David -- 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 -- 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: multiple return values
Thanks Tom. Using proxy like this could work. But i'm worried about one thing.What happens if I have many instances? With proxy there's a new class with each instance. Could I run out of permgen space? On Dec 13, 9:38 am, Tom Faulhaber tomfaulha...@gmail.com wrote: Razvan, I think that you can implement your idea of extending the class with proxy in the following way (originally suggested to me by Rich Hickey Chris Houser for use with the pretty printer): (let [extra-fields (ref {:field1 extra-value1, :field2 extra-value2}] (proxy [Writer IDeref] (deref [] extra-fields) (write [x] ...) other funcs)) You don't need to make the extra-values item a ref if you will set the values immutably at create time. You can see the full example of this athttps://github.com/clojure/clojure/blob/1f11ca3ef9cd0585abfbe4a9e7609... The rest of that module is an abomination that was written when I was still under the influence of CLOS O-O. Hope that helps, Tom On Dec 12, 5:10 pm, Stephen Compall stephen.comp...@gmail.com wrote: On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote: - 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 You should approach such a need with great trepidation: [org.jboss.netty/netty 3.2.7.Final] (import 'org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap) (def ^:private asides (ConcurrentIdentityWeakKeyHashMap.)) (defn function-with-two-return-values [...] (let [retval ...] (.put asides retval extra-data) retval)) (let [x (function-with-two-return-values ...)] (prn x) (prn (.get asides x))) -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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: multiple return values
I don't want to change the interface i'm exposing to the outer world. May be that I'm thinking too javaish, but what I miss here is a possibility to extend the base class. :) On Dec 12, 9:31 pm, James Reeves jree...@weavejester.com wrote: On 12 December 2011 18:54, Razvan Rotaru razvan.rot...@gmail.com wrote: - 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) Why does it need to be a Java instance? - James -- 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: multiple return values
Thanks. I don't know how this hashmap works, but at the first glance there seems to be one problem: the two values don't get garbage collected at the same time. I'll look more into it, thanks. On Dec 13, 3:10 am, Stephen Compall stephen.comp...@gmail.com wrote: On Mon, 2011-12-12 at 10:54 -0800, Razvan Rotaru wrote: - 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 You should approach such a need with great trepidation: [org.jboss.netty/netty 3.2.7.Final] (import 'org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap) (def ^:private asides (ConcurrentIdentityWeakKeyHashMap.)) (defn function-with-two-return-values [...] (let [retval ...] (.put asides retval extra-data) retval)) (let [x (function-with-two-return-values ...)] (prn x) (prn (.get asides x))) -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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
multiple return values
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 -- 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: java reflection during macro
Thanks. I was missing the call to resolve. (let [klass (resolve c)] ) With it it works. Razvan On Dec 8, 11:39 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Not sure if it helps, but here's my example of using reflection in a macro: http://stuartsierra.com/2010/12/16/single-abstract-method-macro -S -- 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
java reflection during macro
Hi, I'm trying to write some macros for java object instanciation. Here's the code: (defn- gen-object-method [my-class id option value] (let [method (some (java-methods option) (map #(.getName %) (.getMethods my-class)))] (when (not method) (throw (new java.lang.IllegalArgumentException (str A method for option was not found in class component-class (list (symbol (str . method)) id value))) (defmacro gen-java-code [my-class body] (gen-object-method myclass ~id arg val) ) Function gen-object-method is called from a macro (that tries to generate java code). My problem is that my-class is a symbol and not a java class, so that (.getMethod ) fails with No matching field found: getMethods for class clojure.lang.Symbol [Thrown class java.lang.IllegalArgumentException] How can I check in a macro that a particular java method exists for a class or not? Thanks, Razvan -- 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
on lisp and scheme macros
Hi everyone, I was searching the web these days trying to find out more about these two macro systems and understand their differences, and why one is preferable over the other (or not). I'd like to share with you some ideas, and hopefully get some opinions back as well. Coming from the lisp side, and without much knowledge on scheme macros, I'm also trying to decide for myself whether scheme macros can have a (practical) advantage. One good point (found here http://lambdagrok.wikidot.com/forum/t-194636) I think explains it pretty well: lisp macros merely transform a list into another, while scheme macros use a pattern matching sub- language to apply transformations on the input syntax, and produce new syntax. I think this puts the finger on the spot. It seems to me that with macros, scheme breaks out of the homoiconicity of lisp, and opens up a new array of possibilities: define new languages with bdifferent/b syntax (while lisp allows new languages but with the same syntax). I'm saying this by looking at Racket and the direction it has chosen to go (have a look at Typed Scheme and Datalog). This looks like the world turned upside down: the pattern matching macro system is the essence of the system, and scheme is just another language defined with it. The list is not that important anymore, since it's not so essential for the macro system. Now, I have read some opinions which say that most who choose the scheme macros, make it for the pattern matching abilities and not for the hygienic part. This seems like a reasonable thing to do, since I don't hear lispers complain about unhygienicity. If there are people out there who had some practical experience with scheme macros, I hope they read this post and share some thoughts. I have a feeling that there's an additional gain with scheme macros: debugging information given by the system when something goes wrong. But it's only a feeling, I know too little of this subject to be sure. Macros are hard to debug. The stacktrace displayed by clojure does not contain information related to macro code. It's probably hard to do. My feeling relates to the fact that in scheme macro processing is not arbitrary, but rather strictly defined and under control. So I'm thinking that this gives scheme more control over what's going on in a macro and also enables scheme to give me more information in a stacktrace. I'd love to hear other opinions on this. Another point I find peculiar is the small attention that scheme macros got during all these years. I wonder why it's like that. It could be scheme's low score for practical stuff, but then again I don't know of another language that borrows these kind of macros. Does anybody know? And lastly, a question to Rich Hickey, should he read this post: what is the reasoning behind the choice of lisp macros over scheme's? Cheers, Razvan -- 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: on lisp and scheme macros
Wow. I didn't thought this was possible. You know, I have seen a lot of people saying that scheme macros are more powerfull, citing the fact that scheme also has lisp macros, while it's not possible to do it the other way around. On Dec 4, 2:06 am, Scott Jaderholm jaderh...@gmail.com wrote: Scheme style macros in Clojure:https://github.com/qbg/syntax-rules Scott On Sat, Dec 3, 2011 at 1:20 PM, Razvan Rotaru razvan.rot...@gmail.comwrote: Hi everyone, I was searching the web these days trying to find out more about these two macro systems and understand their differences, and why one is preferable over the other (or not). I'd like to share with you some ideas, and hopefully get some opinions back as well. Coming from the lisp side, and without much knowledge on scheme macros, I'm also trying to decide for myself whether scheme macros can have a (practical) advantage. One good point (found herehttp://lambdagrok.wikidot.com/forum/t-194636) I think explains it pretty well: lisp macros merely transform a list into another, while scheme macros use a pattern matching sub- language to apply transformations on the input syntax, and produce new syntax. I think this puts the finger on the spot. It seems to me that with macros, scheme breaks out of the homoiconicity of lisp, and opens up a new array of possibilities: define new languages with bdifferent/b syntax (while lisp allows new languages but with the same syntax). I'm saying this by looking at Racket and the direction it has chosen to go (have a look at Typed Scheme and Datalog). This looks like the world turned upside down: the pattern matching macro system is the essence of the system, and scheme is just another language defined with it. The list is not that important anymore, since it's not so essential for the macro system. Now, I have read some opinions which say that most who choose the scheme macros, make it for the pattern matching abilities and not for the hygienic part. This seems like a reasonable thing to do, since I don't hear lispers complain about unhygienicity. If there are people out there who had some practical experience with scheme macros, I hope they read this post and share some thoughts. I have a feeling that there's an additional gain with scheme macros: debugging information given by the system when something goes wrong. But it's only a feeling, I know too little of this subject to be sure. Macros are hard to debug. The stacktrace displayed by clojure does not contain information related to macro code. It's probably hard to do. My feeling relates to the fact that in scheme macro processing is not arbitrary, but rather strictly defined and under control. So I'm thinking that this gives scheme more control over what's going on in a macro and also enables scheme to give me more information in a stacktrace. I'd love to hear other opinions on this. Another point I find peculiar is the small attention that scheme macros got during all these years. I wonder why it's like that. It could be scheme's low score for practical stuff, but then again I don't know of another language that borrows these kind of macros. Does anybody know? And lastly, a question to Rich Hickey, should he read this post: what is the reasoning behind the choice of lisp macros over scheme's? Cheers, Razvan -- 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 -- 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
keyword arguments
Hi, This may be a question without hope, but I'm thinking that asking never hurts. So here goes: The closest thing to keyword arguments that I have found is destructuring with a map: (defn myfun [ {:keys [arg1 arg2 arg3] :or {arg1 default-value} :as args}] ...) When I call myfun without specifying value for arg2 or arg3 I get an error, which is great. However, when I do this: (myfun :arg2 2 :arg3 3 :arg15 15) I don't get an error, because of the rest () thing. Do you know if this can be achieved with a nice syntax, and not check args in the code (i.e. checking should be done when evaluating/creating the function, and not when executing). Thanks, Razvan -- 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: appengine-magic + servlets
Yes, I tried that but did not work. appengine-magic/serve expects an appengine-application, which is a map that among others contains the ring handler. The serve function turns this handler into a servlet and maps it to the root path / (or /*, I haven't figured that out yet). Whatever i write in web.xml is apparently overwritten by appengine-magic/serve, or web.xml does not matter at all when starting the server with appengine-magic/serve. I have only one servlet, which is in the external jar. I don't have a ring handler or a second servlet. I just want to feed this servlet to appengine-magic. Thanks, Razvan On Nov 6, 10:43 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm still having trouble figuring out what it is you are wanting to do, but if you have an existing Java servlet that will handle some url pattern, and you want to write an appengine-magic app that will create a servlet to handle some other url pattern, and use both servlets in one app engine app, then you should be able to add the jar as a dependency to your project such that the jar ends up in war/WEB-INF/lib, and setup that servlet and url pattern in web.xml just as you normally would, and setup the appengine-magic servlet to handle some other desired url pattern. On Sun, Nov 6, 2011 at 3:24 PM,RazvanRotaru razvan.rot...@gmail.com wrote: The servlet is coming from an external jar, which is written in Java. I need appengine-magic for the other services, like datastore. Razvan On Nov 6, 7:45 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm still not quite following. What appengine-magic does is provides Clojure wrappers for many of the App Engine for Java service APIs, and from a ring handler creates a servlet suitable for deployment to App Engine. If you already have the servlet, I'm not sure why you need appengine-magic. Where is this servlet coming from? And what are you wanting to do with it once you have integrated it with appengine-magic? - Mark On Sun, Nov 6, 2011 at 11:41 AM,RazvanRotaru razvan.rot...@gmail.com wrote: I want integration of servlet in appengine-magic. Documentation describes that you use a ring handler to call def- appengine-app: (appengine-magic.core/def-appengine-app my-app #'my-ring-handler) I have a servlet and want to build an application, something like: (appengine-magic.core/def-appengine-servlet-app my-app #'my-servlet) Razvan On Nov 6, 4:32 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm not using ring, I have a servlet which I need to feed to appengine-magic. Not sure what you mean by this, could you expand on it a little more? You have an existing Java servlet that you want to handle some url pattern, and you want to integrate that into your appengine-magic app? On Sun, Nov 6, 2011 at 5:08 AM,RazvanRotaru razvan.rot...@gmail.com wrote: Hi, appengine-magic (https://github.com/gcv/appengine-magic) uses ring- handlers to turn into servlets that are accepted by GAE. Does anybody know how to use servlets directly with appengine-magic? I'm not using ring, I have a servlet which I need to feed to appengine-magic. Thanks, Razvan -- 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 -- 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 -- 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 -- 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
appengine-magic + servlets
Hi, appengine-magic (https://github.com/gcv/appengine-magic) uses ring- handlers to turn into servlets that are accepted by GAE. Does anybody know how to use servlets directly with appengine-magic? I'm not using ring, I have a servlet which I need to feed to appengine-magic. Thanks, Razvan -- 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: problems of a newbie
I remember having the same frustrations some time ago. Not that they are gone now. :) It obviously depends on the tool, and these code analysis you describe you get only in IDEs. I don't know what tool you are using now, but you have them all described in the Getting Started page (http:// dev.clojure.org/display/doc/Getting+Started). My experience is only with vim + slimv (http://www.vim.org/scripts/ script.php?script_id=2531) + swank-clojure (https://github.com/ technomancy/swank-clojure), and I can tell you it's far from what you are looking for. Emacs + slime + swank-clojure is probably better, but not by much. I would recommend Intellij + La Clojure (without actually having tried it myself), and that's because of the emphasis of Intellij on these analysis tools. La Clojure seems to be supported by JetBrains, and that gives it a big potential. However it seems that in the lisp world, code analysis tools are that wanted. We have Common Lisp for quite some time now, and people seem quite happy with slime. Razvan On Nov 5, 2:16 pm, Dennis Haupt d.haup...@googlemail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi, i'm half done with my asteroids clone. i stumbled over a few problems and wanted to know how others already solved them :) i am used to less concrete programming. i ask my tools to do the actual analysis and coding for me: * where is that used? * rename that * show me all errors * add a parameter here * autocomplete this for me, i am too lazy to even remember the exact method name * show me a list of all methods and fields starting with an e that fit in here. i know the one i want is in that list. as elegant as clojure may be as a language, it's dragging me down to almost native text editing which i did more than 10 years ago when i wrote a game in turbo pascal. how did you solve these problem and get some tool-support? or don't you miss it because of something i am not aware of? -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOtSkdAAoJENRtux+h35aGeeQP+gJbQdNSZEdEIgjVFC/VZvRe z1Rh9Z8xVwxbuyl/kx1GMLU3jZxJKkhp0OIp7RLbDgjwFFzwBnQ0CZSeuHd9bFD/ S5Vmf6tXB4AdC3u3a7wZilEQuSuq+ARtJhMKdGIQfoXgqDYA7JwOvV8ZkpiR2T2d pKqswheRVstBqo9/xyinfuLsJMujDlF9NshoIC0n1b/L4tzddq/kgzIATcg/NJ4N I0Qd1lqGC1THU2nHtiaSR66KQE5Ciq22FN0nVoT3jW9EU/kJ9tao7L6SUTY3tcaA th8mxKLYId/NrbRmsYUTyWe6O30HAUTLLFEnImYTW2fUMdwRYeAoZGc7t5V3yJ/p dU4JN0dGA/ADbdTItykaao1DtGI2/kGe6p9VaKk3IPCVAOio9UwgOCUQylTKqy7M CWbrDcSFCQs5pTY1Sw5We9LV2VOBoTsai6vH/qE7t98mJLVf0wHvLLIBOkf/QO5a HuSyCJRpOrWQF2jbooDqAbaJAa6huxLQjMeO9Ri4sDx2gDRYsf9Fmdjp4TFWWjdZ O5HEzhUR165peQHo4RQLLf8dnlkibsdbx60n+VJ0E4iE7ID+hBOFC76bAllnAS1K Q8HqXUogMi/ZLXIAB4BA83q71IEDVcytuYAn9Ku2FQLrmWCiOD57uMhSLjtzK/8J TIuaLwipARdzsqi/piwl =MnRq -END PGP SIGNATURE- -- 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: appengine-magic + servlets
I want integration of servlet in appengine-magic. Documentation describes that you use a ring handler to call def- appengine-app: (appengine-magic.core/def-appengine-app my-app #'my-ring-handler) I have a servlet and want to build an application, something like: (appengine-magic.core/def-appengine-servlet-app my-app #'my-servlet) Razvan On Nov 6, 4:32 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm not using ring, I have a servlet which I need to feed to appengine-magic. Not sure what you mean by this, could you expand on it a little more? You have an existing Java servlet that you want to handle some url pattern, and you want to integrate that into your appengine-magic app? On Sun, Nov 6, 2011 at 5:08 AM, Razvan Rotaru razvan.rot...@gmail.com wrote: Hi, appengine-magic (https://github.com/gcv/appengine-magic) uses ring- handlers to turn into servlets that are accepted by GAE. Does anybody know how to use servlets directly with appengine-magic? I'm not using ring, I have a servlet which I need to feed to appengine-magic. Thanks, Razvan -- 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 -- 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: appengine-magic + servlets
The servlet is coming from an external jar, which is written in Java. I need appengine-magic for the other services, like datastore. Razvan On Nov 6, 7:45 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm still not quite following. What appengine-magic does is provides Clojure wrappers for many of the App Engine for Java service APIs, and from a ring handler creates a servlet suitable for deployment to App Engine. If you already have the servlet, I'm not sure why you need appengine-magic. Where is this servlet coming from? And what are you wanting to do with it once you have integrated it with appengine-magic? - Mark On Sun, Nov 6, 2011 at 11:41 AM, Razvan Rotaru razvan.rot...@gmail.com wrote: I want integration of servlet in appengine-magic. Documentation describes that you use a ring handler to call def- appengine-app: (appengine-magic.core/def-appengine-app my-app #'my-ring-handler) I have a servlet and want to build an application, something like: (appengine-magic.core/def-appengine-servlet-app my-app #'my-servlet) Razvan On Nov 6, 4:32 pm, Mark Rathwell mark.rathw...@gmail.com wrote: I'm not using ring, I have a servlet which I need to feed to appengine-magic. Not sure what you mean by this, could you expand on it a little more? You have an existing Java servlet that you want to handle some url pattern, and you want to integrate that into your appengine-magic app? On Sun, Nov 6, 2011 at 5:08 AM, Razvan Rotaru razvan.rot...@gmail.com wrote: Hi, appengine-magic (https://github.com/gcv/appengine-magic) uses ring- handlers to turn into servlets that are accepted by GAE. Does anybody know how to use servlets directly with appengine-magic? I'm not using ring, I have a servlet which I need to feed to appengine-magic. Thanks, Razvan -- 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 -- 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 -- 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: shortcut for anonymous function literal and syntax quote
Yeah, you are probably right. But I figured asking never hurts... Thanks for the reply. Razvan On Oct 19, 10:50 pm, Alan Malloy a...@malloys.org wrote: Not really. In _Let Over Lambda_'s section on reader macros, he creates a reader macro #`(foo bar a1 a2) that expands to (lambda (a1 a2) `(foo bar ,a1 ,a2)), but this is not possible in Clojure. A nice example of something you can do with reader macros, in case Clojure ever gets them. And you could certainly write it yourself as a regular macro, at the expense of a syntax that's almost as long as the (fn [x] `(foo)) syntax. But really, that construct is very short, and worrying about the extra six characters you would save by writing it with #() seems like wasted effort to me. On Oct 19, 1:14 pm,RazvanRotaru razvan.rot...@gmail.com wrote: Hi, I'm just wondering is there a nicer way to write this: (defmacro my-macro [ body] (map (fn[x] `(my-fun ~x)) body)) I'd like to use the anonymous function literall #(), but this won't work: (defmacro my-macro [ body] (map #(`(my-fun ~%)) body)) So if you have some suggestion, I'd be glad to hear it. Thanks, Razvan -- 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: Can't eval locals problem
Thanks for your suggestion. I finally decided to find a way around the problem. :) This is cutting too deep for me to handle with my current clojure knowledge. I also talked to Constantine Vetoshev (the author of appengine-magic) and he anknowledged it as an issue which could have a solution by changing the query macro. So, for the moment I'm waiting for a new version. Thanks anyway. I really appreciate the activity on this group. Razvan On Oct 3, 11:49 pm, Michał Marczyk michal.marc...@gmail.com wrote: Ok, so I mailed off the above discussion without including any suggestions for alternative approaches... *fail* Anyway, I think Joop's answer (especially the first code snippet) is *very* likely to be the best. As far as I can tell from reading the source, appengine-magic's query macro includes the filter expression in its expansion verbatim, so it will just be evaluated at run time. If you do want to play around with some super-flexible eval-based approaches, you might want to give Michael Fogus's highly enjoyable evalive library [1] a try -- it provides an aptly named #'evil function which, together with its companion macro #'local-bindings (or was it #'local-env...), does allow one more flexibility in what one evals. The usual warnings (don't eval unless you have to etc.) apply. Sincerely, Michał [1]https://github.com/fogus/evalive -- 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
shortcut for anonymous function literal and syntax quote
Hi, I'm just wondering is there a nicer way to write this: (defmacro my-macro [ body] (map (fn[x] `(my-fun ~x)) body)) I'd like to use the anonymous function literall #(), but this won't work: (defmacro my-macro [ body] (map #(`(my-fun ~%)) body)) So if you have some suggestion, I'd be glad to hear it. Thanks, Razvan -- 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
how to use record as a value
Hi, I want to instantiate a record, but having the record type as value at runtime. Example: (defrecord car [year manufacturere]) (defrecord bike [year manufacturere]) (defrecord boat [year manufacturer]) I want to do (new stuff 1982 Mercedes), but having the record type kept in the variable stuff. Something like: (let [stuff car] (new stuff 1982 Mercedes)) (let [stuff bike] (new stuff 1990 Harley Davidson)) Obviously new does not work. I'm gratefull for suggestions of how to do it best. Thanks, Razvan -- 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: how to use record as a value
Wow, that was fast. Thanks. This could work but only partially. (let [stuff car] (new stuff 1982 Mercedes) (new stuff 2001 Seat) ...) I could take advantage of the fact that records are maps: (let [stuff (car. 1982 Mercedes)] ... use Mercedes... (assoc stuff :year 2001 :manufacturer Seat)) But this will work only if all my types have the same parameters. If bike would be: (defrecord bike [manufacturer year type]) then i'm stuck again. Razvan On Oct 6, 8:32 pm, Aaron Bedra aaron.be...@gmail.com wrote: Assuming you want to do things with the record later, why not just create it in the let binding (let [foo (-car 1982 Mercedes)] ...) or (let [foo (car. 1982 Mercedes)] ...) or even (let [foo (map-car {:year 1982 :manufacturer Mercedes})] ...) or if you must (let [foo #user.car{:year 1982 :manufacturer Mercedes}] ...) Cheers, Aaron Bedra -- Clojure/corehttp://clojure.com On 10/06/2011 01:27 PM, Razvan Rotaru wrote: Hi, I want to instantiate a record, but having the record type as value at runtime. Example: (defrecord car [year manufacturere]) (defrecord bike [year manufacturere]) (defrecord boat [year manufacturer]) I want to do (new stuff 1982 Mercedes), but having the record type kept in the variable stuff. Something like: (let [stuff car] (new stuff 1982 Mercedes)) (let [stuff bike] (new stuff 1990 Harley Davidson)) Obviously new does not work. I'm gratefull for suggestions of how to do it best. Thanks, Razvan -- 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: how to use record as a value
This is what I'm looking for. Thanks. I have not seen this kind of expression before: -foo. Is is created by defrecord or is it implemented at reader level? I realize now that I can also keep a generating function in the variable stuff: (let [stuff #(car. %1 %2)] (stuff 1982 Mercedes) (stuff 2011 Seat)) But keeping the actual constructor is of course better. RR On Oct 6, 8:56 pm, Meikel Brandmeyer m...@kotka.de wrote: Hi, use the factory function. Clojure 1.3.0 user= (defrecord car [year manufacturer]) user.car user= (defn create [stuff] (stuff 1982 Mercedes Benz)) #'user/create user= (create -car) #user.car{:year 1982, :manufacturer Mercedes Benz} You can't pass car. around at runtime because it is a class. And instantiating a class is hard-wired in the byte code. Hence the actual class must be known at compile time. -car however is a normal clojure function. So you can pass it around as you like. 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
Can't eval locals problem
Ok, so I'm stuck. If any of you more seasoned clojurians have a hint that could get me out, I will be forever gratefull to him/her: I'm trying execute a query against google app engine datastore, using appengine-magic, with the filter dynamically generated from a map. Here's the closest code I have been able to come up with: (defmacro order-query [params] `(ds/query :kind Order :filter ~(map #(list (key %) (val %)) (eval params This macro fails with a Can't eval locals error. I recognize that the main issue here is that i'm forcing evaluation of something at macro expansion time. Apparently clojure does not (fully) support this, so I'm looking then for alternatives. Cheers, Razvan -- 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
metadata for records
Hi, Is there a way to attach metadata to defrecord ? Razvan -- 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
get keys from defrecord
Hi, Assuming I have: (defrecord myrecord [:a :b :c]) is there a way to get the list of keys from the record definition? Thanks, Razvan -- 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
Cyclic load dependency
Hi, I'm trying to use r0man / appengine-clj, and when :use-ing the datastore namespace I get a cyclic load dependency. Doesn't clojure allow such cyclic references? (use 'appengine.datastore) Cyclic load dependency: [ /appengine/datastore/entities ]-/appengine/ datastore/query-[ /appengine/datastore/entities ]-/appengine/ datastore [Thrown class java.lang.Exception] Restarts: 0: [QUIT] Quit to the SLIME top level Backtrace: 0: clojure.core$check_cyclic_dependency.invoke(core.clj:4817) 1: clojure.core$load.doInvoke(core.clj:4912) 2: clojure.lang.RestFn.invoke(RestFn.java:408) 3: clojure.core$load_one.invoke(core.clj:4729) 4: clojure.core$load_lib.doInvoke(core.clj:4766) 5: clojure.lang.RestFn.applyTo(RestFn.java:142) 6: clojure.core$apply.invoke(core.clj:542) 7: clojure.core$load_libs.doInvoke(core.clj:4800) 8: clojure.lang.RestFn.applyTo(RestFn.java:137) 9: clojure.core$apply.invoke(core.clj:544) Cheers, Razvan -- 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: bug in partition?
Thanks. But still I don't get something. Shouldn't partition return a sequence? Shouldn't every sequence end with nil? Razvan -- 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: Vim Nailgun setup - access to REPL from outside Vim
You may also want to have a look at slimv. http://www.vim.org/scripts/script.php?script_id=2531 It performs quite nice (can't compare it with vimclojure though, 'cause I don't know vimclojure). Razvan -- 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: bug in partition?
Thanks for the hint. And don't worry about the meaning of this function. :) Name parameter has no use. And the regex stuff's for the url. Razvan -- 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
bug in partition?
Hi, Not sure if this is a novice thing or a real bug. Here's what I encountered: I'm calling a Java method which returns a String[], which I then pass to partition to get a list of lists (I know, sequence, but list is a shorter word). What happens then, is I loop over my list of lists with (loop .. (recur (rest ...))) and as the very last thing I get an empty list instead of nil. This doesn't look ok to me, but then again I could be terribly wrong since I rather novice in clojure. Here's the code (never mind the complete lack of logic in this function - it's been stripped): (defn authenticate? [uri name pass] (loop [user-pass (partition 2 (.getStringArray *conf* authentication))] (if user-pass (if (re-matches (re-pattern (ffirst user-pass)) uri ) true (recur (rest user-pass))) false) )) Calling this function throws a NullPointerException. Any hint is greatly appreciated. Thanks, Razvan -- 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: History Question
I think it returns :a rather than just a so that you can print stuff, then read it back in and it would be the same. You can use it to dump configuration data to a file for example then load it later easily. Razvan On Thu, May 6, 2010 at 10:21 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, or as-str from c.c.java-utils (I think) 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.comclojure%2bunsubscr...@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 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: Examples of Clojure in production?
FlightCaster were just mentioned in a recent thread. They use Incanter in production: http://measuringmeasures.com/ Razvan -- 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
sorted-set-by drops elements
Hi, Is this the intended behavior? (sorted-set-by (constantly 0) 1 2 3 4) returns #{1}. I would expect the set to contain all the elements, and the comparator to only affect sort order. Razvan -- 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: sorted-set-by drops elements
Why should sorting be related to the primary key? You should be able to sort on any attribute. If you wanted to sort a set of people by age would it make sense to only retain one person of each age? Sort order and identity should be orthogonal. Besides, if you need a collection based on primary keys then a map or a sorted map is more appropriate, and if you chose a set instead you probably expect operations on that set to take into account the entire element. Raz -- 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: Extending Clojure's STM with external transactions
Cool stuff, Dave. I'm interested to see/test it, could you post it as an attachment to this group or commit it to contrib ? Cheers, Razvan. On Dec 8, 9:08 pm, Dave Griffith [EMAIL PROTECTED] wrote: Okay, hacking complete. I've got a patch that extends the Clojure STM so that it will make appropriate callouts to an external transaction manager that cause the STMs transaction to be atomic/consistent/ isolated with respect to an external transaction, using a dosync- external macro. Note that this is not the same as XA support. The Clojure STM is in charge of the transaction as a whole, not the external transaction manager. (Among other things, this means that transactions can not span multiple transaction managers. You'll get an exception if you try.) The external transaction manager must implement the clojure.lang.ITransactionManager interface, which means that to use any given external transaction manager you will need to implement a small adapter to that interface, and instantiate it appropriately. This code is highly experimental, and should not be used for production purposes. Contents may have settled during shipping. All models over 18. Where should I send the patch? --Dave Griffith --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Re: Extending Clojure's STM with external transactions
Hi Dave. I think your proposal would be useful to have in Clojure, I have thought about something similar since I read about the STM. But I also think there are quite a few difficulties in implementing this in a sane way. Actually, the more I think about it, the more it seems that the goal of STM (to aid concurrent programming at a micro-level) is not really compatible with that of traditional transactions (to enable persistent and consistent changes to a shared resource, at an application/system level). Here are some observations: 1. Normal transactions A successful commit on an external transaction can be (and usually is) a side-effect, so it breaks the assumption that transactional operations are side-effect free and can be retried by the STM. Thus Clojure would need to recognize this as a special case and treat it as a composite transaction, which can not be retried entirely. I don't know how STM is implemented in Clojure. Maybe if the external commit can be delayed until the end of the transaction, when it is certain that the in-memory operations succeeded, it could work. I think this is the most promising way of implementing this. 2. XA transactions If Clojure's STM works similar to an XA transaction, it would still be difficult to delegate the coordination to a JTA transaction manager. XA-capable resources MUST have stable storage for crash recovery, which definitely isn't the case (and also wouldn't make sense) with the STM. The STM guarantees ACI, external transactions are usually ACID, so there's a conceptual mismatch between the two. If you think about it, why would you want to have transactions between a transient and a durable resource ? Also, XA resources must be prepared to handle the case of an heuristic commit, when all resources confirmed the prepare stage, but not the final commit. This situation does not exist with pure STM, so one would have to be aware of the risk and settle for less guarantees when using composite transactions. Razvan. On Dec 4, 1:38 am, Rich Hickey [EMAIL PROTECTED] wrote: On Dec 3, 3:48 pm, Dave Griffith [EMAIL PROTECTED] wrote: It often happens that I would like to have gaurantees about the consistency of in-memory data structures and external resources. For instance, in the last two large systems I've built, the system would respond to an external message received via socket, do some complex processing based on the contents of the message which modified it's internal state, write a log of the message to a database and update some other database tables so that the internal state of the system was reconstructable in case of crash, and then send some other messages to clients via socket. This all had to either work, or not work, with full ACID properties for the system as a whole (both the database and memory). This was an enormous pain, requiring in-memory rollback functionality to be coded by hand for each and every possible interaction. It seems like it should be possible to extend the STM semantics of Clojure to allow this sort of thing to Just Work. From the user point of view, one would call dosync-external, rather than dosync, and pass it an external (JTA?) transaction manager along with the operations to be executed. If either the in-memory operations or the external operations required rollback, then both would be, otherwise both would be committed. If committed, any agent sends that the transaction had sent would occur. Simple to use, and pretty much exactly what's required for a high-reliability message processing engine. Literally thousands of lines of code would disappear from each of my last two projects. Looking over the current implementation of Clojure, I think I've convinced myself of the following facts. 1) This can't be done purely in Clojure code itself, as the necessary hooks into the STM don't exist (nor, I would argue, should they). 2) This could be done pretty easily by hacking the Clojure runtime, at a (obviously excessive) cost of inducing a hard dependency between the core runtime and some particular transaction manager. The STM implementation already has enough of a two-phase commit structure to make it pretty easy to integrate with any given transaction management system. 3) Creating some sort of plugin system so that arbitrary transaction managers could be integrated with the Clojure STM runtime is doable, but doesn't much fit with the current architecture. 4) If one were to do such a thing, it would be pretty easy to extend the STM with features like timeouts and such. Thoughts? Am I missing anything? Has this already been attempted in some way I was unable to google for? My temptation is to try to implement something as a quick spike and see how it works. It's definitely an interesting idea - I don't think anyone is working on it. I don't have enough knowledge of JTA/XA to do it myself, but could provide advice about
Re: Distributed concurrent applications in Clojure?
@dokondr: the blackboard mechanism you mention is just a distributed associative memory, and there is already a Java specification for such a system (search for Jini and Javaspaces), with several open source and commercial implementations available. Unfortunately, anyone who has ever worked with such a mechanism can probably tell you how difficult it is to go beyond some simple use cases. Also, the fact that it's not language agnostic (Javaspaces works with Java objects) doesn't actually make it better, since it imposes big limitations on the objects you can use efficiently with this mechanism. There are other limitations I have encountered in my work with such systems, mostly related to the lack of support tools (administration, monitoring, etc). From my experience with distributed Java applications, JMS is generally a good fit for most systems. It offers transactions (even XA) and persistence, which are both necessary more often than not in such systems, while the API is simple. Additionally, most JMS implementations can be clustered (giving you fail-over and/or load- balancing functionality) and the message content can be language agnostic. Implementing even a subset of these features naitvely in Clojure would represent a very big effort, and for what gains? A JMS wrapper library for Clojure would make much more sense, especially if it could integrate with the STM (a successful JMS commit has side- effects, so maybe this is impossible ) / Agent support. Also, there are good implementations and support tools for JMS, since it's been around for a long time. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---