Re: Moving average from Java to Clojure

2014-07-20 Thread Jony Hudson
On Sunday, 20 July 2014 12:48:19 UTC+1, Cecil Westerhof wrote: > or is there a better way? > Probably not the answer you're looking for, but the exponentially-weighted moving average doesn't require any state other than the current value: (defn ewma [alpha] (fn [avg new] (+ (* (- 1 alpha) avg)

Re: Moving average from Java to Clojure

2014-07-20 Thread Mike Fikes
Hey Cecil, In addition to using peek instead of first, as indicated by Plinio, the moving-average function above uses some poor names, in hindsight, especially the "old-queue" parameter name. I'd suggest naming it queue, as it refers to an atom. You could even consider naming the function mov

Re: Moving average from Java to Clojure

2014-07-20 Thread Mike Fikes
There actually is a queue implementation. Here is a way to use it for your problem: (defn make-moving-average-queue [n] (atom {:lengthn :current-total 0.0 :old-values(clojure.lang.PersistentQueue/EMPTY)})) (defn update-moving-average-queue [old-queue next-value]

Re: Moving average from Java to Clojure

2014-07-20 Thread Plínio Balduino
Hi Cecil Clojure has a clojure.lang.PersistentQueue to work with queues. I don't know why it doesn't have a reader macro, but works fine and returns you a Clojure collection you can handle with cons and peek. You can start with an empty queue with clojure.lang.PersistentQueue/EMPTY or insert y

Moving average from Java to Clojure

2014-07-20 Thread Cecil Westerhof
I just wrote a moving average class in Java: https://github.com/CecilWesterhof/JavaExamples/blob/master/MovingAverageQueue.java I was just wondering: what is the best way to translate this to Clojure? At the moment Clojure does not have a queue. Should I just use the Java calls, or is there a be

Re: Aw: Re: How to convert a VTK example from java to clojure?

2013-04-26 Thread Aaron Cohen
You no longer need any of this. All you should need is to use (clojure.lang.RT/loadLibrary "vtk") That will ensure that the native libs end up in the correct classloader. On Fri, Apr 26, 2013 at 3:46 AM, Nils Blum-Oeste wrote: > Great, thanks a lot. Fixed the issues I had. > However I wonder wh

Re: Aw: Re: How to convert a VTK example from java to clojure?

2013-04-26 Thread Nils Blum-Oeste
Great, thanks a lot. Fixed the issues I had. However I wonder where 'wall-hack-method' lives now, as clojure-contrib has been split. This (old) thread suggests it has also been renamed to call-method https://groups.google.com/forum/?fromgroups=#!topic/clojure-dev/tKzqnJWpz-k So is this still inc

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-28 Thread Timothy Washington
Very interesting. Thanks for the insight. Tim Washington Interruptsoftware.ca 416.843.9060 On Sat, Jul 28, 2012 at 6:40 AM, nicolas.o...@gmail.com < nicolas.o...@gmail.com> wrote: > > There is indeed an infinite number of functions, or relationships between > > natural numbers. I don't think

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-28 Thread nicolas.o...@gmail.com
> There is indeed an infinite number of functions, or relationships between > natural numbers. I don't think that means that that any one of those > relationships is not computable because it is within the range of infinite > functions. The countable parts of a program can still accept an infinite

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-27 Thread Timothy Washington
Hey Nicolas, Thanks for the feedback and corrections. I was trying to hone in on OO and Lisp's model of what it means to compute. While this just served as a backdrop for the conceptual and code differences between Bkeeping's Java and Clojure versions, I can see a much deeper analysis happening he

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-27 Thread nicolas.o...@gmail.com
Hi, Great notes. I like a lot. A few (mostly technical) comments: > Concept of Computation > > What does it mean to compute? Turns out this is a complicated question. From > what I can tell, to compute is an actualization (or concrete version) of a > mathematical function. We are swimming in a

Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-27 Thread Timothy Washington
Hi all, I recently gave a talk at a Toronto Dev Shop, The Jonah Group. It just detailed my experiences, transitioning a Java app to a Clojure app, and the benefits that accrued to me. I thought it would be nice to share with the Clojure community. Below is an approximate

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
Aaron Cohen, thank you! It works !!! -- 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

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Aaron Cohen
On Tue, Jun 21, 2011 at 8:00 PM, Antonio Recio wrote: > I have tried to use wall-hack-method but I still obtain the > error: UnsatisfiedLinkError vtk.vtkConeSource.VTKInit()J >  vtk.vtkConeSource.VTKInit (vtkConeSource.java:-2). What I am doing wrong? > (ns project.core >   (:import (javax.swing J

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
I have tried to use wall-hack-method but I still obtain the error: UnsatisfiedLinkError vtk.vtkConeSource.VTKInit()J vtk.vtkConeSource.VTKInit (vtkConeSource.java:-2). What I am doing wrong? (ns project.core (:import (javax.swing JButton JFrame JPanel) (vtk vtkConeSource vtkPolyDat

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Aaron Cohen
OK, I've gotten it working on my computer, and it turns out to be a slightly complicated problem. What is happening is that the vtk java files and your clojure code are using different classloaders (clojure uses its own classloader). System/loadLibrary is kind of crippled in that it always loads

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
All the vtk libraries that I need are in /usr/local/lib/vtk-5.9/ and are executable. Java and c++ examples work fine. -- 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 n

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Aaron Cohen
On Tue, Jun 21, 2011 at 12:38 PM, Antonio Recio wrote: > java -Djava.library.path=/usr/local/lib/vtk-5.9/ This is the directory that contains: libvtkCommonJava.so, libvtkFilteringJava.so, libvtkIOJava.so, libvtkImagingJava.so, libvtkGraphicsJava.so, and libvtkRenderingJava.so ? They all are exec

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
java -Djava.library.path=/usr/local/lib/vtk-5.9/ -cp /usr/share/java/clojure.jar:/usr/local/lib/vtk-5.9/java/vtk.jar clojure.main main.clj Exception in thread "main" java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: vtk.vtkConeSource.VTKInit()J at clojure.lang.Util.runtimeExce

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Aaron Cohen
Your LD_LIBRARY_PATH is quite extensive there, is that all required or is this just a bunch of stuff you've been trying? I usually just use -Djava.library.path=. On linux you also may have to be sure that your shared libraries are +x for your user. --Aaron On Tue, Jun 21, 2011 at 12:17 PM, Anton

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
Aaron, thanks. You are right I had forgotten the vtk.jar, but I still obtain errors: *My /usr/local/bin/clojure:* #!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-6-sun/ export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/amd64/:/usr/local/lib/:/usr/local/lib/vtk-5.9/:/usr/local/lib/cma

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Aaron Cohen
It appears that you need to have the VTK *.class or *.jar files on you classpath as well. Add the path to your VTK java files to the "cp" parameter you are invoking clojure with. On Tue, Jun 21, 2011 at 11:26 AM, Antonio Recio wrote: > I have tried also this: > > $ java -Djava.library.path=/usr/

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
I have tried also this: $ java -Djava.library.path=/usr/local/lib/vtk-5.9/ -Djava.ext.dirs=/usr/share/java -cp clojure.jar:src clojure.main main.clj Exception in thread "main" java.lang.ClassNotFoundException: vtk.vtkConeSource (main.clj:1) at clojure.lang.Compiler.eval(Compiler.java:54

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
I have tried with ... but I get the same error: (System/setProperty "java.library.path" "/usr/local/lib/vtk-5.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

Re: Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
I have added the static libraries in the clojure file: (ns project.core (:import (javax.swing JButton JFrame JPanel) (vtk vtkConeSource vtkPolyDataMapper vtkRenderWindow vtkRenderWindowInteractor vtkCamera vtkActor vtkRenderer vtkInteractorStyleTrackbal

Aw: Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Meikel Brandmeyer
Hi, you are missing the static part from the Java source. Add the (System/loadLibrary "vtkCommonJava") etc. between the ns clause and the definition of main. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, s

Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
*After the corrections I have this: * (ns project.core (:import (vtk vtkConeSource vtkPolyDataMapper vtkRenderWindow vtkRenderWindowInteractor vtkCamera vtkActor vtkRenderer vtkInteractorStyleTrackballCamera))) (defn main [] (let [cone (doto (vtkConeSource.)

Re: How to convert a VTK example from java to clojure?

2011-06-21 Thread Tassilo Horn
Antonio Recio writes: Hi Antonio, > My modified version in clojure with errors:* The errors would be interesting as well. But I found at least two obvious glitches. > (defn main [] > (let [cone (doto (vtkConeSource.) >(.SetHeight 3.0) >(.SetRadius 1.0) >

How to convert a VTK example from java to clojure?

2011-06-21 Thread Antonio Recio
I have tried to convert the example Cone5.java from VTK to clojure. I have write this ... but it doesn't work. Do you have any suggestion? *The original java:* import vtk.*; public class Cone5 { static { System.loadLibrary("vtkCommonJava"); System.loadLibrary("vtkFilteringJava");

Re: Passing Arguments From Java to Clojure

2010-06-16 Thread rzeze...@gmail.com
-- CallClojure.java -- import clojure.lang.RT; import clojure.lang.Var; import clojure.lang.PersistentVector; public class CallClojure { static PersistentVector toVec(int[][] arr) { PersistentVector pv = PersistentVector.EMPTY; for (int[] a : arr) { Persist

Re: Passing Arguments From Java to Clojure

2010-06-16 Thread Stuart Halloway
Do you really need a Clojure vector-of-vectors, or do you just want an indexed collection of indexed collections? If the latter, you can simply use Java arrays, or ArrayMaps. ; build a collection a Java programmer might have made ; (I am not really going to go into Java just for an example... :

Re: Passing Arguments From Java to Clojure

2010-06-16 Thread Daniel
Actually, just look at the main method (for testing) which has been commented out at the bottom - that will show you a better way to create and use it. On Jun 16, 9:37 am, allie wrote: > There's a canonical intro on how to call or embed Clojure into > Java:http://en.wikibooks.org/wiki/Clojure_Pr

Re: Passing Arguments From Java to Clojure

2010-06-16 Thread Daniel
You need to pass in a PersistentVector of PersistentVector's. It's in clojure.lang and there are a number of static creation methods. On Jun 16, 9:37 am, allie wrote: > There's a canonical intro on how to call or embed Clojure into > Java:http://en.wikibooks.org/wiki/Clojure_Programming/Tutoria

Passing Arguments From Java to Clojure

2010-06-16 Thread allie
There's a canonical intro on how to call or embed Clojure into Java: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java While this is a great introduction, the only thing Java passes in to Clojure here is a string. I've tried methods where Java passes in

Re: From Java to Clojure

2009-07-11 Thread Patrik Fredriksson
On Fri, Jul 10, 2009 at 3:04 PM, Benjamin Stewart wrote [...] > (defn count-hash-vals [coll] > ;; apply hash-map mapcat was the first thing > ;; I found that worked here... better options ++welcome. >               (apply hash-map >                      (mapcat #(let [[k v] %] >                

Re: From Java to Clojure

2009-07-11 Thread Patrik Fredriksson
Sean Devlin wrote: > If you're running "edge" Clojure, and not 1.0, I'd recommend writing > the tests in Clojure next, using the clojure.test namespace. I'd like to keep it 1.0 for now, so the tests are in clojure.contrib.test-is. But I'll make note, or add an alternative version for clojure.test.

Re: From Java to Clojure

2009-07-10 Thread Sean Devlin
To quote Benjamin Stewart: ;; the body of this fn should probably be a macro that takes ;; any number of comparisons and or-chain them correctly such that ;; ties cascade to the next comparison and obviates the need for ;; explicit calls to false-if-zero. Does it already exist? This could be do

Re: From Java to Clojure

2009-07-10 Thread Benjamin Stewart
I've been playing along at home for awhile now, but this example hit close to home -- I've written variations on this code countless times in perl, and figured I'd take a stab at clojuring it while also taking advantage of clojure.contrib.seq-utils's very useful to the matter at hand group-by. I'

Re: From Java to Clojure

2009-07-09 Thread Chouser
On Thu, Jul 9, 2009 at 7:31 AM, Patrik Fredriksson wrote: > > My shot at a Clojure implementation, with inspiration from a previous > post in this group on a similar problem: > > (ns step3.pnehm.clojure-orderer >  (:gen-class >    :name step3.pnehm.ClojureOrderer >    :implements [pnehm.Orderer] >

Re: From Java to Clojure

2009-07-09 Thread Sean Devlin
Okay, since you DO call the Clojure code from Java, I like what you did very much. If you're running "edge" Clojure, and not 1.0, I'd recommend writing the tests in Clojure next, using the clojure.test namespace. Sean On Jul 9, 10:16 am, Patrik Fredriksson wrote: > The idea is to gradually, ov

Re: From Java to Clojure

2009-07-09 Thread Patrik Fredriksson
The idea is to gradually, over a few steps, move from a Java implementation to a pure Clojure implementation. A this step the Clojure implementation is called by the Java JUnit-test (see complete test below). In the last step, the Java-references will be removed from the Clojure implementation and

Re: From Java to Clojure

2009-07-09 Thread Sean Devlin
One question on design intent before feedback. Is your intent to have this Clojure code called by Java code later? On Jul 9, 7:31 am, Patrik Fredriksson wrote: > Hi! > > I started to look closer at Clojure after Rich Hickey's presentation > at QCon London in March, this is my first post. I spe

From Java to Clojure

2009-07-09 Thread Patrik Fredriksson
Hi! I started to look closer at Clojure after Rich Hickey's presentation at QCon London in March, this is my first post. I spend my days programming Java, but my journey as developer did actually start with an ML programming course many years ago. It has been great fun to re-discover the function

Re: Transitioning from Java to Clojure

2008-10-09 Thread Ande Turner
81842/transitioning-from-java-to-clojure Ande On Oct 9, 11:07 am, MikeM <[EMAIL PROTECTED]> wrote: > > What project types lend themselves to using Java over Clojure, vice > > versa, or in combination? > > A project where a GUI-building tool (such as Matisse in Netbeans) is &

Re: Transitioning from Java to Clojure

2008-10-08 Thread MikeM
> What project types lend themselves to using Java over Clojure, vice > versa, or in combination? > A project where a GUI-building tool (such as Matisse in Netbeans) is needed would be a case where Java may still be required. Anything done in Java can be done in Clojure quite readily, with proxy

Transitioning from Java to Clojure

2008-10-08 Thread Ande Turner
After discovering Clojure I have spent the last few days immersed in it. This question is directed at prominently at Java programmers who have transitioned to Clojure: What project types lend themselves to using Java over Clojure, vice versa, or in combination? Which programs which you would hav