How To Make Code More Functional?

2008-12-26 Thread aria42
Hi all, I'm just getting started with clojure from a functional background, and while I like playing with clojure and accomplishing script like tasks, I have no experience with anything larger than about 20 lines. I wanted to try to take something with alot of state and put it into clojure. I

Re: How To Make Code More Functional?

2008-12-26 Thread aria42
Clojure for Tajan's Algorithm uploaded here http://clojure.googlegroups.com/web/tarjan.clj?gsc=yOHJ-CEAAAB3Fq8nFW3O6gqQkWXH_xrOYRvSPFZyhAT412614U6EGkzfKN-m9S9niuHrq-IEXAE - aria On Dec 26, 6:30 am, aria42 ari...@gmail.com wrote: Hi all,   I'm just getting started with clojure from a

Re: Exercise: words frequency ranking

2008-12-26 Thread lpetit
Instead of #(- (val %)), one could also use the compose function : (comp - val) My 0,02 EURO, -- Laurent On Dec 25, 4:58 pm, Mibu mibu.cloj...@gmail.com wrote: My version: (defn top-words [input-filename result-filename] (spit result-filename (apply str (map

Re: Exercise: words frequency ranking

2008-12-26 Thread lpetit
What would you think of this form of coding ? - The rationale is to separate functions that deal with system boundaries from core algorithmic functions. So you should at least have two functions : one that does not deal with input/output formats : will only deal with clojure/java constructs. -

Re: Exercise: words frequency ranking

2008-12-26 Thread Piotr 'Qertoip' Włodarek
On Dec 25, 4:58 pm, Mibu mibu.cloj...@gmail.com wrote: My version: (defn top-words [input-filename result-filename]   (spit result-filename         (apply str                (map #(format %s : %d\n (first %) (second %))                     (sort-by #(-(val %))                              

sync vs. dosync

2008-12-26 Thread Mark Volkmann
What is the difference between the sync and dosync functions? Their documentation strings are identical. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To

println output

2008-12-26 Thread Mark Volkmann
Why does (for [x (range 3)] (println x)) output (0 nil 1 nil 2 nil) when run in the REPL instead of 0 1 2 and nothing at all when run from a script? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are

Re: sync vs. dosync

2008-12-26 Thread Michael Wood
On Fri, Dec 26, 2008 at 9:44 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: What is the difference between the sync and dosync functions? Their documentation strings are identical. sync has an extra flags argument. At the moment they are the same, but presumably sync will do different

Re: println output

2008-12-26 Thread mehrheit
On Fri, 26 Dec 2008 14:43:23 -0600 Mark Volkmann r.mark.volkm...@gmail.com wrote: Why does (for [x (range 3)] (println x)) output (0 nil 1 nil 2 nil) when run in the REPL instead of 0 1 2 and nothing at all when run from a script? The seq of nils is the return value of `(for ...)'. It

Re: println output

2008-12-26 Thread Michael Wood
On Fri, Dec 26, 2008 at 10:43 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Why does (for [x (range 3)] (println x)) output (0 nil 1 nil 2 nil) when run in the REPL instead of 0 1 2 This is because println returns nil every time it's run. user= (println test) test nil

Accessing this in gen-class constructor

2008-12-26 Thread CuppoJava
Hi, I've hit a stumbling block using Clojure's gen-class facility for constructors. Is there anyway to access this inside Clojure's constructor/init function? ie. The following type of code is quite common in Java. How would you do the same in Clojure? public class MyDerivedClass extends

Re: Proxying in clojure

2008-12-26 Thread Abhishek Reddy
Works for me from SLIME. Check your *inferior-lisp* buffer for exceptions. On 12/27/08, MattyDub mattydu...@gmail.com wrote: This might be off-topic, but when I launched snake from SLIME (via load-file and then run-snake), the app didn't receive any UI Events. I thought at first it might

macro help

2008-12-26 Thread what-a-guy
I'm attempting what should be a simple transformation using a macro called dlg in the following code: (defn fld [parent lay id text field] '...) ;; dlg macro. For this input: ;; ;; (dlg test ;; (field fld-1 Field number one (JTextField.)) ;; (field fld-2 Field number two (JTextField.))) ;;

Re: Random Number Generation Issues

2008-12-26 Thread Mark H.
On Dec 23, 3:10 pm, Jason jawo...@berkeley.edu wrote: For the time-being, you could try something like: user (def *random* (java.util.Random.)) #'user/*random* user (defn my-rand-int [max-val]         (let [bit-length (.bitLength (BigInteger. (str max-val)))]           (loop []          

Re: How to encapsulate local state in closures

2008-12-26 Thread Adrian Cuthbertson
On Dec 22, 2:34 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Mon, Dec 22, 2008 at 4:23 AM, Parth Malwankar parth.malwan...@gmail.com wrote: If I get it right, atoms are quite useful to maintain state in the context of a single thread with memoization and counter (within a

Re: How to encapsulate local state in closures

2008-12-26 Thread Mark Engelberg
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 has to ensure the update function can be retried without ill-effects. However,

Re: Accessing this in gen-class constructor

2008-12-26 Thread CuppoJava
I found that I can use another factory method to workaround this limitation. I can first instantialize the object to get a reference, and then initialize all it's settings. This works only if I don't expect this class to be derived from. Any subclass would expect the class to be fully initialized

sorted-map-by value

2008-12-26 Thread Mibu
Is there a way to sort a sorted-map-by by value without a letrec? --~--~-~--~~~---~--~~ 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 To unsubscribe from this