Re: bug in clojure.walk in 1.3
On Dec 13, 8:38 pm, Alan Malloy a...@malloys.org wrote: Issue is in bean, not walk. walk calls (empty foo) on its collection, in order to make sure you get back a collection of the same type. bean maps are, I guess, some special type rather than an ordinary c.l.PersistentHashMap; and that type doesn't implement the full IPersistentCollection contract (ie, there's no implementation of empty). I'm not so sure this is the right way to look at the issue. clojure.walk doesn't work on records, for example, also because of a missing implementation of empty, and for records it's definitely arguable that they shouldn't support empty anyway even though they *are* a logical target for walk. Joost. -- 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: running foo.clj no main?? install clojure
I run this line java -cp c:/opt/jars/clojure.jar:. clojure.main foo.clj On windows, the java classpath separator is ;, so that should be java -cp c:/opt/jars/clojure.jar;. clojure.main foo.clj I get it can't find clojure.main Doesn't really seem to matter here, but to eliminate misunderstandings, it's better to copy paste the exact error you get instead of paraphrasing / typing from memory. What is the best way to install clojure??? Many people use leiningen these days, which does all the download dependencies (including clojure itself) and set up the classpath stuff for you. See https://github.com/technomancy/leiningen -- 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: gaidica command??
On Nov 11, 5:29 am, jayvandal s...@ida.net wrote: I tried this command but can't find how to execute it. $ lein run -m gaidica.core What folder do I execute this ? (Vista windows ) Probably simple but it's difficult for me Thanks # gaidica Example Seesaw application. Display weather data from weatherunderground.com ## Usage $ lein deps $ lein run -m gaidica.core lein is the leiningen build tool. many clojure projects need it, since it reduces a lot of the overhead of finding and installing dependencies and setting up java options etc. you can get it at https://github.com/technomancy/leiningen after you've installed leiningen, you can run the above commands in the seesaw/examples/gaidica directory (which is in the seesaw source distribution - clone that from https://github.com/daveray/seesaw ) -- 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: Including java classes using lein
On Nov 8, 7:33 pm, megabite afo...@tibox.com.br wrote: I'm trying to use Math/sqrt using clojure 1.3.0 and lein but for some reason I can't get it to work. What do I need to put in the project.clj file and what needs to go into the (ns ...) statement in the core.clj file in order to get this work? It should be fairly straightforward but there don't seem to be any examples of this online. The only examples use [org.clojure/ clojure-contrib 1.2.0] which causes Maven to dump a bunch of errors. java.lang.Math and all standard java library classes do not need any lein configuration to work; they're always available when you run clojure on a standard java runtime. in addition, all the java.lang.* classes are directly addressable without using imports. Here's a session using clojure 1.3 with nothing in the project.clj dependencies except org.clojure/clojure-1.3: user (Math/sqrt 4) 2.0 If that doesn't work, please tell us what you're doing. ps: clojure-contrib 1.2 is not compatible with clojure 1.3 - don't try to mix them in your projects. -- 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-refactoring - what's the best way to distribute a clojure + emacs/elisp combined package?
On Nov 4, 4:07 pm, Chas Emerick cemer...@snowtide.com wrote: I've only looked at the code for ~5 minutes, but I think I might understand what's going on. To confirm: clojure-refactoring is sending something like diffs back to the refactoring-mode/SLIME, and that mode/emacs is what is actually performing the modifications to affected files? Basically, what's happening is that the emacs code sends snippets of code + some argument to the clojure backend, and gets a new snippet back replacing the old one. For instance, extract-fn gets called with a string representing the original function, another string representing the expression to extract and a function name, and it returns a string representing the extracted function + the original function with the expression replaced by a call to the new function. Similar things happen with the threading functions and rename. The emacs side of things pretty much consists of selecting, replacing and re-indenting expressions. On Nov 4, 4:30 pm, Laurent PETIT laurent.pe...@gmail.com wrote: Hello, As far as I remember, clojure-refactoring considered (or is using ?) using parsley + the clojure grammar in paredit.clj for some (all ?) of its refactorings. What is the current status of this ? (I also have a long delayed todo list note on adding refactoring to CCW, for sure ! :-) ) clojure-refactoring currently doesn't use paredit.clj at all, it still has its own parsley clojure grammar in clojure- refactoring.support.parser I haven't looked at paredit's grammar. it may be useful to use that, especially if we can have some common higher-level operations on parsed clojure trees (simple things like find the argument list for this function etc), but I just haven't had the time to look into it. Joost. -- 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-refactoring - what's the best way to distribute a clojure + emacs/elisp combined package?
I've implemented Phil's suggestion of using swank_elisp_payloads, and version 0.6.3 of clojure-refactoring is available right now as a leiningen plugin: lein plugin install joodie/clojure-refactoring 0.6.3 The clojure-refactoring Emacs functions will then be available under C- c C-f whenever you run clojure-jack-in to start a SLIME session. For more info, see the readme at https://github.com/joodie/clojure-refactoring Thanks! Joost. -- 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-refactoring - what's the best way to distribute a clojure + emacs/elisp combined package?
As some of you may know, I've recently taken over maintenance of the clojure-refactoring package for doing simple refactorings in Emacs/ SLIME with clojure-mode. This package consists of a bunch of clojure code that does the actual refactoring, plus an elisp file that handles the editor/ui side of things. I'm working on making the whole package more reliable and one of the obvious issues right now is that installation is a two-step process that may be intimidating to new users - especially those people who don't have a lot of experience customizing their Emacs setup. Ideally, what I would like to end up with is a single-step, no-fuss install process, but I'm unsure how to best get there. Leiningen/cake based installs are good, provide the clojure dependencies and generally work fine, so I'm going with clojars right now, but users still need to extract/download the elisp code separately and keep it in sync with the clojure code. Which is annoying and intimidating to people new to Emacs. Marmalade packages for elisp also work fine but as far as I can see, you can't easily include clojure jars with marmalade packages and also make them work out of the box with SLIME. The most straight-forward solution I can think of right now is to split the package in half; put the elisp code on marmalade and provide a clojars jar for use as a leiningen plugin/project dependency, but if anyone can think of a reasonable way of making things simpler than that for the end-users, I would appreciate any suggestions. I think it would make a lot of probably already overwhelmed new Emacs / Clojure users feel a little less intimidated. :) Please let me know what you think is a good idea. Thanks in advance, Joost Diepenmaat. References: clojure-refactoring page: https://github.com/joodie/clojure-refactoring Clojars pom/lein info: http://clojars.org/joodie/clojure-refactoring -- 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-refactoring - what's the best way to distribute a clojure + emacs/elisp combined package?
On Nov 3, 10:37 pm, Phil Hagelberg p...@hagelb.org wrote: Swank Clojure 1.3.3 actually supports piggybacking elisp inside jar files. Create a file called swank_elisp_payloads.clj in the root of your jar file that contains a vector of paths to elisp files contained in the jar. I hope to have this documented soon, but I believe it's pretty much exactly what you are looking for. Please let me know if you have any trouble with it. That sounds great. I will look into that and see what I can do with it. Thanks, Joost. -- 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-refactoring - what's the best way to distribute a clojure + emacs/elisp combined package?
On Nov 3, 10:52 pm, Chas Emerick cemer...@snowtide.com wrote: Joost, This looks great. I think I might have been vaguely aware of clojure-refactoring before, but I'm glad to have been reminded of it. Q: how much of it is Emacs/SLIME specific? I ask because I'd love to see the advertised functionality rolled into Counterclockwise (and any other Clojure tooling out there). Such common tooling libraries were contemplated here, FWIW: http://dev.clojure.org/display/design/IDE+tooling+backend …though there's no refactoring section there (yet, *hint* ;-) I was sort of expecting this question :) Much of the code is actually editor-agnostic; the real refactoring code is all pure clojure and implements its own parser/generator. The main API requires an interface that can recognize clojure expressions/ def forms and pass them as strings. The actual communication with the editor is done over the SLIME protocol, but aside from the global rename refactoring, which needs to touch files all over a project, it doesn't seem to be too complex (mostly because it's sending the code as strings instead of trying to be clever with s-expressions). As far as I can see, it's definitely possible to split out the editor- agnostic parts of the code into its own package, and I expect that would be useful for more than just refactoring tools too; automated code formatting would be another possible use for one. I'd be willing to put some work into making the code more accessible to other editors/programs, but I'm not personally motivated to develop and maintain any bindings for editors other than Emacs right now. I don't have the time to learn how to use them or to test any issues that may turn up on those systems. In other words; somebody else has to be willing to take up the work of binding the basic refactoring code to their editor of choice (and maintain the bindings!) but if someone is willing to do that, I'm willing to make their usage of the clojure-refactoring code as painless as reasonable. Joost. By the way; any patches on the refactoring code are welcome; it's not perfect, yet. - *hint* ;-) -- 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: including sound or image files with Leiningen uberjar command
On Sep 16, 7:20 am, loonster tbur...@acm.org wrote: Sound or image files will show up in the resulting uberjar if they reside in a /resources subdirectory of a Leiningen home project directory. I can't find any documentation for how to refer to and load such resource files within a project.clj and/or a source clj file so that that the resources can be used by a standalone jar. Many thanks for any hints. Tim You can refer to resources using (clojure.java.io/input-stream (clojure.java.io/resource path/to/ image)) See also ring.util.response/resource-response if you want to do this in a war/jar web app. Joost. -- 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: Ring+Swank
On Jul 12, 7:27 am, Tarantoga d.bushe...@gmail.com wrote: Hi all, I'd like to make a web-app to which I could connect using slime and make some changes there while the application is still running. How to start Swank-server from the working Ring-application? The simplest way during development is to start swank (using leiningen) first, and then load start the web server from the REPL. This ensures swank will start even if your code has a compilation error somewhere. Doing it the other way around isn't difficult either: (require 'swank.swank) (swank.swank/start-repl 4005) ; that's the standard swank port number -- 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: Question on eliminating recur
On Jul 10, 7:15 am, Michael Gardner gardne...@gmail.com wrote: I think Christian wanted to know *why* one should eliminate recur. I can't think of a reason to avoid it myself, though I also don't recall hearing any recommendations against using recur. Just my two cents, but the main reason to consider map/doseq/reduce/ filter etc in favor of loop/recur is that if your algorithm matches one of the former, you'll need a little less boiler-plate code (sometimes), makes it easier to use/create lazy sequences and (most importantly) using map/doseq etc when appropriate conveys a lot of information about the structure of the algorithm and its input/output expectations to the human reader. -- 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: call to idiomatic loop works as stand alone but not when wrapped in my function
(defn read-files-into-memory [ filenames ] (print filenames) (map #(read-json-filename %1) filenames)) The [ filenames] argument spec turns all the arguments given into a sequence. You're not passing the filenames as separate arguments, but as a vector, so you either have to change that: (read-files-into-memory name1 name2 ..) or you need to use apply: (apply read-files-into-memory fnames) -- 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: Announcement: pretzel - a predicate library + call for suggestions
All this stuff on complexity of validations is interesting, but my take on most of this (and especially on the pretzel functions) is that predicates should just test for validity, strictly if possible, and nothing else, since there are too many ways of combining these tests into more abstract functions for anyone to agree on and trying to do force these choices in the predicates themselves would make them less useful and more confusing. An input string of foobar is obviously not a number between 10 and 20, so whatever predicate you use to test for that should just return false. That not everybody here agrees on that indicates to me that people are trying to shove too much functionality into single tests/ predicates. I want simple, correct, well tested predicates that people can use. I'm trying NOT to make design decisions that can be made by the user of the library instead. IOW, how you combine tests should not be up to the code in this level of abstraction; it should be in the validation framework(s) that can be build on top of them. I've made my tentative choices about *that* in clj-decline, and if those don't turn out to be flexible enough for me I'll change them. If they turn out to be too cumbersome, I'll probably write some higher level abstractions on top of them. YMMV. Cheers, Joost. -- 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: Announcement: pretzel - a predicate library + call for suggestions
James Reeves wrote: On 7 April 2011 20:03, Joost jo...@zeekat.nl wrote: Yup. I'm mostly in the same boat. That's why all the predicates I've produced for now are in the pretzel.strings namespace. I expect to end up with few non-string predicates, but those will have to go into pretzel.numbers or whatever make sense. What about predicates that operate on numbers encoded as strings? e.g. 1 or 4.2. IMO, they should be in the strings package. For your specific example of (integer-string? foo), that should just return false. The idea - for strings - is that any kind of input string can be supplied, and the function should just test whether it conforms to some kind of formatting. The same logic should, I think, apply to functions operating on numbers and other types such as files, if there's a need for those kinds of predicates. I think we differ a little in our end goals, then. I'm less concerned about general use, and more concerned about generating good error messages for form-data validation. For instance, with normal predicates, one might get error messages like: {:score [is not present is not an integer is not between 1 and 10]} But in my view, it would be better to have a error message like: {:score [is not present]} Because if a value is blank, there's no point in telling the user it's also not an integer or between a certain range. Also, one might have integer fields that can be blank. Sure, but that's part of the validation mechanism that uses the predicates; the predicates all return just true or false. The messages associated with that aren't (and IMO, shouldn't) be part of the predicates. Basically the problem is one of combining validations (the functions that generate feedback); some validations can be parallel, that is, each validation should be run and the messages they return should be compounded, but others are dependent on each other, in your example, the test for integer-formatting should only be run if the test for existence doesn't return an error message. In clj-decline you can specify this by using the valiations function to combine parallel validations and validate-some to specify dependent validations. A simple example from https://github.com/joodie/flutter-decline-demo/blob/master/src/flutter_decline_demo/validations.clj (defn required [param] (validate-val param seq {param [this is a required field]})) (def validate-entry (validations (required :name) (validate-some (required :email) (validate-val :email str/looks-like-email? {:email [must contain an @ sign, and a dot in the domain name]})) (validate-some (required :phone) (validate-val :phone str/looks-like-phone? {:phone [this doesn't look like a phone number.]})) (required :address))) There's a related question on how to merge predicates (instead of validations) which is what the pretzel.combine namespace is for, but that's on a lower level since it really just merges predicates into new ones without doing anything with messages. So I think Valip needs its own predicate library, but I can probably factor out a lot of the general stuff to Pretzel (e.g. email-address? integer? etc.) I'm not so sure you actually need to have another level of predicates to do what you want, but of course, if it's possible to merge the useful predicates from valip into pretzel, I'd be happy with that :) Joost. -- 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: Announcement: pretzel - a predicate library + call for suggestions
On Apr 7, 1:47 am, James Reeves jree...@weavejester.com wrote: I've been writing a small validation library, Valip, with a number of included predicates. The predicates in Valip are curried if they have more than one argument, but there is probably some overlap between Valip and Pretzel, and it might be an idea to farm out some more generic functionality to Pretzel. I think your choice of currying makes more sense, at least in the context of validations, so it might be a good idea to switch pretzel over to that scheme. https://github.com/weavejester/valip/blob/master/src/valip/predicates... Also, it looks like your ^String type hint is in the wrong place for your length? predicate. Oh, you're right. I really should work on extending the tests... If you want, I can take a stab at unifying the code for this. Cheers, Joost. -- 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: Announcement: pretzel - a predicate library + call for suggestions
James Reeves wrote: On 7 April 2011 06:48, Joost jo...@zeekat.nl wrote: I think your choice of currying makes more sense, at least in the context of validations, so it might be a good idea to switch pretzel over to that scheme. Would it make sense for clj-decline? Yes. The main idea of clj-decline is to get rid of unesessary restrictions on predicates and validation errors, but curried predicates to me fit in slightly better than in-line functions. valip looks pretty similar in design with regards to the predicates. The Valip predicates are designed with HTML form validation in mind, so they have a couple of unusual properties: 1. Valip predicates expect to test strings, e.g. ((between 1 10) 5) = true ((between 1 10) 0) = false Yup. I'm mostly in the same boat. That's why all the predicates I've produced for now are in the pretzel.strings namespace. I expect to end up with few non-string predicates, but those will have to go into pretzel.numbers or whatever make sense. 2. I'm considering adding an extra :pass return value, to denote the case when the input string cannot be tested by the predicate. For instance: ((between 1 10) foo) = :pass (integer-string? foo) = false This is to ensure I don't get exceptions for predicates when the input is incorrect: (defn validate-rating [rating] (validate rating [:score present? should be present] [:score digits? should be a number] [:score (between 1 5) should be between 1 and 5])) (validate-rating {:score }) = {:score [should be present]} (validate-rating {:score foo}) = {:score [should be a number]} (validate-rating {:score 15}) = {:score [should be between 1 and 5]} So the predicates I'm writing for Valip are somewhat customised for validating string data, and are not generic predicate functions. Is Pretzel designed for general-use predicates, or for predicates designed for form validation? As I alluded to above, the predicates in pretzel.string expect a string as an argument. As long as that requirement is met, they shouldn't throw exceptions or return any special value. I see that as general use for these kinds of functions. Either the argument is valid or it is not. Any handling above that cannot be up to the predicate, and this is one of the reasons I added the pretzel.combine functions ~ though I'm not sure that the functions in that namespace are named well. For your specific example of (integer-string? foo), that should just return false. The idea - for strings - is that any kind of input string can be supplied, and the function should just test whether it conforms to some kind of formatting. The same logic should, I think, apply to functions operating on numbers and other types such as files, if there's a need for those kinds of predicates. Cheers, Joost. -- 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: Redirection from inferior lisp to clojure
On Apr 6, 10:33 am, MohanR radhakrishnan.mo...@gmail.com wrote: Hi, I use clojure box and I have included (add-hook 'slime-mode-hook 'slime-redirect-inferior-output) in .emacs I open M-x run-lisp and I still see the exception trace in inferior- lisp I though it will be redirected to the slime repl. Will it be ? AFAIK run-lisp is not supposed to work with SLIME. If you want everything to work on slime, you should start a swank server and then use M-x slime-connect or run M-x swank-clojure-project -- 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: Redirection from inferior lisp to clojure
MohanR wrote: swank server is started and run-lisp works. I thought I don't need to open it but view all the output in slime itself but it gets redirected internally. But as far as I can tell, run-lisp does NOT connect to a swank server, and AFAIK also doesn't set up SLIME. run-lisp starts the inferior-lisp interaction model, which is much more minimal than SLIME. If you've already got a swank server running, the correct function to connect to it is slime-connect. Joost. -- 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
Announcement: pretzel - a predicate library + call for suggestions
Hi, I've collected a bunch of predicate functions and bundled them up as pretzel: https://github.com/joodie/pretzel My main focus right now is towards string formatting predicates; tests for decimals, hex, email, urls, etc. Plus I've added some functions that combine predicates into new ones. The idea is to have a simple collection of these kinds of functions outside of possibly unwanted frameworks. I'm using them myself for doing validation with clj-decline, but it should at least be useful for most code that has to deal with free-form text input. So: 1) Now you know this library is out there, and you don't necessarily need to rewrite stuff from scratch. 2) I probably left out a lot of useful predicates, and I would like to include more, so if you have an itch that needs to be scratched, please suggest additions. Preferably as a pull request :) 3) I'm not sure right now how useful the predicate-combination functions are, or if they should be part of the same distribution as the string predicates. If you feel strongly one way or the other, please let me know. Cheers, Joost Diepenmaat Zeekat Softwareontwikkeling. -- 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: Shaping my game API
Pepijn de Vos wrote: Hey, Hi, Just a couple of remarks: I'm writing some Clojure game stuff, and I'm having trouble coming up with a sensible model for the game objects. The basic idea is that I have a bunch of objects that represent the game, and call 'act' on them, supplying the current world to get their next state. That doesn't sound too unreasonable as a starting point. The objects have a few properties, like an ID, a position, a sprite and any extra information an object might need. I also want to make it implement java.awt.Shape for collision detection using an internal Rectangle. This sounds like you're trying to cram too much stuff into a single object. For example, java.awt.Rectangle already has an intersects() method, so: 1. you don't need to implement Shape just to do rectangle collision. 2. you also don't need to implement Rectangle, as long as your objects can provide a rectangle in some way. To write a game, one must define new types of objects, and implement their 'act' function. My initial thought was to use a record and an actor protocol. The first problem with this is that the properties of the record are not embedded in the actor protocol, so there might be actors that blow up rendering by having no sprite for example. Another problem is that subclasses would need to implement Shape themselves. See point 2 above. If you don't require implementing all the stuff in the same object, the problem goes away. Yet another one is that updating the position of a record via assoc does not update the Rectangle. Again, fixed by having the object provide the Rectangle (via a multimethod, or protocol method or something similar). Then I considered using a multimethod on type, which can use the :type metadata. This leads to a model where no subclasses of the game object are made, but merely given a different type on their meta. Sounds reasonable to me. To integrate the Rectangle with the object, I considered using a type instead, and use classic getters and setters. This has the advantage that I can manage the Rectangle and that the properties of the object are embedded in the protocol. Problem #1 here is that I lose the ability to store arbitrary data on the object. This can be circumvented by using the extension model. But having now defined even more methods, I place an even larger implementation burden on the child type. What would be a clean way to do this? Split up the stuff that doesn't NEED to be in the same object. This is a typical pitfall in OO design; when you can implement functionality with aggregation, you probably should use aggregation instead of inheritance. For instance: in your initial outline for the actor protocol, you basically say that all it does is change the current game state to a new state. That sounds good. But that also means that actors don't inherently have to have sprites, or shapes, or even collision detection. That's all external to the core idea. I can also easily imagine game objects that don't necessarily need to change game state, but where you do still need to have shapes and collision detection - like walls. So to me it sounds like you're talking about two different concepts that are probably complicating your design when you force them to together. Hope that helped, Joost. -- 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: Is there a way to make a symbol throw an exception, when it's referenced?
On Apr 2, 10:30 pm, icemaze icem...@gmail.com wrote: I'm writing a macro that defines a symbol through let, but I also needs to unbind (unlet?) it, so that further uses of that symbol throw an exception. I hoped I could use symbol-macrolet, but local symbols are protected from expansion Thanks! Is there any reason you can't expand to something like: (do (let [my-symbol ...] ;; use my-symbol) ;; do something with my-symbol out-of-scope) where you also can't use gen-syms to prevent accidental re-use? From where I'm standing, if the answer to that question truly is yes, my gut reaction is that the real problem is not in your inability to find a solution to the question you are posing. -- 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: Announcement: flutter - hiccup-based form field generation
I just pushed release 0.0.2, which has many improvements and a bit more documentation on the API. If you're interested, please take a look and let me know if you have any questions or remarks. Cheers, Joost Diepenmaat. -- 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: Announcement: flutter - hiccup-based form field generation
On Mar 28, 11:18 am, Saul Hazledine shaz...@gmail.com wrote: On Mar 27, 12:04 am, Joost jo...@zeekat.nl wrote: I'm currently working on a library to provide a consistent and extensible method for generating form fields, based on hiccup. I think this is a cool thing to do. One thought I had was that your approach looks very general - could it be used for all types of HTML generation or is it limited to form fields? It makes a few assumptions; mostly, it assumes that fields always have a name and a value (though value may be nil). It's certainly possible to create your own field types, but if they don't take values or names, it's probably less useful (and I would imagine in those cases it's easier to write your own functions to generate hiccup code directly). The code is at github:https://github.com/joodie/flutter The README should give you a decent indication of what I'm aiming for. In any case, this library will NOT provide validation routines (though it should integrate nicely with clj-decline or whatever you might prefer). I'm keeping my sights on the do one thing, but do it right goal. I think this is a good direction to go in. I'm really interested in how things will turn out. Thanks, me too :) One thing to look out for (it may not even be an important problem but it has bugged me) is how attributes such as max-length end up as validation and html. Looking at things from an MVC perspective max- length is an attribute of the model that ends up used by the controller for validation and also in the view html. I feel it would be good if there was a painless way of using such attributes across multiple libraries such as clj-decline and flutter. If people start using HTML5 form validation, this problem multiplies. Maybe. Right now it wouldn't be much of an issue to pass constraints to specific fields using a similar style to wrap-labels or wrap-params in flutter. How best to integrate that with server-side validations might be more of a puzzle, though the above way would already mean you can specify the constraints directly from the controller instead of hidden away in a view somewhere. Aside: I've noticed that mapping directly from a model to validation form data quickly leads to inelegant hacks (and possible security issues). I'm still working on the tests, but in any case, the tests are the right spot to look at right now to see some examples. Some more convenience functions should be coming soon. For now, I've been mostly trying to get a consistent internal API. I think the API is the most innovative thing about what you are doing - the functionality is already there, entangled, in most web applications. I feel you would get more early feedback on your approach if you documented the API. Personally, I struggle to get an overview of a library from the unittests. I understand that. I've been holding off a bit on documenting the API until I've tested it a bit more and feel fairly sure that it's flexible enough and that there aren't going to be a lot of big changes. Right now, I'm feeling fairly confident, so that probably won't take too long, provided the Lisp symposium and work don't take up all my time. :) Cheers, Joost. -- 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
Announcement: flutter - hiccup-based form field generation
I'm currently working on a library to provide a consistent and extensible method for generating form fields, based on hiccup. The code is at github: https://github.com/joodie/flutter The README should give you a decent indication of what I'm aiming for. In any case, this library will NOT provide validation routines (though it should integrate nicely with clj-decline or whatever you might prefer). I'm keeping my sights on the do one thing, but do it right goal. I'm still working on the tests, but in any case, the tests are the right spot to look at right now to see some examples. Some more convenience functions should be coming soon. For now, I've been mostly trying to get a consistent internal API. Check it out if you want. Let me know if the API prevents you from doing stuff; preferably using pull requests ~ assume that I'm lazy and you'll have a good chance that I'll accept your suggestions :-) Cheers, Joost Diepenmaat Zeekat Softwareontwikkeling. http://joost.zeekat.nl -- 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: Noob Question - Clojure number rounding
On Mar 23, 8:07 pm, Meikel Brandmeyer m...@kotka.de wrote: Hi, a bit naive, but it seems to work… user= (defn round [x {p :precision}] (if p (let [scale (Math/pow 10 p)] (- x (* scale) Math/round (/ scale))) (Math/round x))) #'user/round user= (round 78.37898794) 78 user= (round 78.37898794 :precision 3) 78.379 There are probably thousand reasons not to do that… Most important one being that it won't be reliable. Floats are fundamentally not compatible with decimal rounding. You'll have to switch to some other representation like (big) decimals, fixed point or strings to get 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: overriding keyword behavior?
On Mar 10, 5:31 pm, kurtharriger kurtharri...@gmail.com wrote: That was basically my question, protocols are designed for this but ILookup isn't a protocol. Is it possible to make ILookup into a protocol? I haven't looked at the java code much at all, but I might take a stab at creating a patch it that seems possible. Converting java.util.Properties into a map isn't hard, but converting java objects to native maps is extreamly common (bean, reflect, ring, etc...) and perhaps unnecessary in many situations if one could just extend an existing java type with ILookup so that if it looks like a duck, its a duck. I've had the same idea a couple of day ago; specifically, looking up public members of an object. In the end, I think the actual use cases generally are more involved than just :keyword lookup, so I wrote some code to automatically do the conversion to map: https://github.com/joodie/clj-java-fields -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Newbie: General question about concurrency in Clojure
On Mar 9, 9:26 am, Nick Wiedenbrueck nick.wiedenbru...@googlemail.com wrote: I'm still getting started with Clojure and I'm wondering about how one should generally go about concurrency and how transparent concurrency is in Clojure. So, to me there would be two approaches: A) Be aware of the parts of your system that will be concurrent and only within these parts write concurrent code using reference types and so on. Basically, yes. But note that any code that doesn't use atoms, refs and other mutable stuff is concurrent by itself. The ref types are the ones that require some thought. As a rough rule of thumb, this means you want to keep the number of reference objects down. My question here would be, how much a developer has to scratch his head about concurrency. Agreed, it's much easier than using locks like in Java, but still I have to think about what should be a ref, what should be an agent and how to set up transactions. You always have this problem. But really, if you're new to clojure, you don't need refs nearly as much as you probably think right now. B) Write concurrent code where you can, even the (smallest) parts of your system which aren't necissarily inherently concurrent. The question here is, if handling concurrency in Clojure is simple enough to go about it this way, or if it would be much less effort to write non-concurrent code. So, in general I think the question is, how transparent concurrency is in Clojure. The ultimate goal would be to just write code, that is concurrent, but to not have to think to much about it. Again, anything that doesn't use mutable objects is automatically concurrent. But I think you're conflating concurrency and parallelism. Joost. -- 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: unchecked-divide etc being replaced in 1.3 - no more support for longs?
On Mar 2, 2:05 am, Jason Wolfe ja...@w01fe.com wrote: But I don't know what the plan is if you really do want truncating arithmetic on longs. On 1.3 alpha 4: user= (+ Long/MAX_VALUE Long/MAX_VALUE) ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1581) user= (set! *unchecked-math* true) true user= (+ Long/MAX_VALUE Long/MAX_VALUE) -2 Looks good, only it doesn't seem to work for division: (set! *warn-on-reflection* true) (set! *unchecked-math* true) (/ 1 2) Reflection warning, NO_SOURCE_FILE:1 - call to divide can't be resolved. 1/2 What I want in this particular program is a truncating, unchecked division on longs, but there doesn't seem to be any way of getting that using these constructs. Even for ints you need to explicitly call unchecked-divide-int: (/ (int 1) (int 2)) Reflection warning, NO_SOURCE_FILE:1 - call to divide can't be resolved. 1/2 (unchecked-divide-int (int 1) (int 2)) 0 I'm guessing the problem here is that compared to the other unchecked* functions, unchecked-divide-int does two additional things: it gets rid of the fractional results and it truncates the result to int. I can't find any way to do that with longs. ps: I realize that in these examples, I could use a bit-shift. -- 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 on JS VMs
On Mar 3, 3:56 pm, Timothy Baldridge tbaldri...@gmail.com wrote: I know we have Scriptjure. But has there been any concentrated effort to port Clojure to JS? This may sound odd, but personally I would love to use Clojure in the browser. Scriptjure would work fairly well, but from what I see, it doesn't support persistent maps and instead relies on JS objects. Not as far as I know. Scripture is extremely limited; it's only a lisp- like wrapper on basic javascript that just happens to have names like clojure's. For instance, there's not even real (if ), (let ..), no automatic returns etc. Its possible to do a real port of clojure that sort of does the basics right, but that would be a lot more involved than just translating source code. Joost. -- 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
unchecked-divide etc being replaced in 1.3 - no more support for longs?
Hi, I just noticed that in 1.3 alpha 4, unchecked-divide (which seemed to support longs as well as ints) has been replaced by unchecked-divide- int. But there's no unchecked-divide-long, as far as I can see. This also seems to apply to the other unchecked-* math functions. Given that one of the main themes of 1.3 seems to be speed/efficiency, I'm sort of surprised by this but I might have missed something. What's the plan for fast math on longs (and floats)? Cheers, Joost. -- 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: Transforming map entries
On Feb 22, 4:08 am, yair yair@gmail.com wrote: I'm hoping this is a dumb question and I've missed something obvious. I have a map with various key-value pairs and I want to transform some of the values, e.g. (def mymap {:first john :last smith :age 25}) and say I want to change the strings to be upper case. Right now all I can think of doing is using reduce and passing in an empty map and the re-associating each key with the (possibly) transformed value. Is there something like the map function that takes two parameters, one a function that receives a pair and returns a new pair, and the other a map, and returns a map that's reconstituted from those pairs? since hash-maps aren't lazy, what's wrong with using hash-map? (apply hash-map (mapcat (fn [[k v]] [(.toUpperCase k) v]) {bla 1 bloop 2}) ) = {BLOOP 2, BLA 1} or: -- 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: First N unique random floats from a lazy seq
On Feb 19, 12:38 am, Alan a...@malloys.org wrote: user= (take 100 (distinct (repeatedly #(rand-int 200 Nitpick: the distinct call may be useful in some circumstances, but if you want a truly random sequence, you definitely do not want it there. Joost. -- 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: Realtime Clojure program
On Feb 14, 4:32 pm, cej38 junkerme...@gmail.com wrote: Laziness is great when there are things that may not ever be needed. But it slows things down when you know that you are going to need some function applied to every element of some col. The doall function is your friend in this case. AFAIK, most if not all of the lazy constructs in clojure have a penalty attached that is only applied the first time you realize the sequence. Executing a doall on a lazy seq does not reduce the penalty (and probably makes the overall running time slightly longer). But there might be exceptions to that, that I don't know about. For speedy and clever algorithms, not using lazy constructs at all and modifying stuff in-place is probably the way to go, though I would certainly advice against doing that before there is a working clean solution that's been tested to show where the actual slow stuff resides. Profiling is generally much better than intuition. J. -- 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 and functional languages advantages over .NET
On Feb 9, 6:48 pm, Bojan Jovicic bojan.jovi...@gmail.com wrote: Dear all, what are in your opinion 3 biggest advantages that Clojure and functional languages have over .NET, with focus on LINQ? .NET is not a language, it's a runtime with explicit multi-language support. There's even a clojure implementation that runs on .NET. There's also F#, which is Microsoft's functional language for .NET. The JVM and .NET runtimes both support loads of languages. There are several other multi-language runtimes in the works at the moment. AFAICS serious hosted languages are all moving towards a split between langugage and runtime. Comparing languages to runtimes is not very useful at this point in time and the question will probably become even more pointless in the future. Never heard of LINQ until you mentioned it, but it appears to be a general data querying library. That sort of thing is generally implemented as on top of a language/runtime. Clojure/Java doesn't currently have something like that as far as I know, (unless you count JDBC and the Clojure-specific layers on top of it like the interesting ClojureQL), though I may be wrong - there is a stupendous amount of Java libraries and frameworks out there and most work with Clojure if need be. E.g. I thought of set functions, but this is supported in LINQ. Clojure has sets and related functions in the core language, ClojureQL implements sets in a way that might be closer to what you're thinking about. -- 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 and functional languages advantages over .NET
Please note that I don't want to start a big argument either. On Feb 10, 11:01 pm, Timothy Baldridge tbaldri...@gmail.com wrote: The LISP syntax can be viewed as a bad thing. I for one struggle with it from time to time. I personally haven't decided if I think the LISP syntax is a pro or a con. I think this is fair. Lisp languages work for me, mostly because they make stuff that seems special in other languages much more explicit and hackable. YMMV. And the dynamicness of Clojure can be considered a bad thing performance-wise. Many benchmarks will show Clojure trailing a bit behind C# in pure number crunching performance. Dynamic languages make *development* fast. At least compared to Java/C style static languages. Even if you're working on a program where performance really matters, the big gains are very probably only to be found in about 20% of the code base (and I think I'm being very generous here). For the other 80% dynamic vs static typing is a non- issue. But in a static language, you're still paying the extra development time for that 80% of code where it doesn't matter. Again, YMMV, IMHO, bla bla bla Joost. -- 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: Sorting of function definitions in namespaces
On Feb 10, 4:27 pm, jkrueger jan.krue...@gmail.com wrote: Sure. I'm not saying that you can't write it yourself. My point was, that a) This is essential to writing understandable code, so it would be nice if the language supported it out of the box I don't agree it's essential. I think if you use namespaces, you can easily structure code in a way that's top down: (ns high-level (:use lower-level)) (defn high [a b] (low1 a (low2 b))) The order within a file is not that important, because a single file shouldn't contain enough code to be confusing. b) A namespace feels to me like a set of functions (ns-publics actually returns a map). That Clojure enforces a particular ordering (if we forget about the declare kludge) while writing a namespace seems arbitrary from a programmers point of view. Yes it's arbitrary, but the other way around would be arbitrary too, and IME 1) it's fairly rare that you actually *need* a declare kludge. 2) full free ordering generally makes stuff harder to find than enforced order. In conclusion, I see the current behavior as slightly more a feature than an issue. Joost. -- 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: Sorting of function definitions in namespaces
On Feb 11, 12:02 am, Joost jo...@zeekat.nl wrote: Yes it's arbitrary, but the other way around would be arbitrary too, and IME 1) it's fairly rare that you actually *need* a declare kludge. 2) full free ordering generally makes stuff harder to find than enforced order. I forgot to add that I've used Perl a lot, which does *try* to do free- style ordering, and it ended up with a system that works most of the time, but is really not easy to figure out when it doesn't work, and even adding declare style statements don't always work like you want to. I really prefer an enforced order with *reliable* declarations. -- 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 lambda funcs and bindings
Andreas Kostler wrote: Hi all, Suppose I have the following function: (defn foo [x changeling] (cond (= (first x) 'bar) (map #(foo % changeling) (rest x (def foobar (atom {:something in-here})) Now, changeling gets bound to (atom {:something in-here}). Erm.. no? where? The conditional in foo might contain another case that actually changes changeling. As a matter of style and readability: don't do that. Have (foo whatever) return a new value for whatever, then use (swap! foobar foo) or something similar. How can I avoid the binding of changeling to the initial value of the atom and have the anonymous function passed to map use the current (possibly changed) value of changeling? You might not want to do this in any function passed to map, since map is lazy. -- 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: probable bug in transients ..
That is not a bug. You should NEVER use transient and its related functions to emulate variables - you're supposed to use assoc! and friends as if they're pure functions. That is, always use the return value of assoc! and don't rely on its argument being modified. something like: (loop [x (transient {}) i 0] (if ( i 10) (recur (assoc! x i (* i i)) (inc i)) (persistent! x))) -- 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: probable bug in transients ..
Joost wrote: you're supposed to use assoc! and friends as if they're pure functions. Just correcting myself for clarity: assoc! etc MAY modify their transient arguments, but not always, and not always in the way you might think. The correct result of these operations is their return value, but they are not pure functions since you also - obviously - cannot rely on the transient arguments to remain unchanged. -- 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: swank-clojure-1.1.0.jar
Christian Guimaraes wrote: Hello all, Where can I download swank-clojure-1.1.0.jar? My attempts to compile (using lein jar) are failing. I think is due to the repositories location. Or, better, how can I fix the repositories in the swank-clojure code. Thanks. -- christian guimaraes Don't think swank-clojure 1.1.0 was available as a lein dependency, since back then it was mixed in with emacs lisp stuff. Any reason you're not using 1.2.1 or the latest snapshot? If you really need a 1.1.0 jar, you should be able to build it from http://github.com/technomancy/swank-clojure/tree/1.1.0 Joost. -- 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: swank-clojure-1.1.0.jar
Christian Guimaraes wrote: Hi, the problem is the (concat http://repo.technomancy.us/; swank-clojure-1.1.0.jar) in the swank-clojure.el this repo no longer exists. -- christian That's because swank-clojure.el no longer exists and is no longer supported. swank-clojure now works out of the box with recent-ish versions of slime. If you must, you'll have build and install 1.1.0 yourself. But I seriously suggest you upgrade to the latest stable release (using leiningen or maven) as documented on http://github.com/technomancy/swank-clojure Also note that there is a separate swank-clojure group at http://groups.google.com/group/swank-clojure -- 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: misunderstanding collection
On Aug 25, 4:06 pm, Glen Rubin rubing...@gmail.com wrote: After toying around at the REPL I realize that I have been working with a heretofore invalid understanding of collections. For example, working with the following collection(s): signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8))) I wanted to sum each individual list: e.g. (1 2 3 4) = (10) (map #(map reduce + %) signal) + is not a collection, it's a function. You need nested currying in some way. ... So, clojure sees 'signal' as 2 collections, whereas I thought it was a single collection. This makes me concerned that I have been doing everything wrong thus far and getting computational errors. :( So, how should I sum each individual list in the above collections? signal is not 2 collections. It's a list containing two lists each of which contains 3 lists. As far as I can see, you're either expecting ((1 2 3 4) (2 3 4 5) (3 4 5 6) (3 4 5 6) (4 5 6 7) (5 6 7 8)) In which case user (map #(reduce + %) signal) (10 14 18 18 22 26) works, or you want to really use (def signal '(((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8 In which case (since you can't use nested #( .. ) forms, something like this will work: user (map #(map (fn [c] (reduce + c)) %) signal) ((10 14 18) (18 22 26)) Which is probably clearer like this: (defn sum [c] (map #(reduce + %) c)) (map sum signal) = ((10 14 18) (18 22 26)) Hope this helps, Joost. -- 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: why data structure
Belun wrote: why does everything have to be a data structure ? like (operation parameter parameter ...) I assume you can see why parameters are data structures (or just plain data, if you want speed). Operations - or function calls - are data structures because it makes sense. Especially in Lisp, because you want as little abstraction between the language implementation and the source code as possible in a Lisp. And you want that because it makes writing the language in itself easier. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Newbie style question - implementing binary search
Dave Snowdon wrote: ; helper function that splits a collection into halves (defn halve [coll] (let [len (count coll), hl (- len (/ len 2))] [(take hl coll) (drop hl coll)] ) ) ; takes a value and an ordered sequence and returns the index of the value or -1 (defn chop [val coll] (letfn [(chop2 [ofst val coll] (cond (empty? coll) -1 (= 1 (count coll)) (if (= val (first coll)) ofst -1) :else (let [[fh sh] (halve coll), sel (first sh)] (cond (= val sel) (+ ofst (count fh)) ( val sel) (recur ofst val fh) :else (recur (+ ofst (count fh)) val sh)] (chop2 0 val coll))) I think the main thing that's confusing here is that you're messing with offsets and split collections at once. At least is was confusing to me. :) I think for binary search (which implies random lookup is ~ O(n) anyway) it's clearer if you stick to offsets. A few remarks regarding style: You don't need letfn; personally I think it's clearer to use either two separate functions or - in this case - specialize on the arguments. If you define assert_equal as a function, you won't get any good feedback if the assert fails. Use a macro instead. Here's what I made: (defn chop ([val coll] (chop val coll 0 (count coll))) ([val coll left right] ; range to test is left ... right - 1, which makes the code a bit cleaner (if ( left right) ; are we still in a valid range? (let [halve (int (/ (- right left) 2)) index (+ left halve) found-value (coll index)] (cond (= val found-value) index ( val found-value) (recur val coll (inc index) right) ( val found-value) (recur val coll left index))) -1))) ; not found (defmacro assert_equal [v1 v2] `(assert (= ~v1 ~v2))) Note that all of this is pretty low-level but I think it looks kinda nice and readable. -- 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: fast development through clojure repl
Josh Stratton wrote: Are there any tutorials specific to developing and debugging large clojure apps through the REPL? While some people seem to really love going through the REPL all the time, personally I prefer something a little more integrated with my editor. I use the above mentioned swank-clojure/SLIME mode for Emacs for that. What that does is it allows you to edit code in files as usual, but have the program you're writing connected to the editor so you can send/modify definitions or whole files directly from the editor to the program. It also gives you a slightly more fancy REPL within the editor. The most obviously useful part of that is that recompiling a single definition or single file into a running program is MUCH faster than restarting/recompiling, especially if your program is large or (more usually, especially in clojure) has fairly large dependencies like a couple of Mbs of jars. I started a blog series on SLIME with some emphasis on clojure some time ago that highlights some of the interesting stuff in SLIME. It's @ http://joost.zeekat.nl/category/slime-hints/ For anyone who's been waiting the last month and a half: I'm planning a new bunch of posts soonish. :) -- 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: bit-and type hint
Peter Ryan wrote: I am trying to avoid a reflective callback with this function: (defn unsign-byte-from-buffer [#^java.nio.ByteBuffer buffer] (bit-and 0xFF (.get buffer))) (println should be 254 (unsign-byte-from-buffer (java.nio.ByteBuffer/ wrap (byte-array [(byte 0xFE)] when run with (set! *warn-on-reflection* true) I receive the following error: Reflection warning...type-hint.clj:7 - call to and can't be resolved. There is no bit-and for bytes; you need ints. At least that's what it looks like to me. (defn unsign-byte-from-buffer [#^java.nio.ByteBuffer buffer] (bit-and 0xff (int (.get buffer seems to solve the issue for me. -- 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's n00b attraction problem
On Jun 29, 5:50 am, Sean Corfield seancorfi...@gmail.com wrote: If folks find the Java stack intimidating, maybe Clojure isn't for them? Lots of language run on the JVM and they all require some basic knowledge of classpaths, build tools and existing IDEs such as Ecliper, NetBeans, IntelliJ etc. If folks are new to all that, I don't think it's Clojure's job to teach them - there's plenty of literature out there about the JVM environment and tools. I've programmed Java for a while, and frankly, the standard Java build tools suck if you want to get anything done quickly. That's one of the reasons IDEs are so popular in Java - once you figured them out, at least they keep your dependencies in check without having to write oodles of XML. Anyway, you don't need that in Clojure. What I want is open an editor, and start banging out code interactively. From what I've seen, leining is probably the best way to set that up. I much prefer Emacs/SLIME to any Java IDE. My conclusion: whoever said above that there appears to be two development/build-tool preferences based more or less on Java vs Ruby/ Perl/Python developers is right IMO. And I'd probably recommend leiningen to any newbie not coming from a Java background. Sure you can write a few batch files to start your repl etc, but I think leiningen is probably doing things the right way if you just want to get started using whatever editor you like (plus, it supports Emacs/ SLIME out of the box, which is nice for Lisp programmers who've probably already got the whole Emacs side of things set up correctly 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: State of Clojure web development
On Jun 23, 11:23 pm, James Reeves weavejes...@googlemail.com wrote: Hello there! Hi James! :) 1. Have you written, or are you writing, a web application that uses Clojure? What does it do? I've written one very simple internal organsiation site in clojure that's finished except for a few little bugs. Should be cleared next monday. 2. Which libraries or frameworks are you using? Which versions? compojure in whatever was the last release version - with a few lines of patches. joda-time 1.6 - which should be mandatory for any java/clojure project dealing with time in any way and lucene 3.0.1 3. What made you choose Clojure to develop web applications in? I hate typing any more than is needed. This means a Lisp variant. Clojure is just the best Lisp I know to program in, and the JVM is a bonus if you need it. What are the strengths of Clojure web development? See the previous question. Plus pure functional programming meshes well with typical Front end - Controller - Database web programming. 4. What do you think are the current weaknesses of web development in Clojure? What could be improved? Not sure. Will get back on this. I will say that anyone claiming to have a full integrated solution in clojure right now is probably wrong. And I'm not sure we need an integrated system at all. Which is why I like compojure splitting up into real composable parts. 5. Anything else you want to comment on? Stick with relational databases unless you really need to get rid of them. Don't think of the previous sentence as an excuse to squeeze/enforce an OO/relational mapping in whatever web framework you're thinking of writing. I'm doing fine without one, thank you very much. Cheers, Joost Diepenmaat Zeekat Softwareontwikkeling. http://joost.zeekat.nl/ -- 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: State of Clojure web development
On Jun 24, 1:55 am, Joost jo...@zeekat.nl wrote: compojure in whatever was the last release version - with a few lines of patches. This may be interesting to anyone in the US or Japan: All the patches I made were to fix UTF-8 handling. I live in Europe. We use characters like Ø and ß and you'd better get used to 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: Enhanced Primitive Support
On Jun 22, 3:00 pm, Daniel Gagnon redalas...@gmail.com wrote: Lets just make things easy for the average guy.., If we base the decision on the average guy not writing high performance numeric apps, then we should also base it on the fact that he does not need more than a long in 99% of cases either as Rich points out. And longs are a much simpler concept to grok. My work depends. I've written some audio code in different languages and that needs to be fast. But writing fast math-heavy code is not just a case of no auto-promotion or primitives only. You'll have to be very careful about float - int conversions too (so, for instance, you want to multiply floats only or ints only wherever possible) and you also need to be very careful about how your algorithm is structured. My point is, I expect all code that isn't written with performance in mind to be slow. But for almost all non-audio work, I really don't care all that much, as long as I can get better performance in the few pieces of code that need it. For that reason, I really dislike having to use the ugly *' variants to get the correct math ops. To me, a 10 to 20% slowdown (or rather, less accelleration compared to the current 1.1 branch) is worth it if it guarantees that unbounded data can still be handled by naive code, and it encourages use of correct math in code where speed isn't that important. Really speed-intensive code will need to be documented as using specific input types. I.e. for audio code, you generally use floats or doubles for all data, and any deviation from that will cause problems. For this kind of code, there is no reason at all to support extra-wide numbers. But for most code, I expect to be able to just cram in a bunch of untyped numbers and get the correct answer even if it's a bit slower. I do see the argument that ''longs and doubles should be enough for everybody'' and it's generally true. But making them the default will mean that in the longer run you won't be able to use your bigints with any library, since they'll all default to using the exception-throwing math. I may have misinterpreted the current proposals somewhere, so please correct me if I'm wrong. Keeping up with this thread is kinda hard. Just my 2 cnts. Joost. -- 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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work
On Jun 22, 7:36 am, Larry Travis tra...@cs.wisc.edu wrote: Thanks. I'm not sure what you mean by leiningen or by a clojure project (which almost certainly reveals my inexperience with respect to clojure installation and/or programming!) but I think I can figure it out with some exploration. Leinging is a build/dependencies tool for clojure that should make it fairly easy to include swank-clojure in your project (I mean, clojure program). But really, all you need is swank.swank and the rest of the .clj code from swank-clojure in your class path, and some code like this: (ns your-namespace (:require [swank.swank])) (defn run-swank [] (swank.swank/start-repl 4005 :host localhost)) Calling (your-namespace/run-swank) will start a server that you can connect to with M-x slime-connect from Emacs. HTH, Joost. -- 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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work
On Jun 20, 8:03 am, Larry Travis tra...@cs.wisc.edu wrote: So far so good. But then when I open a new file, say /foo.clj/ (and indeed am presented with a buffer in clojure mode), and do /M-x slime/, I get the error message Symbol's function definition is void: define-slime-contrib. As I understand things, what I should get the first time I do /M-x slime/ is something like Clojure is not installed. Do you want to install it? Yes or No -- but I don't. Current swank-clojure doesn't include the elisp part anymore, so you can't start slime and expect a running Clojure image. See http://groups.google.com/group/swank-clojure/browse_thread/thread/4afb565185842d31 for where the code went. For core swank-clojure (without the elisp parts), you start a swank server somewhere (using leiningen or some other script) and connect to that using slime-connect. This means you don't need to install swank- clojure in your clojure project, and can use general Slime and clojure-mode in Emacs. -- 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: Need help getting Snow Leopard, Aquamacs, Clojure, and Slime to work
On Jun 21, 3:07 pm, Joost jo...@zeekat.nl wrote: For core swank-clojure (without the elisp parts), you start a swank server somewhere (using leiningen or some other script) and connect to that using slime-connect. This means you don't need to install swank- clojure in your clojure project, and can use general Slime and clojure-mode in Emacs. Ugh. I meant to say You DO need to install swank-clojure in your clojure project and the rest in Emacs. -- 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: noob questions - Hello world + learning
On Jun 14, 10:09 pm, Jared tri...@gmail.com wrote: Also, I thought this language is functional but I'm able to do change declarations in the repl. For example: user= (def x 1) #'user/x user= x 1 user= (def x 2) #'user/x user= x 2 user= (def x (+ 1 x)) #'user/x user= x 3 Why does that happen? This seems to go against the ideas of functional programming. I can do the same things with functions too. It's true that def isn't a strictly functional construct. That's by design, since def is the construct that allows you to define and set globally accessible vars, which includes all globally accessible functions. If you couldn't re-def a var, you couldn't redefine functions while coding (or modify/extent existing functions using macros etc). Clojure (like most Lisps) is a dynamic language with strong support for interactive development - and you need redefineable vars (or something similar) for that. The alternative is to recompile/load the whole program every time you change a function definition. And that sucks too much. In idiomatic code, you only use (def) and its variants to set up globally reachable data/functions across all threads and you don't, for example, use def as a way to get variable variables - you will get bitten if you try. -- 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: Complex type in clojure
On Jun 14, 7:12 pm, Travis Hoffman travis.a.hoff...@gmail.com wrote: I'm a n00b with git (but experienced with cvs and svn); I'm still trying to figure out how to push my local git repository changes to the fork I created on github. Can anyone help me there? The fork on git-hub is: git://github.com/travis-a-hoffman/clojure.git I created a branch locally complex_type, and have done git commit -a with my changes. I can't, however, seem to push my changes back to github: ~/Projects/HackingClojure/workspace/clojure git push fatal: remote error: You can't push to git://github.com/travis-a-hoffman/clojure.git Use g...@github.com:travis-a-hoffman/clojure.git This is because you're trying to push to the read-only URL. Using the recommended doesn't help: ~/Projects/HackingClojure/workspace/clojure git push g...@github.com:travis-a-hoffman/clojure.git Permission denied (publickey). fatal: The remote end hung up unexpectedly Looks like you haven't given permission for your SSH key on the github site. Go to your Account Settings - SSH public keys and add your public key there. It should be in ~/.ssh/id_rsa.pub, if not, make one first with ssh-keygen -- 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: SLIME REPL clojure completion
On Jun 8, 12:34 pm, Rick Moynihan rick.moyni...@gmail.com wrote: user java.lang.StrTAB No dynamic expansion for `user java.lang.Str' found. check your slime-complete-symbol-function. slime-complete-symbol* does not complete java classes, but slime- simple-complete does HTH, Joost. -- 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: SLIME REPL clojure completion
Oops: check your slime-complete-symbol-function. slime-complete-symbol* does not complete java classes, but slime- simple-complete does that last one should be slime-simple-complete-symbol -- 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: SLIME REPL clojure completion
Oh, and make SURE pressing TAB actually calls slime-complete-symbol and not some non-slime completion function. You can check by doing (in a clojure-mode buffer) C-h C-k TAB I believe the default binding is C-c TAB and M-TAB - not TAB. Joost. -- 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: Loop and Recur
On Jun 7, 1:49 pm, Bruce Durling b...@otfrom.com wrote: Steve and Jon, On Mon, Jun 7, 2010 at 12:43, Steve Purcell st...@sanityinc.com wrote: Empty seqs are logically true, so your if condition is always true. I was looking at that today too. I did ( 0 (count my-list)) in my if statement to fix it. Be aware that counting a list is an O(n) operation (since it needs to walk all the links in the list). The preferred way to test if any seq- able thing is empty is (empy? thing) and the already mentioned (seq thing) to test if it's not empty. Joost. -- 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: studying core.clj, questions on read-lines, lazy-seq, and if-let
On Jun 7, 6:37 am, toddg t.greenwoodg...@gmail.com wrote: I'm attempting to read and understand core.clj, and I'm walking through methods as I run into them, trying to understand them, line by line. I' mostly understand read-lines (w/ the exception of the last line), but I do not follow lazy-seq or if-let. Could someone check my deconstruction of read-lines and make sure I'm getting this right? -Todd 1. read-lines This is from clojure.contrib.duck-streams, right? (defn read-lines Like clojure.core/line-seq but opens f with reader. Automatically closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE. [f] (let [read-line (fn this [#^BufferedReader rdr] (lazy-seq (if-let [line (.readLine rdr)] (cons line (this rdr)) (.close rdr] (read-line (reader f 1.1 define a function, named 'read-lines', that takes a single parameter, 'f' (defn read-lines [f] 1.2 create a scoped variable, 'read-line', and assign a function to it (let [read-line (fn this [#^BufferedReader rdr] 1.3 the function is called 'this', and it takes a BufferedReader...note the compiler hint telling that this is a 'BufferedReader' (that's what the #^ is doing) 1.4 create a lazy sequence (lazy-seq Q: what is a lazy-seq? A lazy-seq makes a seq that's backed by functions instead of a plain data structure. the main advantage of lazy seqs is that they can present a normal seq interface over data that's hard or slow to realize as a pure list (like infinite or huge lists or disk-based data). especially when it's expected not all of the seq is actually relevant to the user. 1.5 let line equal the result of rdr.readLine (if-let [line (.readLine rdr)] 1.6 if line is true, then insert this line at the head of a sequence (cons line (this rdr) 1.7 if line was false, then close the reader (.close rdr] 1.8 invoke the locally defined read-line function on... Q: what does (reader f) mean? What is 'reader'? the reader function is defined elsewhere in duck-streams. It converts a number of possible types into a BufferedReader. (read-line (reader f 2. lazy-seq (defmacro lazy-seq Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls. {:added 1.0} [ body] (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body))) This is mostly just a call to the constructor of clojure.lang.LazySeq that encaptulates the expressions provided in a function. In other words, most of the interesting stuff is in the java code. 3. if-let (defmacro if-let bindings = binding-form test If test is true, evaluates then with binding-form bound to the value of test, if not, yields else {:added 1.0} ([bindings then] `(if-let ~bindings ~then nil)) ([bindings then else oldform] (assert-args if-let (and (vector? bindings) (nil? oldform)) a vector for its binding (= 2 (count bindings)) exactly 2 forms in binding vector) (let [form (bindings 0) tst (bindings 1)] `(let [temp# ~tst] (if temp# (let [~form temp#] ~then) ~else) Disregarding the argument checking and edge cases and the details of prevention of multiple evaluation, the code first stores the result of the test expression, then tests if it's true, if so: store the result under the given binding and evaluate the then-expression. otherwise, evaluate the else-expression. You may want to read up on macros in clojure. Joost. -- 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: runtime inspection: how to get a list of all defined keywords?
On Jun 5, 9:19 am, Meikel Brandmeyer m...@kotka.de wrote: Am 05.06.2010 um 08:49 schrieb ataggart: If I understand correctly, keywords aren't defined anywhere; they are literal values, so your question would be akin to asking for a way to retrieve all the literal integers used in the code. That said, there may be some implementation detail that maintains the set of instantiated keyword values, but so far as I've seen, there's nothing in the public api. Integers (when not BigNumbers) are trivial to compare so you don't need to keep a list. But keywords are different. In any language that does keywords right, keywords evaluate to themselves the same keyword always evaluates to exactly the same object (since keywords are also immutable in any language). This makes equality tests on keywords very fast (you can convert from string to the object at compile time) and implies you've got a list (or probably hash-table) of them somewhere anyway. Vim has a feature that let's you complete arbitrary keywords (vim's definition, not clojure's) which are used in an open buffer. So when you have ::some-terribly-long-keyword-so-that-completion-makes-sense in one buffer, then you can type ::some-teC-n in another buffer and Vim will happily complete it. Maybe emacs has a similar feature? This would also have the advantage, that you don't need a running swank in the background. Although it's not completely accurate, it's a reasonable approximation. Well, when you're working with SLIME, you've got a running swank anyway, so doing a less accurate (and probably much more complex) search through the source (assuming you've got all of it) is not something I'd prefer when I've got close to 100% accurate completions for everything else. Joost. -- 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: update-in oddness
On Jun 4, 7:37 am, Heinz N. Gies he...@licenser.net wrote: Update-in behaves oddly when getting an empty path. (update-in [] {1 2} (constantly {2 3})) returns {nil {2 3} 1 2} not {2 3} as I'd expect. get-in works well with empty pathes so I think this isn't a good behavior. I don't know why you expect that to do anything - first of all, the second argument to update-in should be a seq of keys. In any case, it throws nth not supported on this type: PersistentArrayMap [Thrown class java.lang.UnsupportedOperationException] -- 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: update-in oddness
On Jun 4, 1:42 pm, Heinz N. Gies he...@licenser.net wrote: Sorry I mixed arguments, it should be (update-in {1 2} [] (constantly {2 3})) Yes, that gives {nil {2 3}, 1 2} You're not giving any key in the key list, so that is the reason there's a nil key now, and {2 3} is just the value that you give it, since that's what ((constantly {2 3}) nil) returns. Seems correct as far as the documentation of update-in is concerned. Joost. -- 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: update-in oddness
On Jun 4, 2:03 pm, Joost jo...@zeekat.nl wrote: Seems correct as far as the documentation of update-in is concerned. Addendum: though I think you've got a point in that inserting a nil key is unexpected. Personally, I don't really know what to expect from that expression. Joost. -- 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
runtime inspection: how to get a list of all defined keywords?
I asked this on the swank-clojure list too*, but no responses so far. I want swank-clojure to complete on keywords as well as vars, but the only place I can find that has that information is clojure.lang.Keyword.table, which is private (probably for good reasons). Is there any way to get a seq of the defined keywords at run time? I imagine that would be interesting for other development/debugging systems beside SLIME too. Thanks, Joost. * http://groups.google.com/group/swank-clojure/browse_thread/thread/5c938a3ce3a5d42b -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to make that eval could see its caller context
On May 31, 12:03 pm, Michael Jaaka michael.ja...@googlemail.com wrote: Hello, I would like to make that eval see context of the caller block. In the example: (defn my-if [a b c] (let [z (name (gensym)) t (symbol (str z true)) f (symbol (str z false)) ] (def t (fn[] b)) (def f (fn[] c)) (def mycond (boolean a)) ((eval (symbol (str z mycond)) the symbol can't be found in context represented by the eval. What to do to make it working? Practically all of the time you need to solve this kind of problem, you can use a map with symbol - value pairs instead of adding bunch of variable definitions to the environment. And it usually turns out once you do this you don't even need to (eval) anything anymore. You also *really* do not want to redefine globals in a function body if you have any pretense of doing functional code. Why don't you use (let []) instead? Joost. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to make that eval could see its caller context
On May 31, 1:11 pm, Michael Jaaka michael.ja...@googlemail.com wrote: Well, this is just an example. I need to refer to global vars from eval. You can do that already: user (def bla foo bar) #'user/bla user bla foo bar user (eval 'bla) foo bar user It's just not a good idea. -- 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: special form vs. macro
On May 31, 4:35 pm, Quzanti quza...@googlemail.com wrote: That was interesting. One more Q. What determines whether special forms can be used in functions eg you can't def a variable in a fn. You can: user (defn fun [v] (def my-v v)) user (fun 'a) user my-v a user (fun 'b) user my-v b I'm not aware of any special form that can't be used inside a function. But I haven't looked for them either. Is it there some rule or is it special form specific depending on (a) the intended use of the special form (b) the mechanics of getting the compiler to use the special form First you'd have to find such special forms. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: java.lang.Boolean cannot be cast to clojure.lang.IFn
On May 31, 2:11 pm, garyk gkhomin...@gmail.com wrote: Hi, I've started learn Clojure. While I am writing some functions I was getting the java.lang.Boolean cannot be cast to clojure.lang.IFn. I was wondering if somebody could help me to move on: ; for testing (def sudoku ( sorted-map '[1 1] '(98) '[1 2] '(123) '[2 1] '(56789) '[2 2] '(456))) (def vall 4) (def poss (vector [1 1] [1 2])) (defn valueIn [map value positions] (loop [start (first positions) end (rest positions) cont false] (if (or (true? cont) (nil? start)) cont (recur (cont (contains? (get map start) value)) (start (first end)) (end (rest end)) recur takes positional arguments, not (key value) pairs (which aren't pairs, but function calls). You want *something* like (recur (first end) (rest end) (contains? (get map start) value)) but I can't really make heads or tails out of your code. Note that '(56789) is a list of ONE number, while it looks like you're expecting it to be a list of digits - that would be '(5 6 7 8 9) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: java.lang.Boolean cannot be cast to clojure.lang.IFn
Oh, and you code throws clojure.lang.PersistentVector cannot be cast to java.lang.Number [Thrown class java.lang.ClassCastException] for me. -- 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: special form vs. macro
On May 31, 7:54 pm, Meikel Brandmeyer m...@kotka.de wrote: It works sometimes. Of course you can redef a Var via function. (defn foo [y] (def x y)) (foo 5) However, you cannot define arbitrary Vars. (defn bar [x y] (def x y)) (bar 'c 5) True, but that's more a question of the interface provided by def. The real problem is that if you want to access the vars defined by that function anywhere else, they need to be defined (if not initialized) before you can compile the code. Meaning you either have to def those vars somewhere else (outside of a function) or make sure the function gets called at least once before any access is mentioned in the code. After that, you can re-define the var in any way you like. -- 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: Understanding sequence abstraction
On May 30, 8:11 pm, Richard Newman holyg...@gmail.com wrote: 2. Why is there no other way to determine an empty coll except (not (seq coll)). user= (empty? []) true And in fact, the docs for (empty?) say: Please use the idiom (seq x) rather than (not (empty? x)) Perhaps the seq docs should indicate empty? in some way. -- 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: 57 varieties
On May 28, 9:26 pm, Steve Purcell st...@sanityinc.com wrote: If it helps, I've got a working non-ELPA set-up which you can browse here: http://github.com/purcell/emacs.d It uses git versions of Slime, Clojure-mode and Swank-clojure (as git submodules). Feel free to mail me off-list with any questions. Similarly; my setup is here (only tested with clojure 1.1): http://github.com/joodie/emacs-d with most of the relevant configuration in http://github.com/joodie/emacs-d/blob/master/topics.d/topic-clojure.el -- 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: Lazy map implementation
On May 28, 4:39 pm, Robert Luo robort...@gmail.com wrote: I need a lazy map in my compojure based application to inject data into handlers. I searched the web for an implementation, I got one from Meikel which was written in 2008. Is there any recommendation? Thanks. I don't really see what you're trying to do with this, but as an alternative, you can assoc lazy-seqs to a standard map. That is, if your values are going to be seqs (IME, most of the things you want lazy evaluation for are). Joost. -- 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
Announcement: SLIME hints blog series
Hi everyone, I've started a series of short (ish) blog posts regarding SLIME (The Superior Lisp Interaction Mode for Emacs). Mostly just highlighting simple stuff that makes working with SLIME a little bit nicer. I try to keep it Lisp-agnostic, but since I'm working almost exclusively with Clojure, some clojure-specific stuff might turn up as well. I've got a few more posts planned at the moment, and I don't know how long the series is going to be, so any remarks or suggestions are welcome. Please note that I've got comments switched off on the blog because of spam, so either send me an email or reply to this thread if you've got something to say :) You can find all the posts in the series in reverse chronological order at the following URL. http://joost.zeekat.nl/category/slime-hints/ Cheers, Joost. -- 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: Which GUI toolkit would you like to see wrapped in an idiomatic Clojure library?
Personally, I prefer SWT over Swing mostly because seems a lot more useful and a little more responsive to the user. But then I think Swing is horrible and SWT is just a bit better. I seriously prefer Tk over both (except for the file selection dialogs on Unix). Consider this a + vote for SWT and possibly QT. -- 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: Error when tried to compile with C-c C-k in emacs.
On May 18, 9:38 pm, Robbie Vanbrabant robbie.vanbrab...@gmail.com wrote: - use slime-connect and say yes on this: versions differ: nil (slime) vs. 20100404 (swank) continue? - works For completeness, I started from an emacs-starter-kit installation and then installed swank-clojure and SLIME using ELPA. Removing swank-clojure with elpa does not get rid of the warning. Is there another way to get rid of it? (I also don't get how my SLIME version can be nil). To get rid of the warning/question, you can do (require 'slime) (setq slime-protocol-version 'ignore) somewhere in your emacs init script. As this thread shows, using incompatible swank/slime versions can cause problems, but personally I find the warning too intrusive so I've switched it off. Joost. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can't defalias a macro in clojure 1.2?
On May 7, 12:14 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Just pushed a fix for this. (An ugly hack, really.) Let me know if it works for you. Thanks Stuart, that seems to have done the trick. Regards, Joost. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Can't defalias a macro in clojure 1.2?
In clojure 1.1 you can use defalias on macros, but as far as I can tell, in the current 1.2 branch, this won't work anymore. Is this intentional, and if so, how can I work around it once I start porting stuff to 1.2? Regards, Joost Diepenmaat. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can't defalias a macro in clojure 1.2?
On May 6, 7:01 pm, ataggart alex.tagg...@gmail.com wrote: What defalias are you talking about? The one in clojure.contrib.def -- 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.contrib.sql insert id
On Apr 21, 11:48 am, Remco van 't Veer rwvtv...@gmail.com wrote: Nice! That's a lot better than depending on some quirky sql construct. Agreed. There's just one potential issue (which is the same issue I have with clojure.contrib.sql): it doesn't quote the column or table names, meaning you can't use such nice column keys as :user-id I smashed all of it into my modified version of clojure.contrib.sql: http://gist.github.com/373677 -- 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
apparent bug with binding (or contrib.sql ?) in current master branches
Hello, The following works on the 1.1.0 release of both clojure and clojure.contrib: $ java -server -Djava.net.preferIPv4Stack=true -Dpid=30893 - Djava.awt.headless=true -cp clojure-1.1.0/clojure.jar:clojure- contrib-1.1.0/clojure-contrib.jar clojure.main Clojure 1.1.0 user= (use 'clojure.contrib.sql) nil user= (binding [clojure.contrib.sql/do-commands #(prn %) clojure.contrib.sql/do-prepared #(prn %1 %2)] (do-commands bla)) bla nil But on the master branches I get: $ java -server -Djava.net.preferIPv4Stack=true -Dpid=30893 - Djava.awt.headless=true -cp /home/joost/lib/clojure/clojure-1.2.0- master-SNAPSHOT.jar:/home/joost/lib/clojure-contrib/clojure- contrib.jar clojure.main Clojure 1.2.0-master-SNAPSHOT user= (use 'clojure.contrib.sql) nil user= (binding [clojure.contrib.sql/do-commands #(prn %) clojure.contrib.sql/do-prepared #(prn %1 %2)] (do-commands bla)) java.lang.Exception: no current database connection (NO_SOURCE_FILE:0) It looks like I can't bind do-commands... But this works: user= (defn test-me [] (prn orig)) #'user/test-me user= (binding [test-me #(prn bound)] (test-me)) bound nil I have no idea what's going on. -- 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 To unsubscribe, reply using remove me as the subject.
Re: Are there any plans for more allowed symbol characters?
On 1 mrt, 23:02, Michael Wood esiot...@gmail.com wrote: I don't know if the following's allowed, but it works: user= (def ð Math/PI) #'user/ð user= ð 3.141592653589793 Sine the JVM considers all strings to be 16-bit unicode, I would expect all the usual java/unicode number/letter types to be valid, including the special unicode number/letter category, (accented) upper, title and lower case and a few more. See also, Java's Char.isLetterOrDigit documentation. -- 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: Presentatie over Clojure
A Very Simple Example: (defn list-projects [request posts] (wrap request :project (text :projects) (map project-block posts) (link-to /project/edit/ new))) That's a top-level view function from a (nearly) production site I'm working at right now. Note: Clean readable code. This doesn't use any particular new or fancy feature of clojure. All it is pretty much standard LISP with no side effects. No macros or anything like that. Automatically thread safe. Uses (map project-block posts) to translate a list of project descriptions (a seq of nested maps) into a structured display format, and project-block is simply a function that translates a single project description into the required format (in this case, compojure's generator format). Try doing that with a C-style for loop. If you're presenting to non-functional programmers, I'd concentrate on the basic and immediately useful stuff: map is one of the most useful things I can think of - it pops up everywhere. reduce may be cooler, but you're not going to use it nearly as much. From that project: total lines (including whitespace, comments etc): less than 2000. Total uses of (map) - excluding macros that embed it: 78. That's a map call almost 8% of every line. If I'd had to guess, I'd say that at least half of my loops are done using plain map. Besides: new Array arr; (for i =0; i list.length; i++) { arr[i] = inputArr[i]+1; ] return arr; vs (map inc inputArr) And who's going to argue? -- 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: Dutch Clojure users
On 7 feb, 13:09, Hubert Iwaniuk neo...@kungfoo.pl wrote: Great to hear that there is Clojure group around. For ease of finding it:http://groups.google.com/group/amsterdam-clojurians?hl=en Cheers, Hubert Joined as well. I'm in Utrecht. Shame I missed today's meeting. -- 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/SLIME/Emacs questions
On 31 dec, 13:07, Baishampayan Ghose b.gh...@ocricket.com wrote: This one is called fuzzy-completion, which for some unknown reasons doesn't work with SLIME + Clojure. It used to work perfectly with Common Lisp. I would appreciate a solution to this too. Works for me, but you must have slime-fuzzy or slime-fancy enabled. So you need something like this in your emacs config: (slime-setup '(slime-fancy ;; turns on fancy inspector, autodoc and other useful stuff slime-highlight-edits)) This binds (slime-fuzzy-complete-symbol) to C-c M-i You can also use hippie-expand, which does the same sort of completion, but doesn't query the running lisp. Joost. -- 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: popping optional args from the front
Personally, I prefer to use multiple implementations, like: (defn aaa -- 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: popping optional args from the front
Personally, I prefer to use multple prototypes: (defn bla ([aaa bbb ccc] ) ([bbb cc] (bla 0 bbb cc))) etc. -- 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: Loading a .clj file automatically at repl startup?
You can also create a small start.clj file that does whatever it needs to do (use 'foo) and ends with a call to (clojure.main/repl) -- 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: Advice for someone coming from an OO world?
On 18 dec, 17:55, IslandRick rick.braumoel...@gmail.com wrote: Can anyone here offer some advice to those who are too ingrained in using an object-oriented hammer on every nail they see? I know Rich and Stuart have some good design examples around (I've read many), but if there are any tutorials that show how to re-envision OO problems in an FP world, I'd love to see them. You are probably running into two problems at the same time: 1 is the expectation that you can modify stuff left and right 2. is the dispatch issue In my (short) experience with clojure, the main problem is actually #1. In most relatively simple programs in clojure you actually don't need all that much dynamic dispatching, and if you really do need it there's always multi-methods. When you're working in clojure and want to keep the code simple, it's vital that you think about what parts of the shared data can actually change, and try to keep those parts minimal, and keep the inter- changeable parts as unrelated as possible. That tends to mean you probably prefer not to set up a big graph of inter-related objects if you can help it - while that is something that's common in OO programming. Rich's ant colony example is a good demonstration of that principle: instead of having ant objects that carry around all kinds of state, you have a static grid of mutable locations and the ants are immutable objects contained in the grid's cells. Hope that helps, If you've got more specific questions about your program, people here can probably help you in more detail. Cheers, Joost Diepenmaat. -- 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: Advice for someone coming from an OO world?
Oh and another thing: In my experience, it's easier to start by putting all the code in a single package, and only split it up once you get to a level of complexity that really demands splitting it up. Emacs/SLIME (and probably other interactive environments) really help too: once you've written/rewritten a function, you want to test it immediately, interactively. Write/compile/run loops are annoying if you don't have an interactive environment. This is why in emacs, the *scratch* buffer and ielm are so handy. -- 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: Parenthesis Inference
On 19 dec, 15:25, Martin Coxall pseudo.m...@me.com wrote: I guess it's mostly a matter of judging a language by its long-term merits instead of initial appearance -- just like with so many other things in life. That - right there - is a tacit admission that the Clojure community will find it actively desirable that it remain a minority language, so we can all feel smug that we understand something those poor average programmers were too simple to see. You know there's nothing wrong with allowing Clojure to display its elegance upfront, rather than making programmers work for it like it's some Presbytarian admission exam. Most programming languages aren't judged on their syntactical elegance, otherwise nobody would use Erlang, for example. Now I like Erlang, but I still think it just looks horrible and it has way too many syntactical niggles that are hard to get familiar with. Lisp languages are completely simple in that regard. The worst question you generally run into is whether to add 1 or 2 pairs of parentheses at some point. Clojure makes this a bit simpler in the generally-used cases and a bit harder overall (since it uses 4+ different kinds of delimiters) Now that does not mean it doesn't look alien. It does. Deal with it or do something else. But don't pretend that doing what clojure *does* is much easier to write or read in any kind of familiar syntax, unless you're got a really serious contender. It's been tried many times - McCarthy himself did not think s-expressions were the final syntax for the language - but nobody has been able to come up with a syntax that actually works better for Lisp. Once everything is an expression - and especially when you place a large emphasis on side-effect free code - all you can really do to improve the parenthesis problem is to compact typical constructs. We've already got macros and decent reader syntax. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: How to fund open source Clojure development
On 16 dec, 21:48, Joe globalwarmingisah...@gmail.com wrote: a. Offer new clojure features in binary form to developers who pay $100 a year 3 months before everyone else. Would stifle development and piss off everybody who's working with clojure and doesn't want to pay. b. Run a clojure programmer temp and/or high level consulting agency. Running an agency costs money. Who is going to do all the work? Basically you're asking for a company or other intested parties to donate money. That's what Rich is doing already. c. Charge for cert testing and training. See b. Also: I bloody hate tests. d. Sell for access to online library api calls. If you want to kill off clojure that would be a good idea. e. Find a business for whom Clojure is a critical piece of technology. Yes. See b) f. Get employed by a standards body or consortium trying to develop parallel programming. Who? What? See b) g. Keep Clojure open source but make native tool chain compilers for various platforms available only online-ie android. See d) h. Sell support contracts or create a business that does that and than employs you, similar to RedHat. See b) i. Sell Clojure training classes to teachers and schools, advocating that Clojure is ideal for the classroom since it combines the widespread industry tool Java and the comp sci friendly and desireable Lisp. See b) -- 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: Call for masters thesis ideas (possibly related to Clojure)
On 18 dec, 13:35, Patrick Kristiansen patrick.kristian...@gmail.com wrote: Hi We're two students that have been working with concurrent programming languages (Erlang and Clojure), and while both languages are very interesting, we would like to work on something related to Clojure in our masters thesis. I once asked on #clojure for ideas, and Rich Hickey suggested looking into predicate dispatch and it is one idea that we are considering. We have also considered working on distributed Clojure, but I don't know if there is already an effort going on in that regard? Do you have any other suggestions? We'd be really thankful for any suggestions. Erm, what's your master? I'll assume CS. Personally, I'm interested in whether complete thread abstraction that makes threads as light-weight as possible, but also the only way to do concurrency (like Erlang provides with its processes) is really the best way to model concurrent programs. I'm over 95% sure that native threads really are not the best way to model in-process concurrency for most programs, simply because of all the overhead that you incur especially when dealing with massively concurrent long- running thead-like-things - since you both know erlang, you will know what I'm talking about - that sort of approach really doesn't work in clojure, that's why clojure uses thread pools for agents etc. But maybe a new and lightweight in-kernel thread model is an interesing subject? Just asking :) Good luck with your thesis, Joost Diepenmaat. -- 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: Call for masters thesis ideas (possibly related to Clojure)
On 19 dec, 01:20, Patrick Kristiansen patrick.kristian...@gmail.com wrote: Thanks for your suggestion. It's an interesting idea, and we've been considering something along those lines. I don't know if Erlang's processes are even more lightweight than green threads. According to Wikipedia [1], Linux actually performs really well in terms of context switching OS threads compared to green threads. But I can't find the paper Wikipedia cites, and it seems not to be downloadable from ACM [2]. The problem seems to be two part: 1. Starting new native thread takes a relatively long time 2. Native threads means a fairly significant memory and scheduler consumption. In Java-based threads, that means for example that a 20,000 connection server is pretty much the maximum that's possible in that model. In Erland, 20,000 concurrent connections is what you should expect from an unoptimized system. This is at least partly due to kernel design, but also due to language design. A purely side- effect free language is much more capable of sharing data. In *that* regard, it's probably easier to optimize Erlang than Clojure. But in any case, massive networking is the key - In clojure, there is plenty of room to improve in that regard. In Erlang probably too, but erlang has no really interesing memory sharing mechanisms. -- 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: Mapping OOPS concepts to Clojure? Doable or Wrong thinking?
On 13 dec, 08:12, Raoul Duke rao...@gmail.com wrote: hi, 2. In my mind, the single most important use of OO is polymorphism. The ability to associate functions with multiple implementations depending on their parameters is very useful since it means you can generalize algorithms without having to know the implementation details of the data that's passed in. this probably isn't the right list to get into such things, but... :-) i think that polymorphism here would need to be better defined since there are many kinds of it, and that a lot of polymorphism doesn't in any way have to be anything about OO at all. i'm just trying to warn against believing 'OO bijection Polymorphism' or some such. Of course you don't need OO to do polymorphism, and I'm fairly sure that OO doesn't do polymorphism the best way, but in my estimation the main reason classic OO is so popular is that it provides a very concrete way to do polymorphism easily. In the same way, you can do functional (side-effect free) code with objects too. They're not mutually exclusive. It's just that doing stuff side-effect free pretty much forces you to drop many of the classic OO patterns. -- 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: Mapping OOPS concepts to Clojure? Doable or Wrong thinking?
On 13 dec, 19:48, Raoul Duke rao...@gmail.com wrote: seems to me that a lot of it comes down to connotations vs. denotations; I really don't know what you mean by that. what /is/ OO, anyway? :-) From what I've seen, it's the association of function implementations with a complex type or data structure. -- 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: Mapping OOPS concepts to Clojure? Doable or Wrong thinking?
On 13 dec, 21:19, Richard Newman holyg...@gmail.com wrote: At the risk of going off on a bit of a tangent: My experience with teaching OO to university students (and watching my own class learn it) suggests that polymorphism -- at least, as presented by C++ and Java -- is the hardest concept for beginners to grasp. I would probably say that that is because it is the most powerful aspect of OO. Power is hard to wield effectively. Encapsulation and some (usually erroneous) notion of 'modeling the world' would seem to be the most obvious improvements over structured programming, and beginners pick those up easily. When you present a scenario of some object representing a bank account, owning its balance and providing an interface to access it, OO seems a natural fit to the problem. Polymorphism builds on that, yes, but one could have a useful OO system without it (e.g., the various approaches to OO in C, such as putting function pointers in structs, or prototype-based OO systems). Oh yes, OO demands a kind of view of the problem that helps in breaking it down into manageble items, but it's not easy. In fact, I think it's actually hard to design an object-based system that models a problem well - in the general case - and the main reason we as programmers feel comfortable with OO is that we're so used to it. In the same way we tend to feel comfortable with relational databases - they're both a help in that they give you a pretty clear way of deciding what works and what doesn't, but at the same time, they can force all kinds of restrictions and work-arounds that are completely artificial. Encapsulation as in access control is really quite incidental and only marginally helps you in making sure the program works as expected - but neophytes to OO seem to think that that is the main benefit - while you can do encapsulation and API contracts in any language that has functions. I've commented in the past that whoever thought up protected should be publicly shamed. That's not to say that pure functional programming is better. As a general design principle, I would say it is, but you'll still run into problems where maybe OO has the better tools or the more straight- forward means of mapping a problem to code. I suspect that students' difficulty with traditional OO polymorphism has something to do with having to hold the inheritance hierarchy in their heads while also looking at the instance, and figuring out what will happen. At that larval stage it's a lost cause to dive into virtual function tables :) Inheritance is at the same time too powerful and too weak. Look at any large Java project's API docs and try to figure out what the hell is happening. It just doesn't work for anything that isn't fundamental or clearly restricted. It's just not a good way of handling the larger problems. See the number of Java classes named XXXworker/actor/factory/ builder etc. Those things aren't objects; they really are just a bunch of functions. I think it's actually harmful when the language forces OO upon you because that kind of thinking can cloud the intent of whatever it is you're trying to build. I'd be interested to see how Clojure's multimethods -- which pull out the dispatch function into a concrete thing -- fare by comparison. As with a lot of things, having a REPL there and being able to call the dispatch function on various inputs would be a massive aid to understanding. At the very least, explicit dispatch functions force you to think about what you're doing. That's probably a good thing. In my experience, you really don't need them much at all though. As with standard polymorphism, it's a great tool when it fits - especially when designing general libraries - but it's not something you need much in day-to-day programming, except - maybe - as a way to deal with name clashes. -- 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