Re: Why isn't a docstring allowed for defrecord?
(Point. x y) is resolved as if Point. was a special form. Nothing Lisp-2 about it. :) On Thu, Oct 31, 2013 at 11:48 AM, Mars0i marsh...@logical.net wrote: OK, I get it now. By using Point. I'm ... temporarily descending into the Java world, on top of which Clojure is built. By using -Point I remain in the more harmonious Clojure world, which usually hides the darkness of Java from me. (No offense meant to Java afficionados. One of the things I love about Clojure is its Java interop.) On Thursday, October 31, 2013 10:38:31 AM UTC-5, Mauricio Aldazosa wrote: On Thu, Oct 31, 2013 at 9:15 AM, Mars0i mars...@logical.net wrote: Excellent. Thanks Tassilo. I had attempted to do the same sort of thing using Point. rather than -Point which didn't work: user = (doc Point.) nil user= Point. CompilerException java.lang.ClassNotFoundException: Point., compiling:(NO_SOURCE_PATH:0:0) user= -Point #user$eval254$__GT_Point__269 user$eval254$__GT_Point__269@ 3c90fa05 I had assumed that Point. and -Point were the same thing, but they are apparently not. -Point names something real, while Point. is just some kind of magic, I guess. The thing to remember here is that by defining a record you are creating a new Java class. As a convenience a factory function (Point-) is created for you, but you can always create instances of your record via the constructor (Point.). Point. is a macro that expands to (new Point). Take a look at http://clojure.org/datatypes for an introduction of what is going on when you use defrecord and http://clojure.org/java_ interop#Java%20Interop-The%20Dot%20special%20form-(new% 20Classname%20args*) for the constructor documentation. Mauricio -- -- 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: Why isn't a docstring allowed for defrecord?
Jim - FooBar(); jimpil1...@gmail.com writes: Ok my bad...for a second there I thought that a defrecord expression returns a Var but it doesn't. It returns a Class object. You can't put anything on that therefore 'doc' won't work on it anyway. Hm, well, the only thing a record has to document are its fields. (The methods should already be documented by the protocols.) And since a defrecord generates a constructor function -MyRecord, you could alter its metadata. --8---cut here---start-8--- user (defrecord Point [x y]) user.Point user (doc -Point) - user/-Point ([x y]) Positional factory function for class user.Point. nil user (alter-meta! #'-Point update-in [:doc] str \n x and y are the coordinates.) {:ns #Namespace user, :name -Point, :arglists ([x y]), :column 1, :doc Positional factory function for class user.Point.\n x and y are the coordinates., :line 1, :file /tmp/form-init3254591993268451432.clj} user (doc -Point) - user/-Point ([x y]) Positional factory function for class user.Point. x and y are the coordinates. nil --8---cut here---end---8--- I think that it would be useful if defrecord would have an optional docstring (or just mangle :doc metadata attached to the record name) that would be appended to the generated docstring like above. (Ditto for deftype.) Bye, Tassilo -- -- 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: Why isn't a docstring allowed for defrecord?
Excellent. Thanks Tassilo. I had attempted to do the same sort of thing using Point. rather than -Point which didn't work: user = (doc Point.) nil user= Point. CompilerException java.lang.ClassNotFoundException: Point., compiling:(NO_SOURCE_PATH:0:0) user= -Point #user$eval254$__GT_Point__269 user$eval254$__GT_Point__269@3c90fa05 I had assumed that Point. and -Point were the same thing, but they are apparently not. -Point names something real, while Point. is just some kind of magic, I guess. user= (def Point. 5) #'user/Point. user= Point. CompilerException java.lang.ClassNotFoundException: Point., compiling:(NO_SOURCE_PATH:0:0) The fact that Point. is associated with the record type Point causes this. I'll stick to using the - syntax from now on. Less confusing. (Also, I didn't know in detail how to perform the alter-meta! operation. Looks pretty ugly, but it's easy enough to wrap it up in a function.) On Wednesday, October 30, 2013 11:19:33 AM UTC-5, Mars0i wrote: I understand that defrecord can't take a docstring (see Doc string for variables and record in this group), and I have learned that record types are somewhat odd beasts. I know that there are workarounds ( http://clojure-log.n01se.net/date/2010-10-03.html). Still, I'm surprised. *Why* can't I document a record type with a docstring? It seems like extremely useful coding practice to provide a docstring for a type. Even if the underlying semantics would be weird and special-cased, well, that's already true for record types. -- -- 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: Why isn't a docstring allowed for defrecord?
On the other hand, the behavior of Point. might be considered a good thing (or not): user= (defrecord Point [x y]) user.Point user= (meta #'Point.) CompilerException java.lang.RuntimeException: Unable to resolve var: Point. in this context, compiling:(NO_SOURCE_PATH:6:1) user= (meta #'-Point) {:ns #Namespace user, :name -Point, :arglists ([x y]), :column 1, :doc Positional factory function for class user.Point., :li ne 5, :file NO_SOURCE_PATH} user= (def -Point 42) #'user/-Point user= -Point 42 user= (-Point 3 2) ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval245 (NO_SOURCE_FILE:10) user= (Point. 3 2) #user.Point{:x 3, :y 2} user= (def Point. 43) #'user/Point. user= (Point. 3 2) #user.Point{:x 3, :y 2} I can't clobber Point. by def'ing it. It's as if Clojure turns into a Lisp-2 in this one special case. -- -- 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: Why isn't a docstring allowed for defrecord?
The Java class lifecycle and namespaces/vars are separate sorts of 'resolution contexts', but they're (un)fortunately deeply tied together. On Thu, Oct 31, 2013 at 11:24 AM, Mars0i marsh...@logical.net wrote: On the other hand, the behavior of Point. might be considered a good thing (or not): user= (defrecord Point [x y]) user.Point user= (meta #'Point.) CompilerException java.lang.RuntimeException: Unable to resolve var: Point. in this context, compiling:(NO_SOURCE_PATH:6:1) user= (meta #'-Point) {:ns #Namespace user, :name -Point, :arglists ([x y]), :column 1, :doc Positional factory function for class user.Point., :li ne 5, :file NO_SOURCE_PATH} user= (def -Point 42) #'user/-Point user= -Point 42 user= (-Point 3 2) ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn user/eval245 (NO_SOURCE_FILE:10) user= (Point. 3 2) #user.Point{:x 3, :y 2} user= (def Point. 43) #'user/Point. user= (Point. 3 2) #user.Point{:x 3, :y 2} I can't clobber Point. by def'ing it. It's as if Clojure turns into a Lisp-2 in this one special case. -- -- 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: Why isn't a docstring allowed for defrecord?
On Thu, Oct 31, 2013 at 9:15 AM, Mars0i marsh...@logical.net wrote: Excellent. Thanks Tassilo. I had attempted to do the same sort of thing using Point. rather than -Point which didn't work: user = (doc Point.) nil user= Point. CompilerException java.lang.ClassNotFoundException: Point., compiling:(NO_SOURCE_PATH:0:0) user= -Point #user$eval254$__GT_Point__269 user$eval254$__GT_Point__269@3c90fa05 I had assumed that Point. and -Point were the same thing, but they are apparently not. -Point names something real, while Point. is just some kind of magic, I guess. The thing to remember here is that by defining a record you are creating a new Java class. As a convenience a factory function (Point-) is created for you, but you can always create instances of your record via the constructor (Point.). Point. is a macro that expands to (new Point). Take a look at http://clojure.org/datatypes for an introduction of what is going on when you use defrecord and http://clojure.org/java_interop#Java%20Interop-The%20Dot%20special%20form-(new%20Classname%20args*)for the constructor documentation. Mauricio -- -- 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: Why isn't a docstring allowed for defrecord?
OK, I get it now. By using Point. I'm ... temporarily descending into the Java world, on top of which Clojure is built. By using -Point I remain in the more harmonious Clojure world, which usually hides the darkness of Java from me. (No offense meant to Java afficionados. One of the things I love about Clojure is its Java interop.) On Thursday, October 31, 2013 10:38:31 AM UTC-5, Mauricio Aldazosa wrote: On Thu, Oct 31, 2013 at 9:15 AM, Mars0i mars...@logical.net javascript: wrote: Excellent. Thanks Tassilo. I had attempted to do the same sort of thing using Point. rather than -Point which didn't work: user = (doc Point.) nil user= Point. CompilerException java.lang.ClassNotFoundException: Point., compiling:(NO_SOURCE_PATH:0:0) user= -Point #user$eval254$__GT_Point__269 user$eval254$__GT_Point__269@3c90fa05 I had assumed that Point. and -Point were the same thing, but they are apparently not. -Point names something real, while Point. is just some kind of magic, I guess. The thing to remember here is that by defining a record you are creating a new Java class. As a convenience a factory function (Point-) is created for you, but you can always create instances of your record via the constructor (Point.). Point. is a macro that expands to (new Point). Take a look at http://clojure.org/datatypes for an introduction of what is going on when you use defrecord and http://clojure.org/java_interop#Java%20Interop-The%20Dot%20special%20form-(new%20Classname%20args*)for the constructor documentation. Mauricio -- -- 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.
Why isn't a docstring allowed for defrecord?
I understand that defrecord can't take a docstring (see Doc string for variables and record in this group), and I have learned that record types are somewhat odd beasts. I know that there are workarounds (http://clojure-log.n01se.net/date/2010-10-03.html). Still, I'm surprised. *Why* can't I document a record type with a docstring? It seems like extremely useful coding practice to provide a docstring for a type. Even if the underlying semantics would be weird and special-cased, well, that's already true for record types. -- -- 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: Why isn't a docstring allowed for defrecord?
On 30/10/13 16:19, Mars0i wrote: Still, I'm surprised. /Why/ can't I document a record type with a docstring? of course you can...just add a :doc key in the record's meta :) 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+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: Why isn't a docstring allowed for defrecord?
Jim - FooBar(); jimpil1...@gmail.com writes: On 30/10/13 16:19, Mars0i wrote: Still, I'm surprised. /Why/ can't I document a record type with a docstring? of course you can...just add a :doc key in the record's meta :) The OP is correct. He says why can't I document a record type with a docstring, rather than why can't I add directly to the metadata of the symbol. Consistency is always good; in the ideal world all def* forms should have a docstring. Being able to do privacy (defn vs defn-) would be nice also. defmethod definterface defstruct deftype 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 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: Why isn't a docstring allowed for defrecord?
On 30/10/13 16:54, Phillip Lord wrote: Jim - FooBar(); jimpil1...@gmail.com writes: On 30/10/13 16:19, Mars0i wrote: Still, I'm surprised. /Why/ can't I document a record type with a docstring? of course you can...just add a :doc key in the record's meta :) The OP is correct. He says why can't I document a record type with a docstring, rather than why can't I add directly to the metadata of the symbol. Consistency is always good; in the ideal world all def* forms should have a docstring. Being able to do privacy (defn vs defn-) would be nice also. defmethod definterface defstruct deftype Phil Ok my bad...for a second there I thought that a defrecord expression returns a Var but it doesn't. It returns a Class object. You can't put anything on that therefore 'doc' won't work on it anyway. It is the instance of that Class that is able to take meta data. I concur that consistency is good to have. apologies for the rushed response. 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+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.