Re: Clojure can't import some Java classes
So you are saying compilation is trying to instantiate class and run static initializers? This seems very backward, are you sure? On Sat, Oct 12, 2013 at 8:30 AM, Zach Oakes zsoa...@gmail.com wrote: I should add, I am aware I can bring in a class dynamically with Class/forName, and that is what I ended up doing for the Timer class. However, this is not always practical, and sometimes is simply not an option if aot-compilation is required. On Saturday, October 12, 2013 2:28:38 AM UTC-4, Zach Oakes wrote: I recently learned that merely importing a Java class in Clojure causes static initializers to be run. Sometimes, this causes compilation errors, because they are written with the assumption that they will only be run during runtime. I ran into this just now while trying to make a simple Clojure game with LibGDX. After simply importing its Timer class, I began getting compilation errors. The stack trace shows it is due to a static initializerhttps://github.com/libgdx/libgdx/blob/511b557c1a2d23bf8110a05b0ef54cc20b7f958d/gdx/src/com/badlogic/gdx/utils/Timer.java#L32attempting to instantiate the class! I also ran into this recently while trying to use RoboVM. My question is, do I have any options? I haven't found many discussions about this here or elsewhere. This surprises me, because it seems like something more people should be running into. -- -- 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. -- -- 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: Coding while running the program
I have no idea what the guy uses, neither am I a big fan of Eclipse as a tool for anything, but the one tool I do use on a daily basis is JRebel. It is basically a very smart classloader that observes the filesystem for newly compiled classes / copied resources (that happens on save in Eclipse, for example) and replaces them. This works orders of magnitude better than hot swap. Note: I am in no way associated with zeroturnaround (makers of jrebel), I am just a very satisfied user. On Sat, Mar 23, 2013 at 5:20 PM, Oskar Kvist oskar.kv...@gmail.com wrote: It's not about looking cool, it's about saving time. Den lördagen den 23:e mars 2013 kl. 16:03:19 UTC+1 skrev John Smith: If you want to make a game, then make a game. Don't worry about looking cool about it. You don't need to have some feature to make something entertaining :) . I'm making a game with a tool called GameMaker. Not as full-featured or powerful as with a programming language? Sure, but then I want to first have a game under my belt, then I'll worry about looking cool in the process :) . On Sat, Mar 23, 2013 at 10:22 AM, Oskar Kvist oskar...@gmail.com wrote: Hi! I saw this video http://www.youtube.com/**watch?v=BES9EKK4Aw4http://www.youtube.com/watch?v=BES9EKK4Aw4of Notch coding on Minecraft while the game was running, and of course seeing the changes in the running program. He used some kind of debug mode in his IDE (I don't really know which IDE). I want to make a game, and I want to to also be able to code while the program is running. I know this sort of thing is common in Lisps, so even without that IDE's debug mode it should be possible. Is there anything in particular that I need to do or look out for in order to make it work? Are there some JVM settings I should use? Does anyone know how that debug mode works? I kind of understand how it can be done with a plain repl, but I don't wanna miss out on anything that would make it easier. Any kind of insight is very appreciated. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@**googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@**googlegroups.com. For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out . -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to 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. -- -- 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.
macro: retrieving metadata for an object bound to a symbol passed as argument
Hi. I am writing a small library (for learning purposes) and there are a few macros. I have a macro that defines some object with the user-specified name and internal some metadata: (defmacro defobj [name operations] ; operations is a map `(def ~name (with-meta ~operations {::my-obj true}))) Then users (and the library itself will do it) can call it to define objects: (defobj testobj {}) (meta testobj) ; gives {:user/my-obj true} Now, I would like to create a macro that takes a name as an argument, and does something with the object, but first I would like to check if the object was created by 'defobj', i.e. check if the object's meta contains the key ::my-obj. That's what I can do, I don't know how to get the meta of the symbol: (defmacro with-obj [name] (let [obj-meta (meta name)] (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta))) (throw (IllegalArgumentException. (str name seems not be our object) `(println nice)) This always fails, as the meta is not fetched correctly; for example: (macroexpand '(with-obj testobj)) IllegalArgumentException clojure.core$name@48183a9a seems not be our object user/with-obj (NO_SOURCE_FILE:4) So I have a few questions: 1. should I attach the meta to the object, or to its var? or maybe I shouldn't do it at all, and just omit such checks altogether? (but I would still like to know how to make it work ;d) 2. how do I retrieve the meta of an object that is specified by a symbol passed to a macro by the user? 3. eventually, I would like my library to create a few default objects, so they would be in my namespace (say, 'my.lib'), and the users should be able to define their own objects as well in whatever namespace they wish; I would love it if the meta checking in the macro worked with objects in all namespaces, also if the symbols are namespaced or not 4. in the exception above, the symbol is resolved to the clojure.core/name, which is wrong as well; I know I can change the symbol name, but I have the feeling that this is not the way to go ;d Could anybody help me with the macro in question and fetching the meta? Regards, wujek -- 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: macro: retrieving metadata for an object bound to a symbol passed as argument
Thanks. If I use syntax-quoting, the error will be checked only at the time of executing the (macro-expanded) code, not at macro-expansion time, like some other checks I am performing. Is it possible to achieve what I want while the macro is called? The checks I am performing are some semantic checks, so maybe this should really be done later? I know metas are only available for IMetas, but my objects will always be clojure maps, so this shouldn't be a problem. Do you think I should apply the metadata to the symbol? Regards, wujek On Mon, Jan 14, 2013 at 3:34 PM, Jim foo.bar jimpil1...@gmail.com wrote: Of course you should know that built-in java types do not support meta-data...You need to implement IObj in order to provide meta-data support to your own types...otherwise use records... Jim On 14/01/13 14:32, Jim foo.bar wrote: On 14/01/13 14:27, wujek.sru...@gmail.com wrote: (defmacro with-obj [name] (let [obj-meta (meta name)] (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta))) (throw (IllegalArgumentException. (str name seems not be our object) `(println nice)) Try this: (defmacro with-obj [name] `(if-let [obj-meta# (meta ~name)] (println nice) (throw (IllegalArgumentException. (str ~name seems not be our object) HTH... Jim -- 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://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: macro: retrieving metadata for an object bound to a symbol passed as argument
Because this is not the whole functionality ;d The check is just a fragment, the one that doesn't work. There is much more to it, like taking the object, taking some keys and values and using them in (let) and then executing some code in this context (which is another parameter, which is not in my example as I wanted to keep it simple). If I could do it with a function, I would of course prefer it, but I am not sure if it can work. wujek On Mon, Jan 14, 2013 at 3:41 PM, Jim foo.bar jimpil1...@gmail.com wrote: Why does this have to be a macro? Why can't it be a first-class function instead? (defn with-obj [ob] (if-let [obj-meta (meta ob)] name (throw (IllegalArgumentException. (str ob seems not be our object) Jim On 14/01/13 14:34, Jim foo.bar wrote: Of course you should know that built-in java types do not support meta-data...You need to implement IObj in order to provide meta-data support to your own types...otherwise use records... Jim On 14/01/13 14:32, Jim foo.bar wrote: On 14/01/13 14:27, wujek.sru...@gmail.com wrote: (defmacro with-obj [name] (let [obj-meta (meta name)] (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta))) (throw (IllegalArgumentException. (str name seems not be our object) `(println nice)) Try this: (defmacro with-obj [name] `(if-let [obj-meta# (meta ~name)] (println nice) (throw (IllegalArgumentException. (str ~name seems not be our object) HTH... Jim -- 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://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: macro: retrieving metadata for an object bound to a symbol passed as argument
Actually, the with-object mecro is very similar to clojure.algo.monads/with-monad - it also lets a few bindings, like m-bind or m-result, and executes user-defined expressions in the context of the monad specified by a name. They just don't perform such checks, you can call with-monad with any symbol, and you will get an NPE: user= (require '[clojure.algo.monads :refer :all]) user= (domonad identity-m [a 2 b 3] (* a b)) 6 user= (domonad whatever [a 2 b 3] (* a b)) NullPointerException user/eval1803 (NO_SOURCE_FILE:1) That's probably because the monad functions set up by with-monad are nils. (domonad uses with-monad under the hood.) If I perform my check, I will be able to give a much nicer error message, and there is a lot value in that. wujek On Mon, Jan 14, 2013 at 3:45 PM, Wujek Srujek wujek.sru...@gmail.comwrote: Because this is not the whole functionality ;d The check is just a fragment, the one that doesn't work. There is much more to it, like taking the object, taking some keys and values and using them in (let) and then executing some code in this context (which is another parameter, which is not in my example as I wanted to keep it simple). If I could do it with a function, I would of course prefer it, but I am not sure if it can work. wujek On Mon, Jan 14, 2013 at 3:41 PM, Jim foo.bar jimpil1...@gmail.com wrote: Why does this have to be a macro? Why can't it be a first-class function instead? (defn with-obj [ob] (if-let [obj-meta (meta ob)] name (throw (IllegalArgumentException. (str ob seems not be our object) Jim On 14/01/13 14:34, Jim foo.bar wrote: Of course you should know that built-in java types do not support meta-data...You need to implement IObj in order to provide meta-data support to your own types...otherwise use records... Jim On 14/01/13 14:32, Jim foo.bar wrote: On 14/01/13 14:27, wujek.sru...@gmail.com wrote: (defmacro with-obj [name] (let [obj-meta (meta name)] (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta))) (throw (IllegalArgumentException. (str name seems not be our object) `(println nice)) Try this: (defmacro with-obj [name] `(if-let [obj-meta# (meta ~name)] (println nice) (throw (IllegalArgumentException. (str ~name seems not be our object) HTH... Jim -- 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://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: macro: retrieving metadata for an object bound to a symbol passed as argument
When I invoke a macro: (with-object someobject) someobject is not evaluated, it is passed as a symbol to the macro. I need somehow to get the meta for the object that is hidden behind that symbol. So, I won't be passing objects in-line, as you did in your Foo example, I will first be doing: (defobject foo {map of my functions / values}) (with-object foo (some-expressions)) Throwing an exception when meta is not there is one thing what I want (the missing part); the printing was just there to make the example shorter, it's not actually the real code - I don't need a macro for that. In reality, after all checks, there is code generated that desctructures the map in a (let) and executes some-expressions in this context, making certain bindings available for the expressions. This bit works fine, it's just the meta check that doesn't work as I don't know how to get the object that the symbol points to (in the macro, all I have is just a symbol): user= (def somename 17) #'user/somename user= (defmacro testabc [name] (class name)) #'user/testabc user= (testabc somename) clojure.lang.Symbol When I change the macro like this: user= (defmacro testabc [name] name) the object is returned: user= (testabc somename) 17 but it is because after macro expansion the returned symbol resolves to the object I set before. I would like to be able to get access to that object at macro call time. But when I come to think about it now, I guess this would be impossible? Are the vars available when the macro is called? i.e.: user= (def somename 17) user= (testabc somename) ; - in this macro, I need to take the 'somename' symbol and retrieve value 17 from above - is this possible at all? Thanks for your help, wujek On Mon, Jan 14, 2013 at 4:25 PM, Jim foo.bar jimpil1...@gmail.com wrote: I am not sure I follow...Do you by any chance want the macro-expansion to lead you directly to one of your two options (printing or exception)? In this case you can do this: (defmacro with-obj [ob] (if-let [obj-meta (meta ob)] (eval ob) ;not replacing any code but eval-ing on the fly (throw (IllegalArgumentException. (str ob seems not be our object) (defrecord Foo [a b]) user= (macroexpand '(with-obj Jim)) IllegalArgumentException Jim seems not be our object user/with-obj (NO_SOURCE_FILE:3) user= (macroexpand '(with-obj (with-meta (Foo. 'x 'y) {:t 1 :p 2}))) #user.Foo{:a x, :b y} So now you get the exception or the actual object at macro-expansion time...Does that help at all? Jim On 14/01/13 14:56, Wujek Srujek wrote: Actually, the with-object mecro is very similar to clojure.algo.monads/with-monad - it also lets a few bindings, like m-bind or m-result, and executes user-defined expressions in the context of the monad specified by a name. They just don't perform such checks, you can call with-monad with any symbol, and you will get an NPE: user= (require '[clojure.algo.monads :refer :all]) user= (domonad identity-m [a 2 b 3] (* a b)) 6 user= (domonad whatever [a 2 b 3] (* a b)) NullPointerException user/eval1803 (NO_SOURCE_FILE:1) That's probably because the monad functions set up by with-monad are nils. (domonad uses with-monad under the hood.) If I perform my check, I will be able to give a much nicer error message, and there is a lot value in that. wujek On Mon, Jan 14, 2013 at 3:45 PM, Wujek Srujek wujek.sru...@gmail.comwrote: Because this is not the whole functionality ;d The check is just a fragment, the one that doesn't work. There is much more to it, like taking the object, taking some keys and values and using them in (let) and then executing some code in this context (which is another parameter, which is not in my example as I wanted to keep it simple). If I could do it with a function, I would of course prefer it, but I am not sure if it can work. wujek On Mon, Jan 14, 2013 at 3:41 PM, Jim foo.bar jimpil1...@gmail.comwrote: Why does this have to be a macro? Why can't it be a first-class function instead? (defn with-obj [ob] (if-let [obj-meta (meta ob)] name (throw (IllegalArgumentException. (str ob seems not be our object) Jim On 14/01/13 14:34, Jim foo.bar wrote: Of course you should know that built-in java types do not support meta-data...You need to implement IObj in order to provide meta-data support to your own types...otherwise use records... Jim On 14/01/13 14:32, Jim foo.bar wrote: On 14/01/13 14:27, wujek.sru...@gmail.com wrote: (defmacro with-obj [name] (let [obj-meta (meta name)] (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta))) (throw (IllegalArgumentException. (str name seems not be our object) `(println nice)) Try this: (defmacro with-obj [name] `(if-let [obj-meta# (meta ~name)] (println nice) (throw (IllegalArgumentException. (str ~name seems not be our object) HTH... Jim -- You received this message because you are subscribed to the Google Groups
Re: macro: retrieving metadata for an object bound to a symbol passed as argument
Hi. Yes, the (eval `(meta ~name)) did the trick, it also seems to be working the way I would like it to in terms of namespaces, which is great! I must confess that I don't fully grok why it has to be that way (syntax-quote plus syntax escape plus eval), but I will just have learn more and hopefully I some day I will ;d Maybe this can be written easier, but this is good enough for me now. Thank you again, you've been of great help. As for the meta for vars or objects, check this out: user= (def ^:var-meta testtest ^:obj-meta {:fn wujek}) #'user/testtest user= (meta testtest) {:obj-meta true} user= (meta (var testtest)) {:ns #Namespace user, :name testtest, :var-meta true, :line 1, :file NO_SOURCE_PATH} So the metas are different. You said yourself that only IMetas are supported as meta targets, which can be shown here: user= (def ^:var-meta testtest2 ^:obj-meta 17) #IllegalArgumentException java.lang.IllegalArgumentException: Metadata can only be applied to IMetas If metas were always applied to vars, there would be no difference as I guess all vars can habe metadata. wujek On Mon, Jan 14, 2013 at 5:28 PM, Jim foo.bar jimpil1...@gmail.com wrote: aaa ok now I understand what you meanI'm really sorry but I hadn't read all your original questions. So lets set things straight: 1. should I attach the meta to the object, or to its var? or maybe I shouldn't do it at all, and just omit such checks altogether? (but I would still like to know how to make it work ;d) meta-data are always attached on the var if I'm not mistaken... 2. how do I retrieve the meta of an object that is specified by a symbol passed to a macro by the user? the general answer here is that you use ~ inside a syntax-quote to jump right out of the quoting which results in evaluating the expression. If you're not in a syntax-quoted form then I can only think of 'eval' which will resolve the var anyway... 4. in the exception above, the symbol is resolved to the clojure.core/name, which is wrong as well; I know I can change the symbol name, but I have the feeling that this is not the way to go ;d I'm not sure how to answer this...I know what t do inside the macro to avoid symbol capturing but I'm not sure what to do in the actual parameter list of the macro... So, with all these in place I'd say you're looking for something like this: (defmacro with-obj [ob] (if-let [obj-meta (eval `(meta ~ob))] (println nice) (throw (IllegalArgumentException. (str ob seems not be our object) Let's see how it works: user= (def my-name JIM) #'user/my-name user= (defrecord NAME [^String s]) user.NAME user= (def your-name (NAME. Wujek {:surname Srujek} nil)) ;;your-name has meta-data #'user/your-name user= (macroexpand '(with-obj my-name)) IllegalArgumentException my-name seems not be our object user/with-obj (NO_SOURCE_FILE:4) user= (macroexpand '(with-obj your-name)) nice nil I think we 're getting there yes? Is this more helpful? Jim On 14/01/13 15:46, Wujek Srujek wrote: When I invoke a macro: (with-object someobject) someobject is not evaluated, it is passed as a symbol to the macro. I need somehow to get the meta for the object that is hidden behind that symbol. So, I won't be passing objects in-line, as you did in your Foo example, I will first be doing: (defobject foo {map of my functions / values}) (with-object foo (some-expressions)) Throwing an exception when meta is not there is one thing what I want (the missing part); the printing was just there to make the example shorter, it's not actually the real code - I don't need a macro for that. In reality, after all checks, there is code generated that desctructures the map in a (let) and executes some-expressions in this context, making certain bindings available for the expressions. This bit works fine, it's just the meta check that doesn't work as I don't know how to get the object that the symbol points to (in the macro, all I have is just a symbol): user= (def somename 17) #'user/somename user= (defmacro testabc [name] (class name)) #'user/testabc user= (testabc somename) clojure.lang.Symbol When I change the macro like this: user= (defmacro testabc [name] name) the object is returned: user= (testabc somename) 17 but it is because after macro expansion the returned symbol resolves to the object I set before. I would like to be able to get access to that object at macro call time. But when I come to think about it now, I guess this would be impossible? Are the vars available when the macro is called? i.e.: user= (def somename 17) user= (testabc somename) ; - in this macro, I need to take the 'somename' symbol and retrieve value 17 from above - is this possible at all? Thanks for your help, wujek On Mon, Jan 14, 2013 at 4:25 PM, Jim foo.bar jimpil1...@gmail.com wrote: I am not sure I follow...Do you by any chance want the macro-expansion to lead you directly
All the ways to define metadata (and ^:static)
Hi. I am currently learning clojure, which is a nice experience, but you all know that. I have question about certain metadata definitions, which I couldn't find a straight answer to on the net, and in none of the books I'm reading: 1. is ^:dynamic the same as ^{:dynamic true}, just a shortcut? 2. is (def ^:dynamic ^:blah x) the same as (def ^{:dynamic true :blah true} x)? My tests show that the answer to the first 2 questions is yes, but I can't seem to find anything that would back that up. 3. why so many ways to do the same? 4. what does ^:static do? I read on SO that it is not used any more, but the source code in clojure.core still has these, and various tutorials use them as well. 5. since when does one need to use ^:dynamic on vars to be able to use (binding [...]) to rebind them thread-locally? Clojure in Action has a nice example of a simple mocking framework that uses this feature but without dynamic, but it is about clj 1.2 I think. 1.3 seems to require it though. Regards, wujek -- 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: All the ways to define metadata (and ^:static)
Thanks. Yes, I know about ^String being ^{:tag String} because it is mentioned all over the place. ^:dynamic is not. Thanks for the links, I haven't seen them before, and they do clear this issue up. On Wed, Jan 9, 2013 at 10:03 AM, Andy Fingerhut andy.finger...@gmail.comwrote: On Jan 9, 2013, at 12:37 AM, wujek.sru...@gmail.com wrote: Hi. I am currently learning clojure, which is a nice experience, but you all know that. I have question about certain metadata definitions, which I couldn't find a straight answer to on the net, and in none of the books I'm reading: 1. is ^:dynamic the same as ^{:dynamic true}, just a shortcut? Yes. 2. is (def ^:dynamic ^:blah x) the same as (def ^{:dynamic true :blah true} x)? Yes. My tests show that the answer to the first 2 questions is yes, but I can't seem to find anything that would back that up. I don't know where else this might be documented, other than the Clojure source code, but one place is on the Clojure cheatsheet, in the section called Metadata, subsection Abbrevs for Abbreviations: http://clojure.org/cheatsheet http://jafingerhut.github.com There you will also see that ^String is an abbreviation for ^{:tag String}, and in general ^Type for ^{:tag Type} 3. why so many ways to do the same? Clojure developers thought it would be nice to have shorter ways to write metadata expressions that simply set a key's value to true, or annotated the type, since those are quite common cases. I am not sure about the answers to the questions below off-hand. Hopefully someone else can address them. Andy 4. what does ^:static do? I read on SO that it is not used any more, but the source code in clojure.core still has these, and various tutorials use them as well. 5. since when does one need to use ^:dynamic on vars to be able to use (binding [...]) to rebind them thread-locally? Clojure in Action has a nice example of a simple mocking framework that uses this feature but without dynamic, but it is about clj 1.2 I think. 1.3 seems to require it though. Regards, wujek -- 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: All the ways to define metadata (and ^:static)
So take this definition from master: (def ^{:arglists '([x]) :doc Return true if x implements ISeq :added 1.0 :static true} seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x))) static is used twice here. What is / was the difference? Is it correct to say that it is now just noise in the code and could be stripped away? Is it correct to say it has nothing to do with 'dynamic', contrary to what the last SO post in the topic you linked to implies? wujek On Wed, Jan 9, 2013 at 3:24 PM, Philip Potter philip.g.pot...@gmail.comwrote: On 9 January 2013 08:37, wujek.sru...@gmail.com wrote: 4. what does ^:static do? I read on SO that it is not used any more, but the source code in clojure.core still has these, and various tutorials use them as well. This SO thread seems to describe it well: http://stackoverflow.com/questions/7552632/what-does-static-do-in-clojure Is there anything you're still unsure about? 5. since when does one need to use ^:dynamic on vars to be able to use (binding [...]) to rebind them thread-locally? Clojure in Action has a nice example of a simple mocking framework that uses this feature but without dynamic, but it is about clj 1.2 I think. 1.3 seems to require it though. You're quite right, this changed in 1.3. It's even the first entry in the 1.3 changelog: https://github.com/clojure/clojure/blob/clojure-1.3.0/changes.txt which reads: 1.1 Earmuffed Vars are No Longer Automatically Considered Dynamic The old convention was that vars surrounded with *earmuffs* were automatically considered dynamic and appropriate for a (binding [...]) form. Now, everything must be explicitly made dynamic using ^:dynamic. Phil -- 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
clojure.core/ns documentation glitch?
The documentation of clojure.core/ns says nearly to the end of its docstring: If :refer-clojure is not used, a default (refer 'clojure) is used. Shouldn't it say that a default (refer 'clojure.core) is used? -- 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