Re: DDJ for Clojure/Lisp/FP
I am :) That's why I started this discussion. On 15/03/2011, at 2:30 PM, Gregg Williams wrote: > Let me introduce myself. I was senior editor at BYTE magazine from > 1979 to 1988, where I wrote many cover-story articles, developed/ > edited innumerable articles, and was responsible for a number of issue > themes (including the IBM PC, FORTH, and Lisp (Feb. 1988)). From > there, I went to Apple (1988-1998), where I did a similar job for > Apple publications to its third-party developer base (in a magazine > named _Apple Direct_, which was later renamed _Apple Directions_). > > I recently got a Clojure article published in the November 2010 issue > of _PragPub_ magazine (see http://pragprog.com/magazines/2010-11/content). > > I also started the website http://www.GettingClojure.com, which I > meant to be a congregating place for Clojure beginners like myself. > Apart from significant contributions to a Clojure Cookbook by David > Sletten (see http://www.gettingclojure.com/cookbook:clojure-cookbook) > and a reprint of my _PragPub_ article, the site hasn't been used. > > But that can change. > > I'd love to edit *or* help edit a magazine again. I'm tan, fit, and > rested, and I've got the chops to do the job. We could re-brand > GettingClojure.com to be for the entire Clojure community. > > I'd be glad to share the decisionmaking with anybody willing to do the > work. Once something is up and running, I'd be glad to turn the > website or the domain over to anyone or any group who has already been > making the site happen. > > You can reach me through this group, either publicly or via "Reply to > author". > > To start, I'd need authors, reviewers, people with ideas for content-- > and maybe an administrator/logistics person. Who's interested? > > > Best wishes, > > Gregg Williams > > > On Mar 13, 5:30 pm, Andreas Kostler > wrote: >> Hi there, >> Is there something like Doctor Dobbs Journal for Clojure/Lisp or even >> functional programming related topics? - A (peer reviewed) place >> collecting contributions from developers all over the world working in >> Clojure/Lisp environments sharing their insights and solutions >> to problems developers encounter daily. >> >> If there isn't, is it worthwhile starting an effort into this direction? >> >> Kind Regards >> Andreas > > -- > 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 -- "Test-driven Dentistry (TDD!) - Not everything should be test driven" - Michael Fogus -- ** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com www.leica-geosystems.com* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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: DDJ for Clojure/Lisp/FP
Let me introduce myself. I was senior editor at BYTE magazine from 1979 to 1988, where I wrote many cover-story articles, developed/ edited innumerable articles, and was responsible for a number of issue themes (including the IBM PC, FORTH, and Lisp (Feb. 1988)). From there, I went to Apple (1988-1998), where I did a similar job for Apple publications to its third-party developer base (in a magazine named _Apple Direct_, which was later renamed _Apple Directions_). I recently got a Clojure article published in the November 2010 issue of _PragPub_ magazine (see http://pragprog.com/magazines/2010-11/content). I also started the website http://www.GettingClojure.com, which I meant to be a congregating place for Clojure beginners like myself. Apart from significant contributions to a Clojure Cookbook by David Sletten (see http://www.gettingclojure.com/cookbook:clojure-cookbook) and a reprint of my _PragPub_ article, the site hasn't been used. But that can change. I'd love to edit *or* help edit a magazine again. I'm tan, fit, and rested, and I've got the chops to do the job. We could re-brand GettingClojure.com to be for the entire Clojure community. I'd be glad to share the decisionmaking with anybody willing to do the work. Once something is up and running, I'd be glad to turn the website or the domain over to anyone or any group who has already been making the site happen. You can reach me through this group, either publicly or via "Reply to author". To start, I'd need authors, reviewers, people with ideas for content-- and maybe an administrator/logistics person. Who's interested? Best wishes, Gregg Williams On Mar 13, 5:30 pm, Andreas Kostler wrote: > Hi there, > Is there something like Doctor Dobbs Journal for Clojure/Lisp or even > functional programming related topics? - A (peer reviewed) place > collecting contributions from developers all over the world working in > Clojure/Lisp environments sharing their insights and solutions > to problems developers encounter daily. > > If there isn't, is it worthwhile starting an effort into this direction? > > Kind Regards > Andreas -- 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: clojure not using CPU on binarytree benchmark
On a MacBook Pro with 2.4 GHz Intel Core 2 Duo and 3 GB of RAM (although the program only used about half a gig at most), that program finished in about 33 seconds, using 38.5 sec of user + system CPU time. The average CPU utilization was 126% (all of one CPU core, and 26% of another, on average). The CPU utilization never went below 90% of one CPU core. >From the memory use graph you link to, the memory use never goes over about >128 MB. I would bet that is the default maximum heap size in your JVM, or >perhaps one specified explicitly. That is likely not enough, and your program >is causing the JVM to invoke garbage collection repeatedly. I'd recommend using a -Xmx512m argument on the command line, or maybe a bit more, and see if things speed up. Andy On Mar 14, 2011, at 6:25 PM, Nick Zbinden wrote: > Hi, > > I'm working with binarytree benchmark from the Language Shotout. > http://shootout.alioth.debian.org/u64/program.php?test=binarytrees&lang=clojure&id=5 > > Its basiclly a port from the java version. > http://shootout.alioth.debian.org/u64/program.php?test=binarytrees&lang=java&id=2 > > The Problem with the Clojure version you can see here: > https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/AverageCPUAll.png > https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/CPUAll.png > > Clojure does not use the CPU to the full extened witch suggest that > there something blocking it. I tried to figure out what it was with > profiling but I never did that befor and I had no success. > > Node that the Clojure uses less memory too. > https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/MemoryAll.png > > Has anybody an Idea why this happens? > > I ported the programm to 1.3 but that didn't help: > > 1.2 version: > https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/clojure/src/bt/binarytrees.clj > > 1.3 version: > https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/clojure/src/bt/binarytrees_me.clj > (all the benchmarks where made with the 1.2er programm) > > thx for the help > > -- > 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: Polymorphic functions in Clojure (or how to stop thinking in objects)...
If the set of types is closed and will not be extended by users, there's nothing wrong with just writing your own dispatch using cond, something like: (defn draw [shape] (cond (triangle? shape) (draw-triangle shape) (circle? shape) (draw-circle shape) ...)) Then just write your helper functions: triangle?, draw-triangle, circle?, draw-circle and you're good to go. Clearly, no matter what, you need *some* way to distinguish between your different types. It doesn't necessarily have to be a true "type slot", as provided by defrecord. It could be that you represent circles, for example, as a map that begins {:shape :circle ...}. But it's true that protocols or multimethods would be the more common way to do this. Protocols are reportedly faster, but not as flexible (e.g., *must* dispatch on type, such as that provided by defrecord, no inheritance, etc.). I still tend to go with multimethods. Multimethods (or rolling your own predicates and dispatch as I described above) would allow you to use the combination of vectors and structs you outlined. -- 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: Polymorphic functions in Clojure (or how to stop thinking in objects)...
On Mon Mar 14 19:54 2011, stu wrote: > The problem I have is with the myshapes.picture/draw function. As a > Clojure newb I keep wanting to think of this like a polymorphic > function in the O-O world that relies on each sequence member having a > draw function. > > What's the idiomatic way of handling a situation like this in > Clojure? Do I need to use richer data structures than vectors and > structs for the shapes so they carry some kind of type information? I > can see how a draw multi-method would work if the individual shapes > could be distinguished, or am I going about this the wrong way? I believe there are two approaches to doing this in Clojure: 1. Multimethods: http://clojure.org/multimethods 2. Protocols: http://clojure.org/Protocols Of the two, as of Clojure 1.2, protocols are the preferred way of doing things. They handle the simplest and most common case of polymorphism: by type. You can define a set of functions for your shapes: (defprotocol Shape (draw [shape]) (rotate [shape angle]) …) Then you can convert your structs into records. So, instead of something like: (defstruct triangle :side1 :side2 :side3) You now have: (defrecord Triangle [side1 side2 side3]) You can implement your protocol inside of the defrecord itself or use extend or extend-type. An example of doing it inside of defrecord is: (defrecord Triange [side1 side2 side3] Shape (draw [this] ; assumes sides satisfy Shape protocol (draw side1) (draw side2) (draw side3)) (rotate [this] …) …) This method works fairly well, and you can even use it to define protocols for types you don't control, such as classes from a Java API. If you need some more complicated form of dispatch for polymorphism, there is the multimethod approach. Sincerely, Daniel Solano Gómez pgpSND14zVdtO.pgp Description: PGP signature
Polymorphic functions in Clojure (or how to stop thinking in objects)...
Hi, I'd like to create a simple library of drawable shapes: lines, circles and rectangles. I've placed each type of shape in its own namespace with functions that operate on that shape kind: (ns myshapes.line) (defn line ... creates new line ...) (defn draw ... draws a line ...) To keep things simple a line is just a vector of two points and circles and rectangles are just structs. I'd also like to have a sequence of shapes called a picture: (ns myshapes.picture) (defn picture ... returns picture sequence from args ...) (defn draw ... draws whole picture) The problem I have is with the myshapes.picture/draw function. As a Clojure newb I keep wanting to think of this like a polymorphic function in the O-O world that relies on each sequence member having a draw function. What's the idiomatic way of handling a situation like this in Clojure? Do I need to use richer data structures than vectors and structs for the shapes so they carry some kind of type information? I can see how a draw multi-method would work if the individual shapes could be distinguished, or am I going about this the wrong way? Any advice much appreciated, Stu -- 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: Clojure Editor
The Clojure mode activates for me, and I get a little bit syntax coloring, autocompletion, and () matching. But I don't get language aware indentation. Should I, or isn't this supported? (It's a really important feature IMHO.) Also, no matching of [] or {} (less important for me). Thanks, -Lee On Mar 14, 2011, at 8:06 AM, WoodHacker wrote: > The file you need should be there. First look under the Document/ > Language Support menu item. You should see and entry for Clojure. > Try checking it.The syntax file is called clojure.bflang2 and it > should be in a Bluefish directory somewhere on your system. I am > using a MAC, so the file is under the /Applicatiions directory.If > you need to adjust the bflang2 file for some reason, the file that > explains how to do it is Sample.bflang2.If none of this makes > sense and you can't find clojure.bflang2, try contacting the Bluefish > people by sending and email to bluefish-us...@lists.ems.ru. > > On Mar 13, 9:49 am, Shantanu Kumar wrote: >> Do I need a plugin? I downloaded the stock 2.0.3-1 version of the >> editor and it doesn't even seem to syntax-highlight the Clojure code. >> >> Regards, >> Shantanu >> >> On Mar 13, 5:09 pm, WoodHacker wrote:> If you are >> looking for a very good editor for Clojure try Bluefish. >>> It's been around for ever, is very stable, and does everything you >>> would want an editor to do. And it now works with Clojure. >> >>>http://bluefish.openoffice.nl >> >>> Bill > -- 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: clj-ldap - Clojure LDAP client
Hi Saul, thanks for writing this. Embarrassingly I wasn't even aware of the UnboundID LDAP SDK, so it's great to find two useful things I can use right away! I would like to implement a LDAP authentication in Clojure, based around clj-ldap. Do you think it is necessary for the bind-request function to be private? In LDAP v3 bind requests can be sent at any time during a connection, so I can run a small connection pool for authentication without the overhead of creating a new connection every time someone authenticates. My plan is to take the UID and password, search the directory for the matching DN, and then bind with that DN given the provided password. Any enormous flaws in this approach? More specifically, would you consider a public bind-request function in an upcoming release? Paul On Feb 11, 1:37 am, Saul Hazledine wrote: > On Feb 10, 8:36 am, Jozef Wagner wrote: > > > One question, If I search for some entries, you return results as a sequence > > of maps. How do I get dn of some result? It seems that your entry-as-map > > converts attributes but strips away entry dn. > > > I've solved this by adding :dn key in each entry map, > > seehttps://github.com/wagjo/dredd/blob/master/src/dredd/ldap.clj#L19 > > Many thanks for spotting this important missing attribute. Thanks also > for the link to your code. After reading your version I realised that > clj-ldap should also allow attributes to be selected for an ldap/get. > > I've fixed the problem with dn, added attribute selection to ldap/get, > improved the README slightly and released this as version 0.0.2 which > is now on clojars.org. > > Saul -- 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 not using CPU on binarytree benchmark
Hi, I'm working with binarytree benchmark from the Language Shotout. http://shootout.alioth.debian.org/u64/program.php?test=binarytrees&lang=clojure&id=5 Its basiclly a port from the java version. http://shootout.alioth.debian.org/u64/program.php?test=binarytrees&lang=java&id=2 The Problem with the Clojure version you can see here: https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/AverageCPUAll.png https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/CPUAll.png Clojure does not use the CPU to the full extened witch suggest that there something blocking it. I tried to figure out what it was with profiling but I never did that befor and I had no success. Node that the Clojure uses less memory too. https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/maindoku/bilder/MemoryAll.png Has anybody an Idea why this happens? I ported the programm to 1.3 but that didn't help: 1.2 version: https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/clojure/src/bt/binarytrees.clj 1.3 version: https://github.com/nickik/IDPA-Programmiersprachen-Benchmarken/blob/master/clojure/src/bt/binarytrees_me.clj (all the benchmarks where made with the 1.2er programm) thx for the help -- 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: Evaluation of Symbol Bindings vs. Special Forms
On Mon, Mar 14, 2011 at 6:32 PM, Dominikus wrote: > I did some investigations on the code in Compiler.java. There is an > IPersistentMap called 'specials' (line 95, Clojure 1.2) that maps > symbols like 'if' to parsers like IfExpr.Parser(); obviously, these > are the parsers recognizing special forms. > > Method analyzeSeq (line 5347) tries macro expansion first and gets the > operator of a sequence form next. There is some special behavior if > the operator is FN (namely 'fn*' for which no parser is associated in > 'specials'; I don't know why 'fn*' gets special treatment here), then > special parsers are activated if the operator is a special symbol, > otherwise InvokeExpr.parse() is run. That doesn't quite seem right: user=> (defmacro if [x y] `(println ~x ~y)) #'user/if user=> (if (even? 42) "boo!") "boo!" user=> (user/if (even? 42) "boo!") true boo! nil user=> Clearly, the if special symbol, when in operator position, shadows even macros, forcing the use of a fully-qualified name to employ a macro named "if". Perhaps you meant it does macroexpansion of the subforms first, but not (yet) of the whole form? Then it checks for the whole form to be a special form; then for the whole form to be a macro in need of expansion; and then treats it as a function call. If so, it's only the subforms not in operator position that get macroexpanded first. Otherwise user=> (defmacro qqq [] 'if) #'user/qqq user=> ((qqq) (even? 42) "boo!") # would instead produce "boo!", as (qqq) would be expanded to if and then (if (even? 42) "boo!") would be parsed and discovered to be an if special form. On the other hand, user=> (quote (qqq)) (qqq) seems to indicate that nothing is macroexpanded before special form parsing occurs, or it would have output if instead of (qqq), unless quote it another 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
Logging input
I'm going to be working on clojure.tools.logging [1] (formerly clojure.contrib.logging) over the next few days. If you use the original api [2], or plan on using the one in development [3], and have any feedback, please open a jira ticket or post a reply. [1] https://github.com/clojure/tools.logging [2] http://clojure.github.com/clojure-contrib/logging-api.html [3] http://clojure.github.com/clojure-contrib/branch-master/logging-api.html -- 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: Evaluation of Symbol Bindings vs. Special Forms
I did some investigations on the code in Compiler.java. There is an IPersistentMap called 'specials' (line 95, Clojure 1.2) that maps symbols like 'if' to parsers like IfExpr.Parser(); obviously, these are the parsers recognizing special forms. Method analyzeSeq (line 5347) tries macro expansion first and gets the operator of a sequence form next. There is some special behavior if the operator is FN (namely 'fn*' for which no parser is associated in 'specials'; I don't know why 'fn*' gets special treatment here), then special parsers are activated if the operator is a special symbol, otherwise InvokeExpr.parse() is run. All this works as expected. Method analyze (line 5154) analyzes a given expression. If its a symbol, then analyzeSymbol (line 5556) is called, if its a form of kind ISeq, then analyzeSeq is called. There are more checks, of course. As one can see in analyzeSymbol, bindings are resolved but there is no check whether a special symbol like 'if' is used or not. The analysis of the code confirms the behavior of a "redefined" i.e. bound 'if' symbol. In favor of a consistent user experience (as described in the previous post), it simply shouldn't be possible to bind special symbols like 'if' to values at all. I guess that some few lines in Compiler.java could fix that. I don't know how Lisp treats this case. Dominikus On 14 Mrz., 22:09, Timothy Baldridge wrote: > Yes, I think if you dig down into the Compiler.java code (that's where > I assume this issue comes from) you'll probably find your answer. > > Recently in a blog entry Eric Lippert (one of the developers of C#) > handled this exact subject. There are some 'bugs' in languages that > exist, not because the developers don't know that they exist, but > because actually reproducing the bug results in code that would never > be used in production code. Sure this could be viewed as a bug, but > who cares? > > Timothy > > > > > > > > >> I think this is an inconsistent interaction model -- it might even > >> hint towards an implementation flaw. If I manually decompose a list > >> form and analyze its elements in isolation (first evaluate 'if' and > >> then '3' in the REPL), the composite list form should behave > >> accordingly, shouldn't it? -- 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: (.contains (transient #{}) 17) ==> true!?!
On Mon, Mar 14, 2011 at 4:41 PM, Alan wrote: > Thanks Ken, I found this too when I saw Tassilo's problem on irc > (didn't notice it was on ML as well). I was going submit a patch for > this, but if you've already done so let me know and I won't. I don't have a CA so no, I haven't. Go ahead. -- 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: Evaluation of Symbol Bindings vs. Special Forms
Yes, I think if you dig down into the Compiler.java code (that's where I assume this issue comes from) you'll probably find your answer. Recently in a blog entry Eric Lippert (one of the developers of C#) handled this exact subject. There are some 'bugs' in languages that exist, not because the developers don't know that they exist, but because actually reproducing the bug results in code that would never be used in production code. Sure this could be viewed as a bug, but who cares? Timothy >> I think this is an inconsistent interaction model -- it might even >> hint towards an implementation flaw. If I manually decompose a list >> form and analyze its elements in isolation (first evaluate 'if' and >> then '3' in the REPL), the composite list form should behave >> accordingly, shouldn't it? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple replacements in string using a map
There is also this contrib code which facilitates string interpolation: http://clojure.github.com/clojure-contrib/strint-api.html But I second Ken's concern about SQL injection attacks. -- 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: Evaluation of Symbol Bindings vs. Special Forms
2011/3/14 Dominikus > This was also my best guess, Timothy and Stuart, but it does not > explain why a redefined 'if' (or a competing symbol binding, Stuart?) > in the REPL leads to > > user=> if > # > My best guess is because it's not in a callable position (ie not the first element of a list. > > while 'if' within a list form does not: > > user=> (if 3) > java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:74) > > I think this is an inconsistent interaction model -- it might even > hint towards an implementation flaw. If I manually decompose a list > form and analyze its elements in isolation (first evaluate 'if' and > then '3' in the REPL), the composite list form should behave > accordingly, shouldn't it? > > I come up with this scenario in order to understand the precise > behavior of Clojure's evaluation strategy regarding symbol bindings > and special forms. As I said, I'm fully aware that it's no good idea > to change 'if' or any other special forms in production code. > > Dominikus > > On 14 Mrz., 18:26, Stuart Sierra wrote: > > Yes, with one correction: Clojure is not an interpreter. The Clojure > > compiler treats certain symbols specially, such as `if`, `do`, and `def`. > > You cannot redefine these symbols. > > > > -Stuart Sierra > > clojure.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 > -- 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: (.contains (transient #{}) 17) ==> true!?!
Thanks Ken, I found this too when I saw Tassilo's problem on irc (didn't notice it was on ML as well). I was going submit a patch for this, but if you've already done so let me know and I won't. On Mar 14, 12:37 pm, Ken Wesson wrote: > On Mon, Mar 14, 2011 at 4:13 PM, Tassilo Horn wrote: > > Hi all, > > > I've implemented IEditableCollection support for ninjudd's > > PersistentOrderedSet. But when using that, my application delivered > > wrong results. See <87hbb6c4qf@member.fsf.org> and follow-ups. > > > I was able to track it down to the strangeness in the subject: > > > (.contains (transient (hash-set)) foo) > > > returns true for any object foo, that is, the empty transient hash-set > > contains everything. > > > The above clojure code is equivalent to this java code, which I used in > > the PersistentOrderedSet extension: > > > ((ITransientSet) PersistentHashSet.EMPTY.asTransient()).contains(o) > > > For now, I worked around this strange behavior by checking the count() > > of the TransientHashSet backing my TransientOrderedSet implementation in > > addition to contains(). > > > But anyway: Is that behavior intended and facilitated internally > > somehow? If so, is there some documentation about the rationale? > > > Bye, > > Tassilo > > At first blush, the answer appears to be "no". > > Here is APersistentSet.contains: > > public boolean contains(Object key){ > return impl.containsKey(key); > > } > > Here is ATransientSet.contains: > > public boolean contains(Object key) { > return this != impl.valAt(key, this); > > } > > This should probably use a sentinel; it's possible to put a transient > map into itself, at least in principle. But the real problem: > > user=> (.valAt (.asTransient clojure.lang.PersistentHashMap/EMPTY) 1 42) > nil > > Oops! This should have returned 42, not nil! > > The actual error is on line 278 of PersistentHashMap.java: > > Object doValAt(Object key, Object notFound) { > if (key == null) > if (hasNull) > return nullValue; > else > return notFound; > if (root == null) > return null; > return root.find(0, Util.hash(key), key, notFound); > > } > > This obviously should say > > if (root == null) > return notFound; > > !!! -- 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: (.contains (transient #{}) 17) ==> true!?!
On Mon, Mar 14, 2011 at 4:13 PM, Tassilo Horn wrote: > Hi all, > > I've implemented IEditableCollection support for ninjudd's > PersistentOrderedSet. But when using that, my application delivered > wrong results. See <87hbb6c4qf@member.fsf.org> and follow-ups. > > I was able to track it down to the strangeness in the subject: > > (.contains (transient (hash-set)) foo) > > returns true for any object foo, that is, the empty transient hash-set > contains everything. > > The above clojure code is equivalent to this java code, which I used in > the PersistentOrderedSet extension: > > ((ITransientSet) PersistentHashSet.EMPTY.asTransient()).contains(o) > > For now, I worked around this strange behavior by checking the count() > of the TransientHashSet backing my TransientOrderedSet implementation in > addition to contains(). > > But anyway: Is that behavior intended and facilitated internally > somehow? If so, is there some documentation about the rationale? > > Bye, > Tassilo At first blush, the answer appears to be "no". Here is APersistentSet.contains: public boolean contains(Object key){ return impl.containsKey(key); } Here is ATransientSet.contains: public boolean contains(Object key) { return this != impl.valAt(key, this); } This should probably use a sentinel; it's possible to put a transient map into itself, at least in principle. But the real problem: user=> (.valAt (.asTransient clojure.lang.PersistentHashMap/EMPTY) 1 42) nil Oops! This should have returned 42, not nil! The actual error is on line 278 of PersistentHashMap.java: Object doValAt(Object key, Object notFound) { if (key == null) if (hasNull) return nullValue; else return notFound; if (root == null) return null; return root.find(0, Util.hash(key), key, notFound); } This obviously should say if (root == null) return notFound; !!! -- 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: Evaluation of Symbol Bindings vs. Special Forms
This was also my best guess, Timothy and Stuart, but it does not explain why a redefined 'if' (or a competing symbol binding, Stuart?) in the REPL leads to user=> if # while 'if' within a list form does not: user=> (if 3) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:74) I think this is an inconsistent interaction model -- it might even hint towards an implementation flaw. If I manually decompose a list form and analyze its elements in isolation (first evaluate 'if' and then '3' in the REPL), the composite list form should behave accordingly, shouldn't it? I come up with this scenario in order to understand the precise behavior of Clojure's evaluation strategy regarding symbol bindings and special forms. As I said, I'm fully aware that it's no good idea to change 'if' or any other special forms in production code. Dominikus On 14 Mrz., 18:26, Stuart Sierra wrote: > Yes, with one correction: Clojure is not an interpreter. The Clojure > compiler treats certain symbols specially, such as `if`, `do`, and `def`. > You cannot redefine these symbols. > > -Stuart Sierra > clojure.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
(.contains (transient #{}) 17) ==> true!?!
Hi all, I've implemented IEditableCollection support for ninjudd's PersistentOrderedSet. But when using that, my application delivered wrong results. See <87hbb6c4qf@member.fsf.org> and follow-ups. I was able to track it down to the strangeness in the subject: (.contains (transient (hash-set)) foo) returns true for any object foo, that is, the empty transient hash-set contains everything. The above clojure code is equivalent to this java code, which I used in the PersistentOrderedSet extension: ((ITransientSet) PersistentHashSet.EMPTY.asTransient()).contains(o) For now, I worked around this strange behavior by checking the count() of the TransientHashSet backing my TransientOrderedSet implementation in addition to contains(). But anyway: Is that behavior intended and facilitated internally somehow? If so, is there some documentation about the rationale? 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
Re: IEditableCollection support for Justin Balthrop's PersistentOrderedSet
Tassilo Horn writes: Hi again, > Now I've spotted the problem, although I don't know how to fix it yet. > The problem is that my implementation doesn't work with LazySeqs. A > minimal example at the REPL is that: > > funql.test.core> (into (ordered-set) (take 10 (iterate inc 0))) > #{} > > Here, I want to put the first 10 natural numbers into the empty ordered > set, but the result is empty. My observation was false. The problem is not the the second parameter, but the first one. If the PersistentOrderedSet given to `into' is empty, then the transient version fails: funql.core> (into (ordered-set) [1 2 3]) #{} Or doing what `into' does manually: funql.core> (persistent! (conj! (transient (ordered-set)) 1)) #{} Of course, the non-transient variant works as expected: funql.core> (conj (ordered-set) 1) #{1} Then I added some debug code to my TransientOrderedSet.conj() method: --8<---cut here---start->8--- static final class TransientOrderedSet extends AFn implements ITransientSet { ITransientSet items; ITransientVector order; @Override public ITransientSet conj(Object obj) { if (items.contains(obj)) { System.out.println(obj // DEBUGGING OUTPUT + " is already contained in the ordered set of " + items.count() + " items, doing nothing!"); return this; } ITransientSet s = (ITransientSet) items.conj(obj); if (s != items) { items = s; } ITransientVector v = (ITransientVector) order.conj(obj); if (v != order) { order = v; } return this; } } --8<---cut here---end--->8--- With the debugging version in the REPL, the call (persistent! (conj! (transient (ordered-set)) 1)) prints 1 is already contained in the ordered set of 0 items, doing nothing! How can it be that an empty ITransientSet (which is really a TransientHashSet) contains 1? (In fact, you can try to conjoin arbitrary elements, it'll always state that the element is already contained). Contrarily, when conjoining into a TransientOrderedSet that was created for an PersistentOrderedSet that was in turn created with a non-empty constructor, it works as expected: funql.core> (persistent! (conj! (transient (ordered-set 0)) 1)) #{0 1} I now have fixed it by implementing contains() as follows and using that throughout my class instead of only invoking the contains() on the TransientHashSet backing the TransientOrderedSet... public boolean contains(Object obj) { // FIXME: This is a workaround for the puzzling fact that // PersistentHashSet.EMPTY.asTransient().contains(o) for any Object // o. return (items.count() != 0) && items.contains(obj); } I will open a separate thread on this exact issue. 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
Re: DDJ for Clojure/Lisp/FP
On Mon, Mar 14, 2011 at 5:23 PM, Andreas Kostler wrote: > Something along those lines. The key would be to have low publication latency > e.g. articles undergo a initial review in a matter of hours so it > still has the blog vibe to it but undergo stricter quality control. The Monad Reader [http://themonadreader.wordpress.com/] is a good source of inspiration. martin -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple replacements in string using a map
On Mon, Mar 14, 2011 at 2:17 PM, Daniel Solano Gomez wrote: > On Mon Mar 14 13:02 2011, shuaybi2 shuaybi2 wrote: >> I have a string such as: >> >> "select * from account where acctId = _ACCT-ID_ and acctTyp = _ACCT-TYP_" >> >> I have a map such as: >> >> {:_ACCT-ID_ 9876 :_ACCT-TYP "B"} >> >> I want to write a clojure function that will take the string and map as a >> parameter and return me the string with all values from the map substituted. >> >> Output: >> >> select * from account where acctId = 9876 and acctTyp = 'B' >> >> Thanks for your help. > > Something like the following does the trick: > > (defn substitute-mappings > [string mappings] > (let [substitute-mapping > (fn [string mapping] > (let [pattern (java.util.regex.Pattern/quote (name (key mapping))) > pattern (re-pattern pattern) > matcher (re-matcher pattern string) > replacement (java.util.regex.Matcher/quoteReplacement (str > (val mapping)))] > (.replaceAll matcher replacement)))] > (reduce substitute-mapping string (seq mappings > > It uses reduce with an local function so that the string gets its > replacements one at a time. Actually doing the replacement uses Java's > regular expressions. > > Just a few notes about the above: > > 1. quote and quoteReplacement to take care of any special characters > that may otherwise muck up replacement process > 2. The name function is used to convert a keyword to a string without > the initial colon. > 3. For integers and the like, I use the str function to coerce them into > a string that can be used as a replacement pattern. So, you'd want > to make sure this works correctly with any data types you want to > use. Do we have a str function that will prevent the use of {:_ACCT-ID_ "9876; delete * from account;"}? ;) Or are those maps only ever going to be visible to the application's internals? -- 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: Evaluation of Symbol Bindings vs. Special Forms
On Mon, Mar 14, 2011 at 5:11 AM, Dominikus wrote: > But I can call the redefined 'if' only with a qualified symbol name > > user=> (user/if 3) > 9 Or using apply: user=> (apply if [3]) 9 You can even just rename it: user=> (let [a if] (a 3)) 9 Cute, but you probably shouldn't be doing this in production code without a *real* good reason. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Multiple replacements in string using a map
On Mon Mar 14 13:02 2011, shuaybi2 shuaybi2 wrote: > I have a string such as: > > "select * from account where acctId = _ACCT-ID_ and acctTyp = _ACCT-TYP_" > > I have a map such as: > > {:_ACCT-ID_ 9876 :_ACCT-TYP "B"} > > I want to write a clojure function that will take the string and map as a > parameter and return me the string with all values from the map substituted. > > Output: > > select * from account where acctId = 9876 and acctTyp = 'B' > > Thanks for your help. Something like the following does the trick: (defn substitute-mappings [string mappings] (let [substitute-mapping (fn [string mapping] (let [pattern (java.util.regex.Pattern/quote (name (key mapping))) pattern (re-pattern pattern) matcher (re-matcher pattern string) replacement (java.util.regex.Matcher/quoteReplacement (str (val mapping)))] (.replaceAll matcher replacement)))] (reduce substitute-mapping string (seq mappings It uses reduce with an local function so that the string gets its replacements one at a time. Actually doing the replacement uses Java's regular expressions. Just a few notes about the above: 1. quote and quoteReplacement to take care of any special characters that may otherwise muck up replacement process 2. The name function is used to convert a keyword to a string without the initial colon. 3. For integers and the like, I use the str function to coerce them into a string that can be used as a replacement pattern. So, you'd want to make sure this works correctly with any data types you want to use. Sincerely, Daniel Solano Gómez pgpPShNY0Mieb.pgp Description: PGP signature
Multiple replacements in string using a map
I have a string such as: "select * from account where acctId = _ACCT-ID_ and acctTyp = _ACCT-TYP_" I have a map such as: {:_ACCT-ID_ 9876 :_ACCT-TYP "B"} I want to write a clojure function that will take the string and map as a parameter and return me the string with all values from the map substituted. Output: select * from account where acctId = 9876 and acctTyp = 'B' Thanks for your help. -- 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: Evaluation of Symbol Bindings vs. Special Forms
Yes, with one correction: Clojure is not an interpreter. The Clojure compiler treats certain symbols specially, such as `if`, `do`, and `def`. You cannot redefine these symbols. -Stuart Sierra clojure.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: IEditableCollection support for Justin Balthrop's PersistentOrderedSet
Tassilo Horn writes: Hi again, > I use Justin Balthrop's (ninjudd) nice ordered-set library [fn:1] in > my application. Because I frequently merge several sets using `into', > I wondered if I could get a performance win if PersistentOrderedSet > would support going transient by implementing the IEditableCollection > interface by providing a new TransientOrderedSet class and the > relevant asTransient() method for PersistentOrderedSet. > > I've now added support for that (patch against the git master version > attached to this mail, or the complete java file posted at > http://pastebin.com/H2k9q75u where changes/additions start at line 202). > > Unfortunately, it doesn't work correctly, i.e., I get wrong results > (ordered sets that do not contain everything my test cases expect). But > I'm not able to produce some minimal test case at the repl. Now I've spotted the problem, although I don't know how to fix it yet. The problem is that my implementation doesn't work with LazySeqs. A minimal example at the REPL is that: funql.test.core> (into (ordered-set) (take 10 (iterate inc 0))) #{} Here, I want to put the first 10 natural numbers into the empty ordered set, but the result is empty. Any ideas? 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
Re: DDJ for Clojure/Lisp/FP
I have written a long-form article on zippers and tree-editing in Clojure under contract for CQ. I talked to Peter a few weeks ago and he is still working on the first issue. Hopefully it will emerge. :) Alex On Mar 13, 9:28 pm, Andreas Kostler wrote: > On 14/03/2011, at 12:05 PM, Alan Dipert wrote: > > > Hi Andreas, > > >> Is there something like Doctor Dobbs Journal for Clojure/Lisp or even > >> functional programming related topics? > > > To my knowledge, not yet. Peter Seibel's yet-to-be-published "Code > > Quarterly" sounds similar to what you're looking for: > >http://www.codequarterly.com/ > > This certainly sounds/reads interesting. It is to be seen how much > Clojure/Lisp content there will be > and how many every-day problems it will address. How long hast this been > around? > > > > >> If there isn't, is it worthwhile starting an effort into this direction? > > > I don't see why not! > > > Alan > > clojure.com > > -- > "Test-driven Dentistry (TDD!) - Not everything should be test driven" > - Michael Fogus > -- > ** > Andreas Koestler, Software Engineer > Leica Geosystems Pty Ltd > 270 Gladstone Road, Dutton Park QLD 4102 > Main: +61 7 3891 9772 Direct: +61 7 3117 8808 > Fax: +61 7 3891 9336 > Email: andreas.koest...@leica-geosystems.com > > www.leica-geosystems.com* > > when it has to be right, Leica Geosystems > > Please consider the environment before printing this email. -- 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: Evaluation of Symbol Bindings vs. Special Forms
I think it's probably this way because if is built right into the interpreter. So probably the symbol resolution goes something like this, in the compiler: if symbol is in special forms then emit special form else emit call to user function Many of the built-in functions (even the fn symbol) are defined in clojure's core.clj. These are defined on a clojure level, and as such can be re-defed. However, other functions like def, fn* and if are actually functions built in Java code in the compiler, so you can't really re-order those, just because of they way they are evaluated. I could be wrong however. Timothy On Mon, Mar 14, 2011 at 4:11 AM, Dominikus wrote: > I'm not sure I fully understand symbol resolution and the evaluation > strategy of symbol bindings and special forms in Clojure 1.2. > > Let's say I bind 'if' (usually being a special form) to a function: > > user=> (defn if [x] (* x x)) > #'user/if > > However, calling 'if' with an unqualified name does not work. Still, > 'if' works like a special form: > > user=> (if 3) > java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:74) > user=> (if true 1 2) > 1 > > However, 'if' itself evaluates to the new function on the REPL: > > user=> if > # > > But I can call the redefined 'if' only with a qualified symbol name > > user=> (user/if 3) > 9 > > Why is that? I find it inconsistent to see 'if' evaluating to a > function in the REPL but not in the context of a list; in a list form > I'm forced to use a qualified name to suppress interpretation as a > special form. What is the precise evaluation strategy? (I know, it's > dangerous to redefine special forms. Here, I'm interested in the > evaluation strategy of special forms vs. bound symbols.) > > Cheers, > > Dominikus > > -- > 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 -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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: clj-string template
hi Shantanu, i ll answer pt 2 first, I was referring to IDE. regarding groups,We have a use case of subtemplates. I have used clj-stringtempalte to render all emails and likewise for our organisation. So, sometimes we need to add st components inside the master template. For now, i am directly accessing the template using $template-classpath$ Thanks Himangshu On 14 March 2011 08:21, Shantanu Kumar wrote: > Hi Himangshu, > > Author of Clj-StringTemplate here. Yes, my focus has been on database > libraries for some time - I was intending to come back to it sometime > around StringTemplate 4.0 (which is not released yet) timeline but I > can respond to a feature request sooner. > > For the next (v0.3) release I am planning to add a ring-middleware to > automatically render body against a template and the model (map), but > I will certainly consider supporting groups. Just so I understand > better please let me know how do you use groups and what do you use > them for - what is your workflow? > > As for syntax highlighter - are you talking about this support in > IDEs? > > Regards, > Shantanu > > On Mar 14, 6:25 am, himangshu hazarika wrote: > > Hi guys, > > is clj-string template kind of dormant. there has been not much of > activity, > > Does it support groups as of now?? Are thr ny syntax highlighter for the > > templates. > > > > Regards > > Himangshu > > -- > 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
Evaluation of Symbol Bindings vs. Special Forms
I'm not sure I fully understand symbol resolution and the evaluation strategy of symbol bindings and special forms in Clojure 1.2. Let's say I bind 'if' (usually being a special form) to a function: user=> (defn if [x] (* x x)) #'user/if However, calling 'if' with an unqualified name does not work. Still, 'if' works like a special form: user=> (if 3) java.lang.Exception: Too few arguments to if (NO_SOURCE_FILE:74) user=> (if true 1 2) 1 However, 'if' itself evaluates to the new function on the REPL: user=> if # But I can call the redefined 'if' only with a qualified symbol name user=> (user/if 3) 9 Why is that? I find it inconsistent to see 'if' evaluating to a function in the REPL but not in the context of a list; in a list form I'm forced to use a qualified name to suppress interpretation as a special form. What is the precise evaluation strategy? (I know, it's dangerous to redefine special forms. Here, I'm interested in the evaluation strategy of special forms vs. bound symbols.) Cheers, Dominikus -- 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: Clojure Editor
The file you need should be there. First look under the Document/ Language Support menu item. You should see and entry for Clojure. Try checking it.The syntax file is called clojure.bflang2 and it should be in a Bluefish directory somewhere on your system. I am using a MAC, so the file is under the /Applicatiions directory.If you need to adjust the bflang2 file for some reason, the file that explains how to do it is Sample.bflang2.If none of this makes sense and you can't find clojure.bflang2, try contacting the Bluefish people by sending and email to bluefish-us...@lists.ems.ru. On Mar 13, 9:49 am, Shantanu Kumar wrote: > Do I need a plugin? I downloaded the stock 2.0.3-1 version of the > editor and it doesn't even seem to syntax-highlight the Clojure code. > > Regards, > Shantanu > > On Mar 13, 5:09 pm, WoodHacker wrote:> If you are > looking for a very good editor for Clojure try Bluefish. > > It's been around for ever, is very stable, and does everything you > > would want an editor to do. And it now works with Clojure. > > > http://bluefish.openoffice.nl > > > Bill -- 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: DDJ for Clojure/Lisp/FP
Something along those lines. The key would be to have low publication latency e.g. articles undergo a initial review in a matter of hours so it still has the blog vibe to it but undergo stricter quality control. On 14/03/2011, at 8:57 PM, Nick Zbinden wrote: > This sounds very good. It would have to be start up with one topic > (lisp or FP) and if the system worked you could add more topics. > > The length could be like steve yeggy blogposts or like the ibm ähh > articals (http://www.ibm.com/developerworks/java/library/j-clojure- > protocols/). > > On Mar 14, 11:12 am, Andreas Kostler > wrote: >> On 14/03/2011, at 8:00 PM, Saul Hazledine wrote: >> >> >> >>> On Mar 14, 3:41 am, Andreas Kostler >>> wrote: >> Maybe this group could finally get the ball rolling...Surely a collection of highly talented individuals could initiate a forum for technical exchange at the level Peter suggests (somewhere between a blog and a book) - basically the level DDJ is operating at these days. >> >>> The level you mention suggests some sort of review (possibly >>> anonymous?). >> >>> One possibility is to base it around a web application to make things >>> relatively low maintenance. Just an idea for discussion - somebody >>> could submit a text in the style of a blog post which is then passed >>> to relevant reviewers who come back with comments. If the post isn't >>> accepted the author doesn't loose much as they can then post it as a >>> normal blog. >> >> That's exactly what I mean. I was thinking of some sort of exponential >> review process...at first it gets submitted to 4 people, if 3 give their >> thumbs >> up it gets published and submitted to 16 people and so on. The more people >> give their thumbs up, the higher it will appear on the main page. Something >> along those lines. >> One could also introduce elements like stackoverflow does (medals etc) to >> encourage >> people a) to publish and b) to review. >> Ranking the post in terms of positive reviews boosts 'good' posts :) >> This is just a first thought and certainly could use some refinement. >> >> Having said that, I'd like to see the quality and extent of the posts to be >> somewhere between research papers and blogposts. >> >> >> >>> The reviewing is work but if its kept in the style of a blog post >>> rather than an academic paper the overhead shouldn't be too high. The >>> use of an application would reduce the need for an editor. >> >>> Saul >> >>> -- >>> 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 -- "Test-driven Dentistry (TDD!) - Not everything should be test driven" - Michael Fogus -- ** Andreas Koestler, Software Engineer Leica Geosystems Pty Ltd 270 Gladstone Road, Dutton Park QLD 4102 Main: +61 7 3891 9772 Direct: +61 7 3117 8808 Fax: +61 7 3891 9336 Email: andreas.koest...@leica-geosystems.com www.leica-geosystems.com* when it has to be right, Leica Geosystems Please consider the environment before printing this email. -- 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
IEditableCollection support for Justin Balthrop's PersistentOrderedSet
Hi all, I use Justin Balthrop's (ninjudd) nice ordered-set library [fn:1] in my application. Because I frequently merge several sets using `into', I wondered if I could get a performance win if PersistentOrderedSet would support going transient by implementing the IEditableCollection interface by providing a new TransientOrderedSet class and the relevant asTransient() method for PersistentOrderedSet. I've now added support for that (patch against the git master version attached to this mail, or the complete java file posted at http://pastebin.com/H2k9q75u where changes/additions start at line 202). Unfortunately, it doesn't work correctly, i.e., I get wrong results (ordered sets that do not contain everything my test cases expect). But I'm not able to produce some minimal test case at the repl. My application doesn't use transient directly, but only by calling (into s1 s2). To exclude that I accidentially broke the persistent ordered-set implementation, I redefined `into' to not go transient. When doing so, my application's test suite succeeds again. So it can be concluded that my TransientOrderedSet class contains some bug. Sadly, I cannot spot it, and my knowledge of the clojure java classes is pretty much at level zero. It would be awesome if someone with a better knowledge could check my code for obvious mistakes. Bye, Tassilo Footnotes: [fn:1] https://github.com/ninjudd/ordered-set >From a292366da91ceb9fb346e9edb5a3b40505c631fa Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 10 Mar 2011 20:28:55 +0100 Subject: [PATCH] - implement IEditableCollection to allow for going transient - bump version to 0.2.0 --- project.clj|7 +- src/clj/ordered_set.clj|3 +- src/jvm/clojure/lang/PersistentOrderedSet.java | 421 3 files changed, 281 insertions(+), 150 deletions(-) diff --git a/project.clj b/project.clj index 4a927fd..62c8bd7 100644 --- a/project.clj +++ b/project.clj @@ -1,3 +1,6 @@ -(defproject ordered-set "0.1.0" +(defproject ordered-set "0.2.0" :description "A Clojure set that maintains the insertion order of items" - :dependencies [[clojure "1.2.0-master-SNAPSHOT"]]) + :dependencies [[clojure "1.2.0"]] + :source-path "src/clj/" + :java-source-path "src/jvm/" + :javac-options {:destdir "classes/"}) diff --git a/src/clj/ordered_set.clj b/src/clj/ordered_set.clj index 7152edb..32b 100644 --- a/src/clj/ordered_set.clj +++ b/src/clj/ordered_set.clj @@ -1,5 +1,4 @@ -(ns ordered-set - (:import [clojure.lang PersistentOrderedSet])) +(ns ordered-set) (defn ordered-set [& items] (clojure.lang.PersistentOrderedSet/create items)) diff --git a/src/jvm/clojure/lang/PersistentOrderedSet.java b/src/jvm/clojure/lang/PersistentOrderedSet.java index e0a5136..7315a6e 100644 --- a/src/jvm/clojure/lang/PersistentOrderedSet.java +++ b/src/jvm/clojure/lang/PersistentOrderedSet.java @@ -4,150 +4,279 @@ import java.io.Serializable; import java.util.Collection; import java.util.Iterator; import java.util.Set; - -public class PersistentOrderedSet extends AFn implements IPersistentSet, IObj, Collection, Set, Serializable, Counted { - -static public final PersistentOrderedSet EMPTY = new PersistentOrderedSet(null, PersistentHashSet.EMPTY, PersistentVector.EMPTY); - -final IPersistentMap _meta; -final IPersistentSet items; -final PersistentVector order; - -protected PersistentOrderedSet(IPersistentMap meta, IPersistentSet items, PersistentVector order){ - this._meta = meta; - this.items = items; - this.order = order; -} - -static public PersistentOrderedSet create(ISeq items){ - PersistentOrderedSet set = EMPTY; - for(; items != null; items = items.next()) { -set = (PersistentOrderedSet) set.cons(items.first()); - } - return set; -} - -public IPersistentSet disjoin(Object item) throws Exception{ - if (!contains(item)) return this; - - PersistentVector.TransientVector new_order = PersistentVector.EMPTY.asTransient(); - ISeq s = seq(); - for (; s != null; s = s.next()) { -if (s.first() != item) new_order = new_order.conj(s.first()); - } - return new PersistentOrderedSet(_meta, items.disjoin(item), new_order.persistent()); -} - -public IPersistentSet cons(Object item){ - if (contains(item)) return this; - return new PersistentOrderedSet(_meta, (IPersistentSet) items.cons(item), order.cons(item)); -} - -public IPersistentCollection empty(){ - return EMPTY.withMeta(meta()); -} - -public PersistentOrderedSet withMeta(IPersistentMap meta){ - return new PersistentOrderedSet(meta, items, order); -} - -public IPersistentMap meta(){ - return _meta; -} - -public String toString(){ - return RT.printString(this); -} - -public Object get(Object key){ - return items.get(key); -} - -public boolean contains(Object key){ - return items.contains(key); -} - -public boolean containsAll(Collection c){ - for (Object item : c) { -if (!contains(item)) return false; - } - return true
Re: DDJ for Clojure/Lisp/FP
This sounds very good. It would have to be start up with one topic (lisp or FP) and if the system worked you could add more topics. The length could be like steve yeggy blogposts or like the ibm ähh articals (http://www.ibm.com/developerworks/java/library/j-clojure- protocols/). On Mar 14, 11:12 am, Andreas Kostler wrote: > On 14/03/2011, at 8:00 PM, Saul Hazledine wrote: > > > > > On Mar 14, 3:41 am, Andreas Kostler > > wrote: > > >> Maybe this group could finally get the ball rolling...Surely a collection > >> of highly talented individuals could initiate a forum for > >> technical exchange at the level Peter suggests (somewhere between a blog > >> and a book) - basically the level DDJ is operating > >> at these days. > > > The level you mention suggests some sort of review (possibly > > anonymous?). > > > One possibility is to base it around a web application to make things > > relatively low maintenance. Just an idea for discussion - somebody > > could submit a text in the style of a blog post which is then passed > > to relevant reviewers who come back with comments. If the post isn't > > accepted the author doesn't loose much as they can then post it as a > > normal blog. > > That's exactly what I mean. I was thinking of some sort of exponential > review process...at first it gets submitted to 4 people, if 3 give their > thumbs > up it gets published and submitted to 16 people and so on. The more people > give their thumbs up, the higher it will appear on the main page. Something > along those lines. > One could also introduce elements like stackoverflow does (medals etc) to > encourage > people a) to publish and b) to review. > Ranking the post in terms of positive reviews boosts 'good' posts :) > This is just a first thought and certainly could use some refinement. > > Having said that, I'd like to see the quality and extent of the posts to be > somewhere between research papers and blogposts. > > > > > The reviewing is work but if its kept in the style of a blog post > > rather than an academic paper the overhead shouldn't be too high. The > > use of an application would reduce the need for an editor. > > > Saul > > > -- > > 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: DDJ for Clojure/Lisp/FP
On 14/03/2011, at 8:00 PM, Saul Hazledine wrote: > On Mar 14, 3:41 am, Andreas Kostler > wrote: >> >> Maybe this group could finally get the ball rolling...Surely a collection of >> highly talented individuals could initiate a forum for >> technical exchange at the level Peter suggests (somewhere between a blog and >> a book) - basically the level DDJ is operating >> at these days. >> > > The level you mention suggests some sort of review (possibly > anonymous?). > > One possibility is to base it around a web application to make things > relatively low maintenance. Just an idea for discussion - somebody > could submit a text in the style of a blog post which is then passed > to relevant reviewers who come back with comments. If the post isn't > accepted the author doesn't loose much as they can then post it as a > normal blog. That's exactly what I mean. I was thinking of some sort of exponential review process...at first it gets submitted to 4 people, if 3 give their thumbs up it gets published and submitted to 16 people and so on. The more people give their thumbs up, the higher it will appear on the main page. Something along those lines. One could also introduce elements like stackoverflow does (medals etc) to encourage people a) to publish and b) to review. Ranking the post in terms of positive reviews boosts 'good' posts :) This is just a first thought and certainly could use some refinement. Having said that, I'd like to see the quality and extent of the posts to be somewhere between research papers and blogposts. > > The reviewing is work but if its kept in the style of a blog post > rather than an academic paper the overhead shouldn't be too high. The > use of an application would reduce the need for an editor. > > Saul > > -- > 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: DDJ for Clojure/Lisp/FP
On Mar 14, 3:41 am, Andreas Kostler wrote: > > Maybe this group could finally get the ball rolling...Surely a collection of > highly talented individuals could initiate a forum for > technical exchange at the level Peter suggests (somewhere between a blog and > a book) - basically the level DDJ is operating > at these days. > The level you mention suggests some sort of review (possibly anonymous?). One possibility is to base it around a web application to make things relatively low maintenance. Just an idea for discussion - somebody could submit a text in the style of a blog post which is then passed to relevant reviewers who come back with comments. If the post isn't accepted the author doesn't loose much as they can then post it as a normal blog. The reviewing is work but if its kept in the style of a blog post rather than an academic paper the overhead shouldn't be too high. The use of an application would reduce the need for an editor. Saul -- 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: borneo - Clojure wrapper for Neo4j, a graph database.
On Mar 13, 5:55 pm, Jozef Wagner wrote: > On Thursday, March 10, 2011 12:50:13 PM UTC+1, Jeff Rose wrote: > > > Out of curiosity, why did you go with Neo4j rather than using jiraph? > > (https://github.com/ninjudd/jiraph) I used neo4j in the past, and if > > I remember right my main annoyance was that edges had to be traversed > > based on the type of the edge instance object, which felt annoying > > from a language like clojure where I rarely want to think about Java > > types in this way, especially since they are all implementing the > > Relationship interface. Instead with Jiraph you can traverse edges by > > inspecting arbitrary edge properties. It's also a native clojure lib > > so the API is quite easy to work with. > > Well for my purposes, I needed a stable, robust and well tested database. > Moreover, I'm more accustomed to the traditional graphs; your multi-layered > approach is new to me and I don't know if it wouldn't bring some constraints > to the design of the application and data logic. I didn't write jiraph, but in terms of the layers you can just put everything in the same layer if you want. That's what I'm doing. Splitting to multiple layers seems like more of a performance optimization if it works for you, rather than a constraint. > It would be nice if you could translate my borneo graph example into jiraph. > Both are clojure libs so we could compare it in terms of both syntax and > design of the graph. If I find some time I'll do this. -Jeff -- 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: intersection and union on sequences/lists
(defn bag-of [coll] (apply bag coll)) just so we have analogues of both vec and vector here. -- 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: intersection and union on sequences/lists
On Mon, Mar 14, 2011 at 4:12 AM, Alan wrote: > By the way, thanks for the very thorough Bag implementation. Your > implementations of the very detailed things that people wish Clojure > had are always interesting reading. You're welcome. I solved the count problem independently, but thanks for the advice anyway. The presence of the count method in the specification of IPersistentCollection puzzles me, if it's never called unless an object also implements Counted (why not ICounted?), which specifies the same method anyway. -- 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: intersection and union on sequences/lists
By the way, thanks for the very thorough Bag implementation. Your implementations of the very detailed things that people wish Clojure had are always interesting reading. On Mar 14, 12:49 am, Ken Wesson wrote: > > Well, except that count and empty are broken for some reason: > > > user=> (.count (Bag. {} 0)) > > 0 > > user=> (count (Bag. {} 0)) > > 1 > > > I don't understand what's causing this, but empty bags are always > > returning a count of 1 (and false from empty?) although the .count > > method correctly returns zero. I've traced the problem as far as the > > Java method clojure.lang.RT/count but no farther at this time. > > Argh. This same bug causes union to blow up in the case of (union (bag > 1) (bag)). It works with (union #{1} #{}), by contrast. It traces back > to empty? wrongly returning true, and thus to count wrongly returning > 1 even though .count correctly returns 0. -- 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: intersection and union on sequences/lists
Here is a bag implementation: (defprotocol SetOps (disjoin* [this obj]) (has* [this obj]) (total [this obj]) (counts [this])) (defn disjoin ([s] s) ([s obj] (disjoin* s obj)) ([s obj & more] (apply disjoin (disjoin s obj) more))) (defn difference ([s] s) ([s other] (apply disjoin s other)) ([s other & more] (apply difference (difference s other) more))) (defn intersection ([s] s) ([s other] (difference s (difference s other))) ([s other & more] (apply intersection (intersection s other) more))) (defn union ([s] s) ([s other] (if (empty? other) s (apply conj s other))) ([s other & more] (apply union (union s other) more))) (defn has? ([s] true) ([s obj] (has* s obj)) ([s obj & more] (and (has? s obj) (apply has? s more (extend-type clojure.lang.IPersistentSet SetOps (disjoin* [this obj] (disj this obj)) (has* [this obj] (contains? this obj)) (total [this obj] (if (contains? this obj) 1 0)) (counts [this] (zipmap this (repeat 1 (deftype Bag [m c] clojure.lang.IObj (withMeta [this, mtd] (Bag. (with-meta m mtd) c)) (meta [this] (meta m)) clojure.lang.IPersistentCollection (count [this] c) (empty [this] (Bag. {} 0)) (equiv [this other] (= (seq this) other)) (seq [this] (mapcat (fn [[k v]] (repeat v k)) m)) (cons [this obj] (Bag. (merge-with + m {obj 1}) (inc c))) SetOps (disjoin* [this obj] (if-let [n (m obj)] (if (= 1 n) (Bag. (dissoc m obj) (dec c)) (Bag. (assoc m obj (dec n)) (dec c))) this)) (has* [this obj] (contains? m obj)) (total [this obj] (m obj 0)) (counts [this] m) Object (toString [this] (apply str (interpose " " (seq this) (defn bag [& objects] (Bag. (frequencies objects) (count objects))) user=> (difference (bag 1 6 3 6 8 4 5 6 6 9 9) (bag 9 9 6 8 1)) # The difference, union, disjoin, intersection etc. functions are also made to work on Clojure sets, and via extend-type or extend-protocol can be extended to other types. (I didn't make Bag implement IPersistentSet because I considered nonduplication to be part of the latter's contract. So SetOps is a broader umbrella: unordered collection with efficient membership test.) The has? function is like contains?, but works on bags and sets rather than on sets and maps and may take more arguments, in which case it checks for all being contained. Note that (has? (bag 1) 1 1 1) will return true; to check for containing at least a certain number of occurrences use (not (empty? (difference bag-1 bag-2))) where bag-2 has the items we want to check for in the appropriate quantities. Well, except that count and empty are broken for some reason: user=> (.count (Bag. {} 0)) 0 user=> (count (Bag. {} 0)) 1 I don't understand what's causing this, but empty bags are always returning a count of 1 (and false from empty?) although the .count method correctly returns zero. I've traced the problem as far as the Java method clojure.lang.RT/count but no farther at this time. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: intersection and union on sequences/lists
On Mon, Mar 14, 2011 at 3:49 AM, Ken Wesson wrote: >> Well, except that count and empty are broken for some reason: >> >> user=> (.count (Bag. {} 0)) >> 0 >> user=> (count (Bag. {} 0)) >> 1 >> >> I don't understand what's causing this, but empty bags are always >> returning a count of 1 (and false from empty?) although the .count >> method correctly returns zero. I've traced the problem as far as the >> Java method clojure.lang.RT/count but no farther at this time. > > Argh. This same bug causes union to blow up in the case of (union (bag > 1) (bag)). It works with (union #{1} #{}), by contrast. It traces back > to empty? wrongly returning true, and thus to count wrongly returning > 1 even though .count correctly returns 0. Simply adding "clojure.lang.Counted", without any methods, to the protocol list makes it work again. The count function in RT is this odd little thing: public static int count(Object o){ if(o instanceof Counted) return ((Counted) o).count(); return countFrom(Util.ret1(o, o = null)); } If it's not counted, countFrom is called, and for some reason does not work on empty Bags even though it apparently works correctly on, among others, empty LazySeqs: user=> (instance? clojure.lang.Counted (map + '())) false user=> (count (map + '())) 0 Taking the countFrom expression apart, Util.ret1 just seems to return its first argument. I suppose it's being used to null o before countFrom does all of its work, to avoid holding onto the head of a lazy sequence that gets passed in. It's not the source of the problem. The cause seems to be this in countFrom: else if(o instanceof IPersistentCollection) { ISeq s = seq(o); o = null; int i = 0; for(; s != null; s = s.next()) { if(s instanceof Counted) return i + s.count(); i++; } return i; } If "o instanceof IPersistentCollection" then o has a .count method, yet this doesn't call it. Instead it calls seq, and if seq returns a non-null, empty seq that loop returns 1 instead of 0. So another fix that could be made to the original bag would be to call seq on the return value of mapcat. (Why mapcat is not returning nil for an empty input seq is itself somewhat mysterious.) I'm not sure whether the loop above should be considered correct (seq should never return a non-nil, empty seq) or incorrect (the corner case of seq's return being empty but not null should be handled). I'm not even sure whether that loop should exist at all, or should instead call the .count method of IPersistentCollection (with the default implementation being the loop above, of course). If the .count method of IPersistentCollection is not going to be used, on the other hand, unless the thing is also a Counted, then it should be removed from the former interface. Regardless, it looks like (count a-bag) is going to be inefficient despite the .count method implementation unless the Counted type is added to the protocol list, and seq should probably be returning nil for empty bags. So the version I'd suggest using is: (deftype Bag [m c] clojure.lang.IObj (withMeta [this, mtd] (Bag. (with-meta m mtd) c)) (meta [this] (meta m)) clojure.lang.IPersistentCollection (count [this] c) (empty [this] (Bag. {} 0)) (equiv [this other] (= (seq this) other)) (seq [this] (seq (mapcat (fn [[k v]] (repeat v k)) m))) (cons [this obj] (Bag. (merge-with + m {obj 1}) (inc c))) SetOps (disjoin* [this obj] (if-let [n (m obj)] (if (= 1 n) (Bag. (dissoc m obj) (dec c)) (Bag. (assoc m obj (dec n)) (dec c))) this)) (has* [this obj] (contains? m obj)) (total [this obj] (m obj 0)) (counts [this] m) clojure.lang.Counted Object (toString [this] (apply str (interpose " " (seq this) -- 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: intersection and union on sequences/lists
> Well, except that count and empty are broken for some reason: > > user=> (.count (Bag. {} 0)) > 0 > user=> (count (Bag. {} 0)) > 1 > > I don't understand what's causing this, but empty bags are always > returning a count of 1 (and false from empty?) although the .count > method correctly returns zero. I've traced the problem as far as the > Java method clojure.lang.RT/count but no farther at this time. Argh. This same bug causes union to blow up in the case of (union (bag 1) (bag)). It works with (union #{1} #{}), by contrast. It traces back to empty? wrongly returning true, and thus to count wrongly returning 1 even though .count correctly returns 0. -- 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: intersection and union on sequences/lists
clojure.lang.RT.count checks whether the object being counted implements Counted, and only calls .count on it if so. IPersistentCollection does not implement Counted, so it calls (seq) on your object and walks over it to get the count. You return (mapcat ...), when asked for a seq, which is fully lazy and thus non- nil even for an empty bag. You can fix the immediate problem by adjusting the seq function to return (seq (mapcat ...)): in my REPL this causes (count (bag)) to return 0 instead of 1. You could also make Bag derive Counted, so that your .count method will be called to save some time. On Mar 14, 12:49 am, Ken Wesson wrote: > > Well, except that count and empty are broken for some reason: > > > user=> (.count (Bag. {} 0)) > > 0 > > user=> (count (Bag. {} 0)) > > 1 > > > I don't understand what's causing this, but empty bags are always > > returning a count of 1 (and false from empty?) although the .count > > method correctly returns zero. I've traced the problem as far as the > > Java method clojure.lang.RT/count but no farther at this time. > > Argh. This same bug causes union to blow up in the case of (union (bag > 1) (bag)). It works with (union #{1} #{}), by contrast. It traces back > to empty? wrongly returning true, and thus to count wrongly returning > 1 even though .count correctly returns 0. -- 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: intersection and union on sequences/lists
You're right. Your version does what I want. Actually I've just seen that common lisps behaviour in the case of duplicates is undefined: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node152.html I was certain that it behaved the way your intersect behaves. -- 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: Clojure load-file command (+ Aquamacs, Bluefish)
Ken: There are a lot of things to like about Aquamacs, and its creator David Reitter deserves high praise as of course do the Emacs creators on whose shoulders he stands. The problem we have raised here is, for the present at least, the only complaint I have about Aquamacs. And there is probably a quick fix. When you have several separate Aquamacs frames (windows) open simultaneously, the current focus (that is, where your typing will go) is the frame where the cursor is blinking. There is probably a system variable whose setting determines obviousness of the cursor. I haven't found it yet but I haven't looked very hard. If for some reason I ever do want to change editors, I'm tempted to try Bluefish. It was recommended for Clojure editing by ramsa...@comcast.net on this mailing list just yesterday. --Larry On 3/13/11 3:23 PM, Ken Wesson wrote: On Sun, Mar 13, 2011 at 1:51 PM, Larry Travis wrote: Ken: Your question is an interesting one. My answer may serve as a word to the wise: I do my Clojure source-code editing in Emacs (actually Aquamacs, but the difference is not important for what I am saying here). As any Emacs user knows, when one has several Emacs frames (windows) in action and is hurriedly (and maybe also carelessly) moving back and forth among them, he sometimes starts typing for a change he wants to make in one frame when the point (cursor) is actually sitting in a frame different from the one in which he intends to be making the change. Usually, such a false start can quickly be caught and corrected, but I suspect that in this case I made such a false start and didn't fully correct for it. Your typing *should* be going to the cursor in the currently focused (generally frontmost) window. If that does not happen with Aquamacs, then your editor is tripping you up. :) (My own experience is with vi and various Windows editors. To have multiple vi windows one tends to make multiple term windows. As long as the terminal emulator handles focus appropriately vi can't cause problems like this. :)) -- 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