Re: usage examples in clojure api docs
Partly in response to this issue and partly to get my feet wet with Ring and friends, I spent the last few nights writing a proof-of- concept Wiki to collect structured Clojure usage examples: http://clojure-examples.appspot.com/ Here's a sample function page: http://clojure-examples.appspot.com/clojure.core/contains%3F I tried to come up with something that encourages a many-hands approach while maintaining structure and quality. There are plenty of missing features, but it should be easy for anyone interested to jump in and write some examples. It uses a modified version of Markdown for syntax. Content could be exported/parsed en masse relatively easily. The source is on GitHub: http://github.com/jkk/clj-wiki Does this seem like a worthwhile approach? Justin On Jun 29, 9:35 pm, Mike Meyer wrote: > On Tue, 29 Jun 2010 17:01:10 -0700 (PDT) > > > > > > Mark Fredrickson wrote: > > On Jun 29, 5:43 pm, nickikt wrote: > > > We could make it possible to add some metadata to a function > > > like :example or something. Then add a function called (example > > > ) to print the example. > > > > Everybody could send patches. It would be a good way to learn and a > > > good extra doku. > > > I was considering doing this for a while. This thread prompted me to > > put it into action: > > >http://github.com/markmfredrickson/postdoc > > > Here is an example of it in action: > > > (defn foo > > "Adds two numbers" > > [a b] > > (+ a b)) > > > (defn bar > > "Subtracts two numbers" > > [a b] > > (- a b)) > > > (postdoc #'foo > > {:references ["http://foo.com"; "http://bar.com";] > > :examples ['(foo 1 2) '(foo 3 4)] > > :see-also [#'bar] > > :categories [:bar :baz :other]}) > > > user> (doc foo) > > - > > user/foo > > ([a b]) > > Adds two numbers > > === Categories === > > > :bar, :baz, :other > > > === See Also === > > > * #'user/bar > > > === Examples === > > > > (foo 1 2) > > 3 > > > (foo 3 4) > > 7 > > > === References === > > > *http://foo.com > > *http://bar.com > > > There is also a (run-examples foo) function that evaluates the > > examples. > > It's a great start. However, examples are much more useful if you know > what they should produce. run-examples might provide that, but having > them in the metadata would be even better - along with an explanation. > > Doing that would allow the examples to be used as a set of unit tests > as well. Nuts, the things you want to test - corner cases and edge > conditions - are among the more useful things to document about a > function. > > -- > Mike Meyer http://www.mired.org/consulting.html > Independent Network/Unix/Perforce consultant, email for more information. > > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org -- 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: Benchmarking clojure code
I don't see how the loop is relevant here, at least if the same benchmarking function is used for all the benchmarks you're doing, it should make a difference then since the overhead is the same. On Jul 1, 2010, at 9:44 PM, Mike Meyer wrote: > On Thu, 1 Jul 2010 11:27:09 -0700 (PDT) > j-g-faustus wrote: >> On Jul 1, 7:51 pm, Peter Schuller wrote: Is anyone using anything more sophisticated than clojure.core/time for benchmarking clojure code? >> Criterium, a benchmarking library for Clojure, seems pretty good: >> http://github.com/hugoduncan/criterium > > The author responded here. > >> Based on ideas in this article: >> http://www.ibm.com/developerworks/java/library/j-benchmark1.html >> >> The stackoverflow question where I found it, thanks to Michal Marczyk: >> http://stackoverflow.com/questions/3041299/how-to-benchmark-functions-in-clojure >> >> >> Getting *accurate* results can be hard, even with a benchmarking >> library. Criterium runs the code 60 times and does statistical >> analysis on the results, but I can still get variations above +/-10% >> from run to run in the REPL. >> >> I think benchmarking works best when >> * starting a new run each time - i.e. from the command line, a "clean >> slate" JVM >> * having something that runs long enough to stabilize the JVM - >> Criterium wants 1 min or more total runtime. >> * running it more than once and checking that results are tolerably >> consistent >> * looking for differences in orders of magnitude rather than a couple >> of percent more or less. > > Criterium (and the Java code based on the same ideas) has what looks > like a serious problem for microbenchmarking: > > After figuring out how many times to execute the body to make it last > a minute, it times the execution of the loop that does this. Which > means the reported time includes loop overhead. > > When I tried the obvious solution (time an empty loop and subtract > that value from the original) on top of time, it was sometimes > generating negative values, so the empty loop is taking more time than > the loop being timed. That's a pretty solid indication that timing the > target code was lost in the noise of timing the loop overhead. > > Possibly trying this fix with all of criterium code to stabilize the > JVM would help with the problem. I'd fix it (pretty easy) and try > myself, but there's no 1.1 jar and the current sources require 1.2. > > If nothing else adding code to measure the empty loop and punting if > the difference between that and the code loop is statistically > insignificant would seem like a good idea. > > -- > Mike Meyerhttp://www.mired.org/consulting.html > Independent Network/Unix/Perforce consultant, email for more information. > > O< ascii ribbon campaign - stop html mail - www.asciiribbon.org > > -- > 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: Managing the classpath
On Jul 2, 5:20 am, Brian Schlining wrote: > > > There's URLClassLoader for loading classes at runtime. Javadocs are > > athttp://java.sun.com/javase/6/docs/api/java/net/URLClassLoader.html. > > There's > > > an old thread about using it athttp:// > > forums.sun.com/thread.jspa?threadID=300557&start=0&tstart=0 > > > Using a classloader manually is sub-optimal because the rest of > > Clojure, which doesn't know anything about the user-created > > classloader, wouldn't use it to load classes; you'd have to use the > > reflection API yourself to manipulate them. > > That's normally true, but if you look at the thread reference above it shows > you how to 'hack' the system classloader, so you can use the classes as if > they were loaded normally (on JVM startup) That's too much of a hack for my tastes, and it will only work for stand-alone applications (possibly only on certain JVMs). > > > Actually there is such a thing. For most JRE's/JDK's drop the > > > 'always-available-jars' in JRE_HOME/lib/ext. On Mac's you would place > > them > > > in /Library/Java/Extensions. Keep in mind that this is generally > > discouraged > > > in favor of setting the classpath on a per-application basis. > > > There's a reason for that being discouraged: if you install a new > > version of the JRE/JDK, you'll have to copy your jars there by hand. > > Since Java auto-updates itself, at least on Windows, that's quite > > dangerous. > > I agree it should be discouraged. Just FYI though, the current releases of > Java on Windows auto-updates in place. So any jars you put in lib/ext will > still be there after the update. On Macs, Java updates have no effect on > /Library/Java/Extensions. Ok, I stand corrected. I haven't been touching Windows for a while :) Cheers, Alessio -- 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: usage examples in clojure api docs
On 2 Lip, 09:46, Justin Kramer wrote: > Partly in response to this issue and partly to get my feet wet with > Ring and friends, I spent the last few nights writing a proof-of- > concept Wiki to collect structured Clojure usage examples: > > http://clojure-examples.appspot.com/ > > Here's a sample function page: > > http://clojure-examples.appspot.com/clojure.core/contains%3F > > I tried to come up with something that encourages a many-hands > approach while maintaining structure and quality. There are plenty of > missing features, but it should be easy for anyone interested to jump > in and write some examples. It uses a modified version of Markdown for > syntax. Content could be exported/parsed en masse relatively easily. > > The source is on GitHub:http://github.com/jkk/clj-wiki > > Does this seem like a worthwhile approach? > > Justin Great! I was thinking lately of building something similar with the same kind of approach. One suggestion: the core functions should be structured into categories rather than listed alphabetically., that is for example: Maps - fn1 - fn2 - fn3 Vectors - fn3 - fn4 - fn5 Arithmetic - fn6 - fn7 - fn8 etcetera. (Similar to what is in the cheat sheet) This would eliminate the tersness and it would be much easier to find a specific function (handy for newcomers to clojure) Other than that great job, I think it has big potential. It's clean, and easy to contribute. I will surely add some examples later today. -- 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: Documentation and examples (and where is the documentation on reduce)?
You can find a lot of examples using http://github.com/defn/walton For example you can point your browser at http://getclojure.org:8080/examples/reduce for reduce examples. On Jun 30, 8:08 am, michele wrote: > Mother's invention is a lazy necessity, I think. > > On Jun 29, 9:46 pm, Meikel Brandmeyer wrote: > > > Hi, > > > Am 29.06.2010 um 19:11 schrieb michele: > > > > Meikel, idiots are nice people too, so don't feel bad. But seriously, > > > why do you think we work this hard to make the computer do all this > > > things for us? Because we're lazy. > > > Ah. IMHO, computer help us solving problems which we wouldn't have without > > them. > > > But then: laziness is the source of intelligence. Or was it the other way > > around? > > > ;) > > > Sincerely > > Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Benchmarking clojure code
On Jul 2, 3:44 am, Mike Meyer wrote: > On Thu, 1 Jul 2010 11:27:09 -0700 (PDT) > j-g-faustus wrote: > > Criterium, a benchmarking library for Clojure, seems pretty good: > > The author responded here. > I noticed, my reply was sent an hour earlier. I'm still on moderation, so my mails are 1-12 hours delayed. Sorry. -- 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: usage examples in clojure api docs
I'm very new here but I have to say I really like this. These kind of usage examples are the most helpful resource for newcomers. I'll be happy to contribute once I learn more. Bob On Jul 2, 2010, at 16:46, Justin Kramer wrote: > Partly in response to this issue and partly to get my feet wet with > Ring and friends, I spent the last few nights writing a proof-of- > concept Wiki to collect structured Clojure usage examples: > > http://clojure-examples.appspot.com/ > > Here's a sample function page: > > http://clojure-examples.appspot.com/clojure.core/contains%3F > > I tried to come up with something that encourages a many-hands > approach while maintaining structure and quality. There are plenty of > missing features, but it should be easy for anyone interested to jump > in and write some examples. It uses a modified version of Markdown for > syntax. Content could be exported/parsed en masse relatively easily. > > The source is on GitHub: http://github.com/jkk/clj-wiki > > Does this seem like a worthwhile approach? > > Justin > > On Jun 29, 9:35 pm, Mike Meyer 620...@mired.org> wrote: >> On Tue, 29 Jun 2010 17:01:10 -0700 (PDT) >> >> >> >> >> >> Mark Fredrickson wrote: >>> On Jun 29, 5:43 pm, nickikt wrote: We could make it possible to add some metadata to a function like :example or something. Then add a function called (example ) to print the example. >> Everybody could send patches. It would be a good way to learn and a good extra doku. >> >>> I was considering doing this for a while. This thread prompted me to >>> put it into action: >> >>> http://github.com/markmfredrickson/postdoc >> >>> Here is an example of it in action: >> >>> (defn foo >>> "Adds two numbers" >>> [a b] >>> (+ a b)) >> >>> (defn bar >>> "Subtracts two numbers" >>> [a b] >>> (- a b)) >> >>> (postdoc #'foo >>>{:references ["http://foo.com"; "http://bar.com";] >>> :examples ['(foo 1 2) '(foo 3 4)] >>> :see-also [#'bar] >>> :categories [:bar :baz :other]}) >> >>> user> (doc foo) >>> - >>> user/foo >>> ([a b]) >>> Adds two numbers >>> === Categories === >> >>> :bar, :baz, :other >> >>> === See Also === >> >>> * #'user/bar >> >>> === Examples === >> (foo 1 2) >>> 3 (foo 3 4) >>> 7 >> >>> === References === >> >>> *http://foo.com >>> *http://bar.com >> >>> There is also a (run-examples foo) function that evaluates the >>> examples. >> >> It's a great start. However, examples are much more useful if you know >> what they should produce. run-examples might provide that, but having >> them in the metadata would be even better - along with an explanation. >> >> Doing that would allow the examples to be used as a set of unit tests >> as well. Nuts, the things you want to test - corner cases and edge >> conditions - are among the more useful things to document about a >> function. >> >> > -- >> Mike Meyer http://www.mired.org/consulting.html >> Independent Network/Unix/Perforce consultant, email for more information. >> >> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org > > -- > 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: Documentation and examples (and where is the documentation on reduce)?
Hi, On Jul 2, 12:18 pm, Walter van der Laan wrote: > For example you can point your browser > athttp://getclojure.org:8080/examples/reduce > for reduce examples. Is it necessary to have >250 examples for a function which has effectively five variations? (reduce + []) (reduce + [1]) (reduce + [1 2 3]) (reduce + 0 []) (reduce + 0 [1 2 3]) Then there are examples like this one: (reduce '* '(1 2 3)) Someone who is new to Clojure and tries to understand reduce... Does he understand why the result is 3? A result which relies on a not very well-known fact, that you can actually call symbols like keywords for map lookup with up to two arguments. (I bet there quite a few of "seasoned" clojurians who didn't know that) I - if I was a newbie to the language - would mainly think: wtf? Additionally the particular example above doesn't even make sense. I'm all for examples, but please: clear examples focusing on the thing being demonstrated. Symbol calling or showing that [1 2 3] and (list 1 2 3) can be interchanged in the example above are nice to know, but don't help to understand reduce itself. They should go to their own sections in a tutorial. The 0.02€ of a guy who has not put effort in creating examples for the core API. Sincerely Meikel PS: I also think the examples should demonstrate idiomatic clojure. [1 2 3] is idiomatic while '(1 2 3) is not. Whatever we put in examples will show up in code. So be it [] vs. '() or (.java interop) vs. (. interop (java)) - we should pay attention! -- 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: Managing the classpath
> > http:// > > > forums.sun.com/thread.jspa?threadID=300557&start=0&tstart=0 > > > > > Using a classloader manually is sub-optimal because the rest of > > > Clojure, which doesn't know anything about the user-created > > > classloader, wouldn't use it to load classes; you'd have to use the > > > reflection API yourself to manipulate them. > > > > That's normally true, but if you look at the thread reference above it > shows > > you how to 'hack' the system classloader, so you can use the classes as > if > > they were loaded normally (on JVM startup) > > That's too much of a hack for my tastes, and it will only work for > stand-alone applications (possibly only on certain JVMs). Yep, it is a total hack. But, that type of hack could be EXTREMELY useful for standalone scripts/apps. It shows that it's possible to load classes or jars at runtime and use the classes just as one expects. Just imagine, adding a line to the top of your clojure script like: (grab org.sourceforge.jtds jtds 1.2.5) and having your script fetch the jtds dependency (if needed) from a Maven repo and load the classes. You could then just ship a Clojure script WITHOUT the dependent jars. I use this type of thing in Groovy (via Grape) all the time. It makes life much simpler and adding a similar 'hack' to Clojure would greatly increase Clojure's usefulness for scripting tasks. -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Brian Schlining bschlin...@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
Newbie questions about leiningen
Dear all, I am moving from netbeans to leiningen + swank + emacs. Enclojure was great but I wanted to try somnething else. Leiningen is amazing. Thanks to the author(s). I am looking for a way to tell leiningen what JVM options to use with the SWANK server. (I need a lot of Heap size to do anything useful...) I wasn't able to find that in the doc. Is it not the right way of proceeding? Best regards, Nicolas. -- 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: Benchmarking clojure code
On Thu, 1 Jul 2010 22:19:56 -0400 Greg wrote: > I don't see how the loop is relevant here, at least if the same benchmarking > function is used for all the benchmarks you're doing, it should make a > difference then since the overhead is the same. It depends on what you're benchmarking. If the loop time is much smaller than either the actual code time or the standard deviation in the measurements, then it's just noise, and you can ignore it. If it's on the order of the same size as the standard deviation, then it can fool you into falsely concluding that there's no statistically significant difference between two algorithms. Once it gets to be around half the total benchmark time, your results are pretty much worthless. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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: Documentation and examples (and where is the documentation on reduce)?
On Fri, 2 Jul 2010 07:50:45 -0700 (PDT) Meikel Brandmeyer wrote: > On Jul 2, 12:18 pm, Walter van der Laan > wrote: > > For example you can point your browser > > athttp://getclojure.org:8080/examples/reduce > > for reduce examples. > Is it necessary to have >250 examples for a function which has > effectively five variations? > (reduce + []) > (reduce + [1]) > (reduce + [1 2 3]) > (reduce + 0 []) > (reduce + 0 [1 2 3]) Seconded. > I'm all for examples, but please: clear examples focusing on the thing > being demonstrated. Symbol calling or showing that [1 2 3] and (list 1 > 2 3) can be interchanged in the example above are nice to know, but > don't help to understand reduce itself. They should go to their own > sections in a tutorial. Yes. Symbol calling and the equivalence of [1 2 3] and '(1 2 3) aren't really relevant to what reduce can do. Nor is showing someone how to extract the arglist from a functions metadata. While I think the effort is marvelous, some thought should go into the purpose. That page looks like the purpose is to show off the cleverness of the person who wrote it. As such, this page is probably more confusing than helpful. > PS: I also think the examples should demonstrate idiomatic clojure. [1 > 2 3] is idiomatic while '(1 2 3) is not. Whatever we put in examples > will show up in code. So be it [] vs. '() or (.java interop) vs. (. > interop (java)) - we should pay attention! Ditto. Examples are read in order, and should be presented from simple to more complex. In particular, the first example shouldn't require knowing anything but clojure syntax. Each further example should introduce at most one new concept, reinforce the previous example (though that should be kept to a minimum), or show the function working on different data types - if they're not doing one of those things, why are they there? All the inputs to an example should be either literals, or the result of a simple function invocation. If the user has to work to figure out what the input is, they're that much more likely to skip the example, or - even worse - come up with the wrong input and hence wrong result. Finally, maybe provide one example (short) that might be considered a "real world" use. They really need to include an explanation. Having the expected results there would be nice as well. > The 0.02€ of a guy who has not put effort in creating examples for the > core API. Not wanting to be that guy (no offense intended to Meikel, he made a good point), here's what I think is a nice set of reduce examples: ; sum of 0 through 10: 45 (reduce + (range 10)) ; Divide 1 by 2 and then 3: 1/6 (reduce / 1 [2 3]) ; Build a set from a collection: #{:a :c :b} (reduce conj #{} [:a :b :c]) ; Build a sorted set from multiple collections: #{1 2 3 4 5 6} (reduce into (sorted-set) [[3 1 2] [5 4 6]]) ; Reverse a list: (3 2 1) (reduce #(cons %2 %1) [] [1 2 3]) ; Build a hash-map from n to n squared: ; {0 0, 1 1, 2 4, 3 9, 4 16, 5 25, 6 36, 7 49, 8 64, 9 81} (reduce #(assoc %1 %2 (* %2 %2)) {} (range 10)) ; Edge case with one argument: returns argument -> 2 (reduce conj [2]) ; Edge case with one argument: returns argument -> 1 (reduce conj 1 []) ; Note that in the previous two examples, conj is not invoked, as it ; always returns a sequence. ; Edge case with no arguments: (*) -> 1 (reduce * []) ; Broken edge case: Wrong number of arguments passed to function: (reduce conj []) -- Mike Meyer http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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: usage examples in clojure api docs
+1 I like it, Justin. I was looking at making something myself but your efforts are farther along. I'd be happy to help with any aspect of this. Ryan On Fri, Jul 2, 2010 at 2:46 AM, Justin Kramer wrote: > Partly in response to this issue and partly to get my feet wet with > Ring and friends, I spent the last few nights writing a proof-of- > concept Wiki to collect structured Clojure usage examples: > > http://clojure-examples.appspot.com/ > > Here's a sample function page: > > http://clojure-examples.appspot.com/clojure.core/contains%3F > > I tried to come up with something that encourages a many-hands > approach while maintaining structure and quality. There are plenty of > missing features, but it should be easy for anyone interested to jump > in and write some examples. It uses a modified version of Markdown for > syntax. Content could be exported/parsed en masse relatively easily. > > The source is on GitHub: http://github.com/jkk/clj-wiki > > Does this seem like a worthwhile approach? > > Justin > > On Jun 29, 9:35 pm, Mike Meyer 620...@mired.org> wrote: >> On Tue, 29 Jun 2010 17:01:10 -0700 (PDT) >> >> >> >> >> >> Mark Fredrickson wrote: >> > On Jun 29, 5:43 pm, nickikt wrote: >> > > We could make it possible to add some metadata to a function >> > > like :example or something. Then add a function called (example >> > > ) to print the example. >> >> > > Everybody could send patches. It would be a good way to learn and a >> > > good extra doku. >> >> > I was considering doing this for a while. This thread prompted me to >> > put it into action: >> >> >http://github.com/markmfredrickson/postdoc >> >> > Here is an example of it in action: >> >> > (defn foo >> > "Adds two numbers" >> > [a b] >> > (+ a b)) >> >> > (defn bar >> > "Subtracts two numbers" >> > [a b] >> > (- a b)) >> >> > (postdoc #'foo >> > {:references ["http://foo.com"; "http://bar.com";] >> > :examples ['(foo 1 2) '(foo 3 4)] >> > :see-also [#'bar] >> > :categories [:bar :baz :other]}) >> >> > user> (doc foo) >> > - >> > user/foo >> > ([a b]) >> > Adds two numbers >> > === Categories === >> >> > :bar, :baz, :other >> >> > === See Also === >> >> > * #'user/bar >> >> > === Examples === >> >> > > (foo 1 2) >> > 3 >> > > (foo 3 4) >> > 7 >> >> > === References === >> >> > *http://foo.com >> > *http://bar.com >> >> > There is also a (run-examples foo) function that evaluates the >> > examples. >> >> It's a great start. However, examples are much more useful if you know >> what they should produce. run-examples might provide that, but having >> them in the metadata would be even better - along with an explanation. >> >> Doing that would allow the examples to be used as a set of unit tests >> as well. Nuts, the things you want to test - corner cases and edge >> conditions - are among the more useful things to document about a >> function. >> >> > -- >> Mike Meyer http://www.mired.org/consulting.html >> Independent Network/Unix/Perforce consultant, email for more information. >> >> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org > > -- > 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: Documentation and examples (and where is the documentation on reduce)?
n00b question: Why is [1 2 3] idiomatic and not '(1 2 3) ? Is it a vectors vs. lists thing, notation thing, or something else? I don't have a lisp background so there's a truckload of lisp reading I still want to do which may answer questions like these for me. If there's a particular text on what would help a person discern idiomatic vs. not, in clojure, I'd be happy to put that on my "list" '(ha ha). :P Ryan On Fri, Jul 2, 2010 at 9:50 AM, Meikel Brandmeyer wrote: > Hi, > > On Jul 2, 12:18 pm, Walter van der Laan > wrote: > >> For example you can point your browser >> athttp://getclojure.org:8080/examples/reduce >> for reduce examples. > > Is it necessary to have >250 examples for a function which has > effectively five variations? > > (reduce + []) > (reduce + [1]) > (reduce + [1 2 3]) > (reduce + 0 []) > (reduce + 0 [1 2 3]) > > Then there are examples like this one: > (reduce '* '(1 2 3)) > > Someone who is new to Clojure and tries to understand reduce... Does > he understand why the result is 3? A result which relies on a not very > well-known fact, that you can actually call symbols like keywords for > map lookup with up to two arguments. (I bet there quite a few of > "seasoned" clojurians who didn't know that) I - if I was a newbie to > the language - would mainly think: wtf? Additionally the particular > example above doesn't even make sense. > > I'm all for examples, but please: clear examples focusing on the thing > being demonstrated. Symbol calling or showing that [1 2 3] and (list 1 > 2 3) can be interchanged in the example above are nice to know, but > don't help to understand reduce itself. They should go to their own > sections in a tutorial. > > The 0.02€ of a guy who has not put effort in creating examples for the > core API. > > Sincerely > Meikel > > PS: I also think the examples should demonstrate idiomatic clojure. [1 > 2 3] is idiomatic while '(1 2 3) is not. Whatever we put in examples > will show up in code. So be it [] vs. '() or (.java interop) vs. (. > interop (java)) - we should pay attention! > > -- > 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: Documentation and examples (and where is the documentation on reduce)?
On 2 July 2010 15:50, Meikel Brandmeyer wrote: > Then there are examples like this one: > (reduce '* '(1 2 3)) > > Someone who is new to Clojure and tries to understand reduce... Does > he understand why the result is 3? A result which relies on a not very > well-known fact, that you can actually call symbols like keywords for > map lookup with up to two arguments. (I bet there quite a few of > "seasoned" clojurians who didn't know that) I - if I was a newbie to > the language - would mainly think: wtf? Even with your explanation, I'm baffled... I can get to user=> ('* ('* 1 2) 3) 3 Ah. This means look '* up in ('* 1 2) and use 3 as the default if you don't find it. And you don't (for all sorts of odd reasons - why doesn't this raise a "what are you doing, it's not even a map you're looking up in" exception? :-)), so the result is the default, 3. Uh, yeah. That example is actually harmful - as it confused me about what does and doesn't need quoting - something I would probably have got right instinctively until I read this :-( Paul. -- 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: usage examples in clojure api docs
Hey Justin! Nice one! I'm actually planning on doing a similar thing, but hosting it on Amazon's EC2. Would you be interested in combining efforts together? Cheers, Greg Slepak On Jul 2, 2010, at 3:46 AM, Justin Kramer wrote: > Partly in response to this issue and partly to get my feet wet with > Ring and friends, I spent the last few nights writing a proof-of- > concept Wiki to collect structured Clojure usage examples: > > http://clojure-examples.appspot.com/ > > Here's a sample function page: > > http://clojure-examples.appspot.com/clojure.core/contains%3F > > I tried to come up with something that encourages a many-hands > approach while maintaining structure and quality. There are plenty of > missing features, but it should be easy for anyone interested to jump > in and write some examples. It uses a modified version of Markdown for > syntax. Content could be exported/parsed en masse relatively easily. > > The source is on GitHub: http://github.com/jkk/clj-wiki > > Does this seem like a worthwhile approach? > > Justin > > On Jun 29, 9:35 pm, Mike Meyer 620...@mired.org> wrote: >> On Tue, 29 Jun 2010 17:01:10 -0700 (PDT) >> >> >> >> >> >> Mark Fredrickson wrote: >>> On Jun 29, 5:43 pm, nickikt wrote: We could make it possible to add some metadata to a function like :example or something. Then add a function called (example ) to print the example. >> Everybody could send patches. It would be a good way to learn and a good extra doku. >> >>> I was considering doing this for a while. This thread prompted me to >>> put it into action: >> >>> http://github.com/markmfredrickson/postdoc >> >>> Here is an example of it in action: >> >>> (defn foo >>> "Adds two numbers" >>> [a b] >>> (+ a b)) >> >>> (defn bar >>> "Subtracts two numbers" >>> [a b] >>> (- a b)) >> >>> (postdoc #'foo >>>{:references ["http://foo.com"; "http://bar.com";] >>> :examples ['(foo 1 2) '(foo 3 4)] >>> :see-also [#'bar] >>> :categories [:bar :baz :other]}) >> >>> user> (doc foo) >>> - >>> user/foo >>> ([a b]) >>> Adds two numbers >>> === Categories === >> >>> :bar, :baz, :other >> >>> === See Also === >> >>> * #'user/bar >> >>> === Examples === >> (foo 1 2) >>> 3 (foo 3 4) >>> 7 >> >>> === References === >> >>> *http://foo.com >>> *http://bar.com >> >>> There is also a (run-examples foo) function that evaluates the >>> examples. >> >> It's a great start. However, examples are much more useful if you know >> what they should produce. run-examples might provide that, but having >> them in the metadata would be even better - along with an explanation. >> >> Doing that would allow the examples to be used as a set of unit tests >> as well. Nuts, the things you want to test - corner cases and edge >> conditions - are among the more useful things to document about a >> function. >> >> > -- >> Mike Meyer http://www.mired.org/consulting.html >> Independent Network/Unix/Perforce consultant, email for more information. >> >> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org > > -- > 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
structures contains each other
I'm building a directed graph library, where the nodes has "out" and "in" fields. If I connect a node, let's say: (node->node n0 n1) then the node's fields would be the following: n0: in: () out: (n1) n1: in: (n0) out () My problem is that if I update n0 I could only add the old "instance" to the list, so when I update n1, n0's out field would would contain an outdated n1 also.. So n00b head I think it's out of the functional paradigm(or I could use node-ids and a hash as a graph, but I don't like it), but how you guys would solve this problem? Any workaround? Thanks for your help! M -- 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: Benchmarking clojure code
On Jul 2, 7:41 pm, Mike Meyer wrote: > On Thu, 1 Jul 2010 22:19:56 -0400 > It depends on what you're benchmarking. If the loop time ... is > on the order of the same size as the standard deviation, then it can > fool you into falsely concluding that there's no statistically > significant difference between two algorithms. Once it gets to be > around half the total benchmark time, your results are pretty much > worthless. I'm not a JVM benchmarking expert by any means, but I have been working with Java for close to a decade, and to the best of my knowledge that level of micro-benchmarking precision is not possible, for all the reasons listed and linked to - dynamic HotSpot optimizations, unpredictable garbage collection, limited timing resolution etc. For loops that are part of the program, like iterating over all the pixels in an image to compute a transform, it's a non-issue. Those loops are part of the algorithm, and if transform A takes the same time as transform B because both of them are dominated by the time it takes to loop through every pixel, you can correctly conclude that the difference between A and B does not matter. But the benchmarking loop time and other administrative overhead (including the extra overhead on garbage collection) needs to be an insignificant fraction of the total, yes. If the benchmarking framework does more work than the code being measured, you will be benchmarking the framework rather than the code you want to measure. I normally deal with it by putting larger chunks of code inside the benchmarking loop, aiming for at least a second of runtime per invocation. Even then, the PDF from Azul systems linked to earlier says that "performance varies from run to run - stable numbers within a single JVM invocation, but could vary > 20% with new JVM invocation", which matches well with my experience. In practice, I have given up on timing very small blocks of code, and I have given up on trying for precision better than +/-10%. Your mileage may vary. jf -- 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: structures contains each other
I've also struggled with the same concepts in my head in the past. One answer to try explain why it is not possible, is that if you do that, you somehow try to conflate identity and state again. When you write n0: in () out (n1) and n1 in(n0) out() , it seems to me that when you write n0:in() out(n1) you're thinking about n0 as the node(identity)+state (value of an identity at a point in time) conflated, but when you write n1 in(n0) out(), you think about n0 as the identity. So in fact, if I try to separate identity and state again, n0 and n1 are refs: (def n0 (ref nil)) (def n1 (ref {:in [n0], :out []})) (dosync (ref-set n0 {:in [], :out [n1]})) Or you could manage by yourself the concept of identity, not delegating it to clojure's refs, as you said. 2010/7/2 Mate Toth : > I'm building a directed graph library, where the nodes has "out" and > "in" fields. If I connect a node, let's say: > (node->node n0 n1) > then the node's fields would be the following: > > n0: > in: () > out: (n1) > > n1: > in: (n0) > out () > > > My problem is that if I update n0 I could only add the old "instance" > to the list, so when I update n1, n0's out field would would contain > an outdated n1 also.. > > So n00b head I think it's out of the functional paradigm(or I could > use node-ids and a hash as a graph, but I don't like it), but how you > guys would solve this problem? Any workaround? > > Thanks for your help! M > > > -- > 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: Documentation and examples (and where is the documentation on reduce)?
Nice, Mike. I stole your work and put it into the Wiki I created to see how it fit: http://clojure-examples.appspot.com/clojure.core/reduce (Note: reduce seems to be missing a doc string in 1.2 master; for other functions doc strings show up.) As cool as walton is, it's kind of a firehose. A curated collection of examples (perhaps pilfering from walton and others) would be more valuable, I think. Justin On Jul 2, 2:58 pm, Mike Meyer wrote: > On Fri, 2 Jul 2010 07:50:45 -0700 (PDT) > > Meikel Brandmeyer wrote: > > On Jul 2, 12:18 pm, Walter van der Laan > > wrote: > > > For example you can point your browser > > > athttp://getclojure.org:8080/examples/reduce > > > for reduce examples. > > Is it necessary to have >250 examples for a function which has > > effectively five variations? > > (reduce + []) > > (reduce + [1]) > > (reduce + [1 2 3]) > > (reduce + 0 []) > > (reduce + 0 [1 2 3]) > > Seconded. > > > I'm all for examples, but please: clear examples focusing on the thing > > being demonstrated. Symbol calling or showing that [1 2 3] and (list 1 > > 2 3) can be interchanged in the example above are nice to know, but > > don't help to understand reduce itself. They should go to their own > > sections in a tutorial. > > Yes. Symbol calling and the equivalence of [1 2 3] and '(1 2 3) aren't > really relevant to what reduce can do. Nor is showing someone how to > extract the arglist from a functions metadata. > > While I think the effort is marvelous, some thought should go into the > purpose. That page looks like the purpose is to show off the > cleverness of the person who wrote it. As such, this page is probably > more confusing than helpful. > > > PS: I also think the examples should demonstrate idiomatic clojure. [1 > > 2 3] is idiomatic while '(1 2 3) is not. Whatever we put in examples > > will show up in code. So be it [] vs. '() or (.java interop) vs. (. > > interop (java)) - we should pay attention! > > Ditto. > > Examples are read in order, and should be presented from simple to > more complex. In particular, the first example shouldn't require > knowing anything but clojure syntax. Each further example should > introduce at most one new concept, reinforce the previous example > (though that should be kept to a minimum), or show the function > working on different data types - if they're not doing one of those > things, why are they there? All the inputs to an example should be > either literals, or the result of a simple function invocation. If the > user has to work to figure out what the input is, they're that much > more likely to skip the example, or - even worse - come up with the > wrong input and hence wrong result. Finally, maybe provide one example > (short) that might be considered a "real world" use. > > They really need to include an explanation. Having the expected > results there would be nice as well. > > > The 0.02€ of a guy who has not put effort in creating examples for the > > core API. > > Not wanting to be that guy (no offense intended to Meikel, he made a > good point), here's what I think is a nice set of reduce examples: > > ; sum of 0 through 10: 45 > (reduce + (range 10)) > > ; Divide 1 by 2 and then 3: 1/6 > (reduce / 1 [2 3]) > > ; Build a set from a collection: #{:a :c :b} > (reduce conj #{} [:a :b :c]) > > ; Build a sorted set from multiple collections: #{1 2 3 4 5 6} > (reduce into (sorted-set) [[3 1 2] [5 4 6]]) > > ; Reverse a list: (3 2 1) > (reduce #(cons %2 %1) [] [1 2 3]) > > ; Build a hash-map from n to n squared: > ; {0 0, 1 1, 2 4, 3 9, 4 16, 5 25, 6 36, 7 49, 8 64, 9 81} > (reduce #(assoc %1 %2 (* %2 %2)) {} (range 10)) > > ; Edge case with one argument: returns argument -> 2 > (reduce conj [2]) > > ; Edge case with one argument: returns argument -> 1 > (reduce conj 1 []) > > ; Note that in the previous two examples, conj is not invoked, as it > ; always returns a sequence. > > ; Edge case with no arguments: (*) -> 1 > (reduce * []) > > ; Broken edge case: Wrong number of arguments passed to function: > (reduce conj []) > > -- > Mike Meyer http://www.mired.org/consulting.html > Independent Network/Unix/Perforce consultant, email for more information. > > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org -- 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: usage examples in clojure api docs
Good suggestion about the categories. Making it browsable is important. A page that uses categories from the cheatsheet is easy to make. Adding categories/tags and auto-generating such a page is also doable. Code contributions are welcome. I'm not attached to App Engine; I just used it to learn about the platform. The code could be modified to work with any storage backend. I'll be spending free time in the next few days writing real examples and seeing if anyone else follows suit. If it doesn't gain traction, or someone else has a better approach, adding fancy features and re- architecting is moot. Justin On Jul 2, 5:09 am, kredaxx wrote: > On 2 Lip, 09:46, Justin Kramer wrote: > > > > > > > Partly in response to this issue and partly to get my feet wet with > > Ring and friends, I spent the last few nights writing a proof-of- > > concept Wiki to collect structured Clojure usage examples: > > >http://clojure-examples.appspot.com/ > > > Here's a sample function page: > > >http://clojure-examples.appspot.com/clojure.core/contains%3F > > > I tried to come up with something that encourages a many-hands > > approach while maintaining structure and quality. There are plenty of > > missing features, but it should be easy for anyone interested to jump > > in and write some examples. It uses a modified version of Markdown for > > syntax. Content could be exported/parsed en masse relatively easily. > > > The source is on GitHub:http://github.com/jkk/clj-wiki > > > Does this seem like a worthwhile approach? > > > Justin > > Great! I was thinking lately of building something similar with the > same kind of approach. > > One suggestion: the core functions should be structured into > categories rather than listed alphabetically., that is for example: > > Maps > - fn1 > - fn2 > - fn3 > Vectors > - fn3 > - fn4 > - fn5 > Arithmetic > - fn6 > - fn7 > - fn8 > etcetera. > > (Similar to what is in the cheat sheet) > > This would eliminate the tersness and it would be much easier to find > a specific function (handy for newcomers to clojure) > > Other than that great job, I think it has big potential. It's clean, > and easy to contribute. I will surely add some examples later today. -- 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: Documentation and examples (and where is the documentation on reduce)?
On Fri, 2 Jul 2010 14:50:18 -0700 (PDT) Justin Kramer wrote: > Nice, Mike. I stole your work and put it into the Wiki I created to > see how it fit: > > http://clojure-examples.appspot.com/clojure.core/reduce Well, I like it, but I might be a bit biased. I think the important part is the rules that went into picking the examples. I just picked examples from Walton that followed them, tweaked those to build up properly, and then added the edge cases. http://clojure-examples.appspot.com/guidelines actually covers it, but my version was more explicit, and gave a why. Cleaning mine version up and combining them gives: * Keep it simple and self contained - the first example shouldn't require knowing anything but clojure syntax - the inputs to an example should either be literals or simple expressions - the user shouldn't have to figure out anything but the new concept or type * Build up examples cumulatively - each example should introduce at most one new concept - or reinforce the previous example (though that should be kept to a minimum) - or show the function working on a new data type I'd go ahead and edit the page, but figure you might want to such a change beforehand. http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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: Newbie questions about leiningen
If you launch swank with 'lein swank', there is probably an option. lein is just a shell-script which calls the following at the end: exec $RLWRAP $JAVA_CMD -Xbootclasspath/a:"$CLOJURE_JAR" -client $JAVA_OPTS \ -cp "$CLASSPATH" -Dleiningen.version="$VERSION" $JLINE \ clojure.main -e "(use 'leiningen.core)(-main)" $NULL_DEVICE $@ A quick test on my machine showed that changing the environment variable JAVA_OPTS can be used to pass arguments to the java vm. On Fri, Jul 2, 2010 at 7:35 PM, Nicolas Oury wrote: > Dear all, > I am moving from netbeans to leiningen + swank + emacs. > Enclojure was great but I wanted to try somnething else. Leiningen is > amazing. Thanks to the author(s). > I am looking for a way to tell leiningen what JVM options to use with the > SWANK server. (I need a lot of Heap size to do anything useful...) > I wasn't able to find that in the doc. Is it not the right way of > proceeding? > Best regards, > Nicolas. > > -- > 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 -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com/profiles/ulrich.moritz -- 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: usage examples in clojure api docs
On Fri, Jul 2, 2010 at 3:46 AM, Justin Kramer wrote: > Partly in response to this issue and partly to get my feet wet with > Ring and friends, I spent the last few nights writing a proof-of- > concept Wiki to collect structured Clojure usage examples: > > http://clojure-examples.appspot.com/ > > Here's a sample function page: > > http://clojure-examples.appspot.com/clojure.core/contains%3F > > I tried to come up with something that encourages a many-hands > approach while maintaining structure and quality. There are plenty of > missing features, but it should be easy for anyone interested to jump > in and write some examples. It uses a modified version of Markdown for > syntax. Content could be exported/parsed en masse relatively easily. > > The source is on GitHub: http://github.com/jkk/clj-wiki > > Does this seem like a worthwhile approach? > > Justin > Nice job for getting the ball rolling on this! 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: structures contains each other
Take a look at clojure.contrib.graph. It's very basic, but has a nice generic model. - Chas On Jul 2, 2010, at 3:15 PM, Mate Toth wrote: I'm building a directed graph library, where the nodes has "out" and "in" fields. If I connect a node, let's say: (node->node n0 n1) then the node's fields would be the following: n0: in: () out: (n1) n1: in: (n0) out () My problem is that if I update n0 I could only add the old "instance" to the list, so when I update n1, n0's out field would would contain an outdated n1 also.. So n00b head I think it's out of the functional paradigm(or I could use node-ids and a hash as a graph, but I don't like it), but how you guys would solve this problem? Any workaround? Thanks for your help! M -- 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: explode string
On Jul 1, 2010, at 9:21 AM, Martin DeMello wrote: On Thu, Jul 1, 2010 at 6:42 PM, Martin DeMello > wrote: I haven't benchmarked yet, but it's called frequently enough that it's probably worth making it efficient. (This is in code that converts a dictionary to a trie) Actually, it just struck me that the main reason I'm trying so hard to optimise this is that my app has to read in a list of strings and create a trie every time it starts up. Is there any way to dump a trie to disk in some marshalled format? (I could just dump to yaml, but that would probably not be any quicker to read in and parse) If the perf of your (de)serialization isn't a big issue, then pr and read will get you home. - Chas -- 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: usage examples in clojure api docs
On 3 July 2010 10:12, David Nolen wrote: > On Fri, Jul 2, 2010 at 3:46 AM, Justin Kramer wrote: >> >> Partly in response to this issue and partly to get my feet wet with >> Ring and friends, I spent the last few nights writing a proof-of- >> concept Wiki to collect structured Clojure usage examples: >> >> http://clojure-examples.appspot.com/ >> >> Here's a sample function page: >> >> http://clojure-examples.appspot.com/clojure.core/contains%3F >> >> I tried to come up with something that encourages a many-hands >> approach while maintaining structure and quality. There are plenty of >> missing features, but it should be easy for anyone interested to jump >> in and write some examples. It uses a modified version of Markdown for >> syntax. Content could be exported/parsed en masse relatively easily. >> >> The source is on GitHub: http://github.com/jkk/clj-wiki >> >> Does this seem like a worthwhile approach? >> >> Justin > > Nice job for getting the ball rolling on this! > David > +1 Perfect! I'd encourage everyone to get behind this. The barrier to entry is very low so no reason not to help out. The only thing missing is a search system. Also it would probably be a good idea to make the licensing of contributions explicit (boring but important detail). I didn't see anything on the site about that. -- 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: Documentation and examples (and where is the documentation on reduce)?
Hi, Am 03.07.2010 um 00:37 schrieb Mike Meyer: > Cleaning mine version up and combining them gives: > > * Keep it simple and self contained > - the first example shouldn't require knowing anything but clojure syntax > - the inputs to an example should either be literals or simple expressions > - the user shouldn't have to figure out anything but the new concept or type > * Build up examples cumulatively > - each example should introduce at most one new concept > - or reinforce the previous example (though that should be kept to a minimum) > - or show the function working on a new data type I would also add: - exercise edge cases I'm not sure, but maybe some formal transformation to show the general idea, if possible. (reduce + 0 [1 2 3]) => (+ (+ (+ 0 1) 2) 3). (map - [1 2 3]) => (-1 -2 -3) (filter even? [1 2 3]) => (#_1 2 #_3) (remove even? [1 2 3]) => (1 #_2 3) (take 2 [1 2 3]) => (1 2 #_3) With the removed items greyed out, or so. There only one example would be sufficient. Just to explain the idea. I'm not sure how useful this would be for more complicated functions, though... 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