Re: take 1 element from each coll, make all possible strings?

2008-12-29 Thread bOR_
Timothy - It becomes more tricky if you want to know what fraction of everything a host can present that carries 2 or 3 different filters (I mentioned that somewhere). For example: everything is 4^4 = 256 options [ABCD][ABCD][ABCD][ABCD] Host carries these two filters: [ABC][AC][AB][ABC]

Serializing functions

2008-12-29 Thread Itay Maman
I want to be able to read and write a clojure object, which contains functions, from/to a file. The structure looks something like this: { :s my-string :f (fn[x] (inc x) } Reading is easy: (load-file ...) works fine. The tricky part is writing it back to the file. (pr ...) gives something like

Re: making code readable

2008-12-29 Thread Emeka
Mark, Thanks so much for pointing that out, it makes Clojure to belong to others. Clojure should not be only for FP experts and PH.D holders. I took time to check the background of some members in this group: we have lecturers, research scientists and others from the best technical schools. I know

Re: Exercise: words frequency ranking

2008-12-29 Thread Timothy Pratley
You could consider using a StreamTokenizer: (import '(java.io StreamTokenizer BufferedReader FileReader)) (defn wordfreq [filename] (with-local-vars [words {}] (let [st (StreamTokenizer. (BufferedReader. (FileReader. filename)))] (loop [tt (.nextToken st)] (when (not= tt

Re: Fibonacci sequence

2008-12-29 Thread Craig Marshall
Hi David, (defn fib (fib-helper 0 1)) ; This doesn't work either: (defn fib (fib- helper '(0 1))) You're missing your argument list for fib. I assumed you meant the empty square brackets [] just after the work fib? I didn't realise these were necessary even when there were no function

Re: Exercise: words frequency ranking

2008-12-29 Thread Emeka
Hello sir, I would have asked this question in the thread but , I don't want to create noise over this issue. I have not been able to get my head around your code or Clojure. I need some support. (defn top-words-core [s] (reduce #(assoc %1 %2 (inc (%1 %2 0))) {} (re-seq #\w+

Re: making code readable

2008-12-29 Thread Itay Maman
I think that just as important as compactness is the issue of density: the ratio of the conceptual weightof the computation to the size of the code expressing it. if a computation is inherently complicated and I manage to squeeze it into a few lines (typically accomplished via an intense

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 12:03 AM, Abhishek Reddy arbs...@gmail.com wrote: Speaking for myself, as the author of the original Snake example, I had no intention of converting developers to Clojure, or of producing instructive or readable code, with that snippet. While I agree with some of

Re: Stumped - Java hangs when using Swing in Slime

2008-12-29 Thread levand
Haven't solved it yet, but I may have found something useful enough for someone cleverer than I to make something out of. When I run clojure directly as inferior-lisp, without slime, the problem does occur. However, as soon as I enter something in the inferior lisp buffer, it starts working

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 5:44 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I would like to produce a version of the snake code that could serve as an example of the kind of code that the Clojure community thinks is good. Unless it's part of an exercise to produce the shortest code

Re: making code readable

2008-12-29 Thread .Bill Smith
My challenge to everyone on the list is to start with any version of the snake code you've seen and make it as readable as *you* think it should be by doing things like renaming variables and functions, adding comments and changing indentation. I'd really like to see what *you* think is the

Re: How to encapsulate local state in closures

2008-12-29 Thread Rich Hickey
On Sat, Dec 27, 2008 at 12:03 AM, Mark Engelberg mark.engelb...@gmail.com wrote: On Fri, Dec 26, 2008 at 8:35 PM, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: It's important to distinguish between updating atoms within transactions and outside transactions. In the former case, one

Re: making code readable

2008-12-29 Thread Matt Revelle
On Dec 29, 2008, at 10:45 AM, Mark Volkmann wrote: On Mon, Dec 29, 2008 at 5:44 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I would like to produce a version of the snake code that could serve as an example of the kind of code that the Clojure community thinks is good. Unless

Re: making code readable

2008-12-29 Thread lpetit
You should consider using docstrings for documenting functions On 29 déc, 16:45, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Dec 29, 2008 at 5:44 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I would like to produce a version of the snake code that could serve as an

Re: Swank in Tomcat via JSP: classpath issues

2008-12-29 Thread Michael Reid
Hi, I'm not sure how to integrate this into the Tomcat JSP scenario, but I think the issue is that *use-context-classloader* is not set to true (it defaults to nil). Again, I'm not positive how to get your JSP to do this, but an untested stab at it would be just to wrap the call to

Re: Swank in Tomcat via JSP: classpath issues

2008-12-29 Thread Michael Reid
Doh! I just read your discussion w/ Anton on his blog. Seems you've already looked at the context classloader. *shrug*. I'm stumped. /mike. On Mon, Dec 29, 2008 at 12:46 PM, Michael Reid kid.me...@gmail.com wrote: Hi, I'm not sure how to integrate this into the Tomcat JSP scenario, but I

Re: making code readable

2008-12-29 Thread Randall R Schulz
On Monday 29 December 2008 09:11, lpetit wrote: You should consider using docstrings for documenting functions There's a big difference between the comments directed at someone reading the code (possibly the author at a later date) and someone wishing to use it. Function-level documentation

Re: IntelliJ Plugin

2008-12-29 Thread Justin Johnson
On Sat, Dec 27, 2008 at 8:55 AM, Peter Wolf opus...@gmail.com wrote: Hi Justin, This is the right place. Thanks for trying the plugin. It would absolutely be helpful to document use of the plugin. However, I am sure you can tell that it is nowhere near ready. Yes, I noticed there wasn't

Re: Suggestion: introduce (defn name attr-map? [params*] doc-string body) form.

2008-12-29 Thread Christian Vest Hansen
Rich rest. I have gone through the process of implementing this in defn. The patch is inlined for commenting (if need be) and attached for accurate application. I declare my changes public domain, but I suppose I could fill out a CA if it helps. I can also make a similar change for defmacro, if

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 11:11 AM, lpetit laurent.pe...@gmail.com wrote: You should consider using docstrings for documenting functions Good suggestion. I've changed my code to do that. I also noticed that I had forgotten to replace special characters with built-in entities in my HTML, so that

Re: How to encapsulate local state in closures

2008-12-29 Thread Mark Engelberg
On Mon, Dec 29, 2008 at 8:05 AM, Rich Hickey richhic...@gmail.com wrote: It is certainly not the whole point of Clojure to make as much code as possible safe for its software transactional memory. Clojure is a set of tools. They are designed to allow for robust programs to be built, including

Re: Modulo

2008-12-29 Thread Rich Hickey
On Dec 29, 7:50 am, Achim Passen achim.pas...@gmail.com wrote: Hi! I uploaded my attempt at this to the files section of this group: http://clojure.googlegroups.com/web/mod-sgn.diff It adds the modulus operator plus, as a by-product, the signum operator (sgn). Comments most welcome!

load-file within a do

2008-12-29 Thread Kees-Jochem Wehrmeijer
Hi everybody, I just got started with Clojure and I'm now trying to simultaneously learn Lisp and Java. My progress is slow, but I'm having a lot of fun. I hit a small roadblock though, because I can't figure out why calling load-file from within a do is behaving the way it is. I'm probably

Re: (Updated) Patch available: unifies entry points, fixes (read-line) for clojure.main/repl, provides source-only jar

2008-12-29 Thread Rich Hickey
On Dec 21, 5:53 pm, Stephen C. Gilardi squee...@mac.com wrote: On Dec 21, 2008, at 4:43 PM, Stephen C. Gilardi wrote: On Dec 21, 2008, at 4:40 PM, Rich Hickey wrote: If main doesn't match the behavior of Repl and Script in this area when run in repl or script modes respectively, it

Re: [jvm-l] Kawa Scheme on Android

2008-12-29 Thread Rich Hickey
On Sun, Dec 28, 2008 at 6:05 PM, Randall R Schulz rsch...@sonic.net wrote: Howdy, Folks, The gauntlet has been thrown down: I've made changes in svn 1186 and 1188 that should help facilitate targeting Android/Dalvik. clojure.jar now translates with dx --dex, but that is all I've had time to

Re: load-file within a do

2008-12-29 Thread Meikel Brandmeyer
Hi Kees-Jochem, Am 29.12.2008 um 20:37 schrieb Kees-Jochem Wehrmeijer: I created a small file foo.clj with the following contents: (defn foo [] :bar) Then from a REPL I try the following: (do (load-file foo.clj) (foo)) but this gives an error message: java.lang.Exception: Unable to resolve

Re: making code readable

2008-12-29 Thread Brian Doyle
Looking at this code the uppercase variables stands out. This isn't idiomatic is it? (def GRID_SIZE 10) (def HEIGHT 600) (def MARGIN 50) On Mon, Dec 29, 2008 at 12:19 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote: On Mon, Dec 29, 2008 at 11:11 AM, lpetit laurent.pe...@gmail.com wrote:

Re: distinct broken?

2008-12-29 Thread Christophe Grand
Fixed (rev 1190) tristan a écrit : Thanks for the explanation Christophe. I really need to try use (for) more often. I seem to forget about it all the time. On Dec 27, 10:42 pm, Christophe Grand christo...@cgrand.net wrote: tristan a écrit : Hi All, I've been trying to

Re: How to encapsulate local state in closures

2008-12-29 Thread Rich Hickey
On Dec 29, 2:29 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Dec 29, 2008 at 8:05 AM, Rich Hickey richhic...@gmail.com wrote: It is certainly not the whole point of Clojure to make as much code as possible safe for its software transactional memory. Clojure is a set of

Re: Accessing this in gen-class constructor

2008-12-29 Thread Chouser
On Sat, Dec 27, 2008 at 9:24 PM, CuppoJava patrickli_2...@hotmail.com wrote: I believe the first parameter must be this, only in the case of methods . The init function doesn't take a this parameter. Correct. My understanding is that the init function is actually run before the instance is

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle brianpdo...@gmail.com wrote: Looking at this code the uppercase variables stands out. This isn't idiomatic is it? (def GRID_SIZE 10) (def HEIGHT 600) (def MARGIN 50) I don't know. I was following Java conventions of making constants all

Re: 12 Days of Christmas in idiomatic(?) clojure

2008-12-29 Thread MattyDub
Emeka, In short, no. Remember, this was about me learning some functional tools, so this shouldn't be viewed as pedagogical. Well, *my* code shouldn't - I can't speak for the other posters in this thread. -Matt On Dec 27, 7:28 am, Emeka emekami...@gmail.com wrote: (defn sum-up-to [n]  

Re: making code readable

2008-12-29 Thread Stuart Sierra
On Dec 29, 3:40 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle brianpdo...@gmail.com wrote: Looking at this code the uppercase variables stands out. This isn't idiomatic is it? (def GRID_SIZE 10) (def HEIGHT 600) (def MARGIN 50) I

Re: making code readable

2008-12-29 Thread Chouser
On Mon, Dec 29, 2008 at 3:40 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle brianpdo...@gmail.com wrote: Looking at this code the uppercase variables stands out. This isn't idiomatic is it? (def GRID_SIZE 10) (def HEIGHT 600) (def MARGIN

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 3:01 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Dec 29, 3:40 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle brianpdo...@gmail.com wrote: Looking at this code the uppercase variables stands out. This isn't

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 3:10 PM, Chouser chou...@gmail.com wrote: On Mon, Dec 29, 2008 at 3:40 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle brianpdo...@gmail.com wrote: Looking at this code the uppercase variables stands out. This isn't

Re: making code readable

2008-12-29 Thread Chouser
On Mon, Dec 29, 2008 at 4:40 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I think that's supposed to be + instead of *, at least Common Lisp seems to use +. I meant * -- I don't know CL at all, but the *asterisk* form is used frequently in clojure.core, while no +plus+ form ever

Re: making code readable

2008-12-29 Thread Darren Austin
I don't know CL that well myself, but I think the convention is to use + for constants (i.e. defconst) where * is used for global variables (i.e. defparameter). In that case the + convention doesn't really make sense in clojure as it doesn't have any notion of a constant reference type.

Re: making code readable

2008-12-29 Thread Mark Volkmann
On Mon, Dec 29, 2008 at 3:58 PM, Chouser chou...@gmail.com wrote: On Mon, Dec 29, 2008 at 4:40 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I think that's supposed to be + instead of *, at least Common Lisp seems to use +. I meant * -- I don't know CL at all, but the *asterisk*

Re: How to encapsulate local state in closures

2008-12-29 Thread Dave Griffith
It looks like the mutable locals use case is covered by the with- local-vars binding form. That said, I'm not sure how useful this would be. Even in Java 5, 95% of my local vars are immutable, i.e annotated as final and never have any mutating methods called on them. Most of the rest are

Re: Some code review for clj-record?

2008-12-29 Thread Brian Doyle
That seems to be working better now John. I looked over most of the code and it seems like a good start. I'm no expert when it comes to functional programming or Clojure, so I'm not sure how to critic the code exactly. If I was doing the porting I would prolly do it in very OO way, since

Re: making code readable

2008-12-29 Thread Tom Ayerst
A useful comment addition: How do I run it? Cheers Tom 2008/12/29 Mark Volkmann r.mark.volkm...@gmail.com On Mon, Dec 29, 2008 at 3:58 PM, Chouser chou...@gmail.com wrote: On Mon, Dec 29, 2008 at 4:40 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I think that's supposed to be

Re: Accessing this in gen-class constructor

2008-12-29 Thread CuppoJava
Thanks for the reply Chouser, Yeah, I figured it would be like that. No this value actually exists until after the init function is called. The reason I'm asking about this is that it's quite standard practice to set up some parameters inside the constructor of a class. ie. A use-case like

Re: How to encapsulate local state in closures

2008-12-29 Thread Mark Engelberg
On Mon, Dec 29, 2008 at 12:40 PM, Rich Hickey richhic...@gmail.com wrote: People who know what they are doing can do these things right now with Clojure's array support. There really isn't any more value for Clojure to add to that, so no special primitives. I fully accept the necessity of

Re: Accessing this in gen-class constructor

2008-12-29 Thread Chouser
On Mon, Dec 29, 2008 at 8:02 PM, CuppoJava patrickli_2...@hotmail.com wrote: The reason I'm asking about this is that it's quite standard practice to set up some parameters inside the constructor of a class. ie. A use-case like this is quite common, and (I think) reasonable. public class

Re: How to encapsulate local state in closures

2008-12-29 Thread Mark Engelberg
On Mon, Dec 29, 2008 at 2:57 PM, Dave Griffith dave.l.griff...@gmail.com wrote: It looks like the mutable locals use case is covered by the with- local-vars binding form. Not really. with-local-vars has somewhat surprising semantics. For example, you'd expect this (contrived) function to

what does - mean?

2008-12-29 Thread wubbie
Hi all, Looking into ants.clj, I came across (defn place [[x y]] (- world (nth x) (nth y))) What - mean here? thanks sun --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group,

Contrib REPL Invocation Changes

2008-12-29 Thread Randall R Schulz
Hi, Following today's SVN updates to the Clojure Core and Contrib (as of this writing, at 17:42 PST, which is GMT -8), I can no longer invoke the Contrib REPL as I was able to before today. When I do, I get no prompt until I type a non-empty line, after which I'm presented with an unending

test-is nesting

2008-12-29 Thread Larrytheliquid
;; Note: originally I was just going to write Stuart, but I think input from anybody on the list could be valuable, so I'm CC'ing Clojure Hi Stuart, I've been working on an RSpec-like library for Clojure called Specjure. It has gone through many iterations and the one that is currently up on

Re: Stumped - Java hangs when using Swing in Slime

2008-12-29 Thread Rowdy Rednose
What if you run the Swing code in the Event Dispatch Thread? In other words, does this: (. javax.swing.SwingUtilities (invokeAndWait #(. javax.swing.JOptionPane (showMessageDialog nil Hello World or (. javax.swing.SwingUtilities (invokeLater #(. javax.swing.JOptionPane (showMessageDialog

Re: 12 Days of Christmas in idiomatic(?) clojure

2008-12-29 Thread Aaron Brooks
On Dec 24, 4:20 pm, Mibu mibu.cloj...@gmail.com wrote: I'd write it this way: (apply + (mapcat #(range 1 %) (range 2 14))) I think idiomatically I would have written it with (partial range 1) instead of #(range 1 %), but I prefer compact forms. In Clojure (anybody correct me if I'm wrong) I

Re: Contrib REPL Invocation Changes

2008-12-29 Thread Stephen C. Gilardi
On Dec 29, 2008, at 8:49 PM, Randall R Schulz wrote: Following today's SVN updates to the Clojure Core and Contrib (as of this writing, at 17:42 PST, which is GMT -8), I can no longer invoke the Contrib REPL as I was able to before today. When I do, I get no prompt until I type a non-empty

Re: How to encapsulate local state in closures

2008-12-29 Thread Timothy Pratley
I think if Clojure could do something like this (enforce a certain kind of referentially transparent mutable local), that would be neat, It is possible to achieve this behavior explicitly: (defn create-add-2 [] (with-local-vars [x 1] (do (var-set x 2) (let [z @x] (fn

Re: what does - mean?

2008-12-29 Thread Paul Barry
You can look up the documentation for a function/macro interactively from the repl: user= (doc -) - clojure.core/- ([x form] [x form more]) Macro Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a

Re: Fibonacci sequence

2008-12-29 Thread Paul Barry
Craig, Something you should be aware of is that this implementation of Fibonacci is very inefficient. For more info as to why, you can read: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2 The short story is doing it this way performs a lot of wasted calculations as n

Re: 12 Days of Christmas in idiomatic(?) clojure

2008-12-29 Thread Chouser
On Mon, Dec 29, 2008 at 9:36 PM, Aaron Brooks aa...@brooks1.net wrote: In Clojure (anybody correct me if I'm wrong) I think it's preferable for performance reasons to use reduce instead of apply when you can. I actually think that's backwards. In many cases it doesn't really matter. It's

Re: Exercise: words frequency ranking

2008-12-29 Thread Timothy Pratley
(defn top-words-core [s]      (reduce #(assoc %1 %2 (inc (%1 %2 0))) {}              (re-seq #\w+                      (.toLowerCase s maps are functions of their keys means: user= ({:a 1, :b 2, :c 3} :a) 1 Here we created a map {:a 1, :b 2, :c 3}, can then called it like a function with

Re: what does - mean?

2008-12-29 Thread wubbie
Very criptic for newbie. What does Threads the expr through the forms. mean? Does it create a thread to execute? thanks sun On Dec 29, 10:07 pm, Paul Barry pauljbar...@gmail.com wrote: You can look up the documentation for a function/macro interactively from the repl: user= (doc -)

Re: [jvm-l] Kawa Scheme on Android

2008-12-29 Thread Adam King
Rich Hickey wrote: On Sun, Dec 28, 2008 at 6:05 PM, Randall R Schulz rsch...@sonic.net wrote: Howdy, Folks, The gauntlet has been thrown down: I've made changes in svn 1186 and 1188 that should help facilitate targeting Android/Dalvik. clojure.jar now translates with dx --dex,

Re: Contrib REPL Invocation Changes

2008-12-29 Thread Randall R Schulz
On Monday 29 December 2008 18:36, Stephen C. Gilardi wrote: On Dec 29, 2008, at 8:49 PM, Randall R Schulz wrote: Following today's SVN updates to the Clojure Core and Contrib (as of this writing, at 17:42 PST, which is GMT -8), I can no longer invoke the Contrib REPL as I was able to

Re: what does - mean?

2008-12-29 Thread Timothy Pratley
On Dec 30, 2:49 pm, wubbie sunj...@gmail.com wrote: Very criptic for newbie. What  does Threads the expr through the forms. mean? Shameless plug, if you find learning from examples easier than textual descriptions, you might want to look up

Re: Kawa Scheme on Android

2008-12-29 Thread walterc
thanks for sharing. looking forward to the day when i can write my android app in clojure! On Dec 30, 12:07 pm, Adam King va3...@gmail.com wrote: Rich Hickey wrote: On Sun, Dec 28, 2008 at 6:05 PM, Randall R Schulz rsch...@sonic.net wrote: Howdy, Folks, The gauntlet has been thrown

Re: Contrib REPL Invocation Changes

2008-12-29 Thread Stephen C. Gilardi
Now I'm dumped back to my shell prompt following a single Clojure REPL prompt (of the Contrib REPL variety) without even touching the keyboard: % clojure-svn --crepl +cp=$PROJ_SRC/tau/run +cp=/dar/clojure 1:1 user= % Here it is working with the current clojure.jar and clojure-contrib.jar: %

Re: Some code review for clj-record?

2008-12-29 Thread John D. Hume
On Mon, Dec 29, 2008 at 7:15 PM, Brian Doyle brianpdo...@gmail.com wrote: I noticed that in the init-model macro you are creating a 'defn table [] ...' function in the model namespace and was wondering why you didn't just make it a def instead, since it doesn't take any args? That didn't

Re: Swank in Tomcat via JSP: classpath issues

2008-12-29 Thread Greg Harman
Thanks, Mike - although we had already looked at the context classloader, your explanation did provide some inspiration for a workaround. The correct classloader should be available in the JSP and so it should be possible to grab it there and pass it into Clojure as a variable (or a binding?) in

Re: Parallel words frequency ranking

2008-12-29 Thread Mark H.
On Dec 28, 7:50 pm, Piotr 'Qertoip' Włodarek qert...@gmail.com wrote: Following my recent adventure with words ranking, here's the parallel version: ... (defn parallel-top-words [in-filepath out-filepath]   (let [string  (slurp in-filepath) 'slurp' just reads the whole file in at once as a

Understanding how to use namespaces

2008-12-29 Thread Mark Engelberg
So up until now, I've mainly been writing my code in a given file, using no namespaces, and then just compiling and executing it in a SLIME-based REPL. I've accumulated a few functions that seem worth making into a little library. So, for example, I've written a few permutation functions. I

Re: In core structure editor, anyone?

2008-12-29 Thread falcon
How's textjure coming along? On Dec 10, 3:35 pm, Chouser chou...@gmail.com wrote: On Wed, Dec 10, 2008 at 7:15 AM, Simon Brooke still...@googlemail.com wrote: I note people seem mainly to be using Emacs as an editing/development environment for Clojure. But as people keep pointing out,