Re: Why I have chosen not to employ clojure

2010-03-26 Thread prhlava

Hello Ronan,

> By the way, if someone has an idea about a sample application (simple,
> but not trivial) which could lead the tutorial, and show different
> aspects of the language, let me know !
> I was thinking about a more complete and idiomatic version of Vincent
> Foley's "Fetching web comics" tutorial, but something more
> "enterprisey" seems more adequate.

I have a slightly more - a full application, it is a tool which I
wrote to save someone around one hour per week of doing "monkey
work" (nothing against monkeys, I just do not like when people waste
their time on what computer can do for them, so I "wasted" some of
mine on learning clojure better while doing something useful).

The input is an excel spreadsheet, this spread-sheet is read (using
libraries developed at apache project), checked whether it is
"valid" (i.e. user opened the right kind), parsed (nothing too
complicated), filtered (what the user needed was a subset according to
few rules), and written to a new file in which the data split in 3
pages - all (for checking), not-interesting (what user does not want)
and interesting (the stuff the user needs to make informed jugement).
The result is, that instead of manually checking 100s spread-sheet
"records" (the input spread-sheet was output from a database, btw),
one only needs to check few.

The app also reports reasonable errors and possibly exceptions (which
can be cut-and-pasted - they do not pop up as dialog boxes), so this
could be fed back to the programmer (me) to get a clue where the
problem is.

The program is not too long, reasonably structured (I wrote it twice,
the first version with focus to make it work and learn, the second to
like the code and the result), I could add more comments (to the code)
as it was not too long ago that I wrote it.

Also, I am pretty sure, someone with higher mastery of clojure-fu
could improve it (my main motivation here is
for other people not to pick up possibly bad beginners (mine) habits
if there are some in there).

Please e-mail me privately if interested.

Kind regards,

Vladimir

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: database management: curing lock issues

2010-03-25 Thread prhlava
> Is it as simple as moving to a better database, such as
> mySQL?

PostgreSQL is considerably better (even than MySQL, which still uses
locks AFAIK)
for anything concurrent. The PostgreSQL is using multiple version
concurrency (MVC)
approach - the same approach the clojure STM is using.

The PostgreSQL might need a bit of tuning (the defaults are very
conservative),
but after that it usually performs very well. Make sure that you
understand the
PostgreSQL transactions and how they work, but usually - in default
settings, the
readers do not block writers, and readers always see consistent view
of the data
(but this view could be a "bit behind" in terms of time).

The PostgreSQL mailing list is both, friendly and knowledgeable -
speaking from
experience.

Kind regards,

Vladimir

-- 
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 from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


feedback on (shortish) code wanted - parallel factorial examples

2009-12-03 Thread prhlava
Hello,

I would like to extend the examples section on clojure wiki with 
parallel factorial example codes (one version is sligtly simpler, one 
performs better).

Your feedback on the code is more than welcome, as I still consider 
myself beginner on clojure (but coming up with the algorithm + 
implementing it in clojure was a good exercise).

Both versions should be attached to this message (i did not include
them directly in e-mail as formatting gets usually messed up).

Kind regards,

Vladimir

-- 
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; parallel version of factorial

; no any guarantees for this code - it is a toy implementation and
; could be incorrect

; idea is to apply * in parallel to a set of ranges
; (each of which represent the number n)

; n - calculate factorial of this number
; m - number of digits of n (used to partition the number)
; z - the whole part of n/m

; partitions number n which is long m decimal digits into ranges
; fixme: the m should be calculated from n but this way one can decide
;on the number of partitions by hand
; also, the partitioning is not optimal (large number take longer to multiply)
(defn part-num [n m]
  (let [z (quot n m)
last-range (range (+ (* z m) 1) (+ n 1))
]
(cons (if last-range last-range '(1))
  (for [x (range m)]
(range (+ (* x z) 1) (+ (* (+ x 1) z) 1))
)
  )
)
  )

; the same argumets as part-num
; e.g. call (pfactorial 10 6); takes around 5 seconds on core 2 duo
(defn pfactorial [n m]
  (let [agents (map agent (part-num n m))]
(doseq [a agents]
  (send a #(apply * %)))
(apply await agents)
(let [result (apply * (map deref agents))]
  (doseq [a agents]
(send a (fn [_] nil)))
  result)
)
  )
; parallel factorial - version 2

; this 2nd version multiplies the intermediate results also in parallel

; fixed to also work with clojure 1.1.0-alpha

; no any guarantees for this code - it is a toy implementation and
; could be incorrect

; idea is to apply * in parallel to a set of ranges
; (which represent the number n),
; after this, a set of agents is set up to multiply 2 intermediate results each

; n - calculate factorial of this number
; m - how many intervals the number n should be partitioned into
; z - the whole part of n/m

; partitions number n which to m ranges
; fixme: the m should be calculated from n but this way one can decide
;on the number of partitions by hand
; also, the partitioning is not optimal (large number take longer to multiply)
(defn part-num [n m]
  (let [z (quot n m)
last-range (range (+ (* z m) 1) (+ n 1))
]
(cons (if (= last-range '()) '(1) last-range)
  (for [x (range m)]
(range (+ (* x z) 1) (+ (* (+ x 1) z) 1))
)
  )
)
  )

; the same argumets as part-num
; e.g. call (pfactorial 100 500)
; for benchmarking: (time (def x (pfactorial 100 500)))
; the above takes around 315 seconds on core 2 duo, 2.66GHz, 64 bit linux
(defn pfactorial [n m]
  (let [agents (map agent (part-num n m))] ; create agents containing ranges
(doseq [a agents]
  (send a #(apply * %))) ; make each agent multiply numbers of it's range
(apply await agents) ; wait until all agents finish

; do multiplication of intermediate results in parallel
(loop [lon (map deref agents)] ; lon - list of numbers
;  (println (count lon))
  (if (= (count lon) 1) ; do we have a result?
(first lon)
(let [ags (map agent (partition 2 lon))] ; multiply 2 numbers in agent
  (doseq [a ags]
(send a #(apply * %)))
  (apply await ags)
  (if (= (mod (count lon) 2) 0) ; even number of numbers in lon?
(recur (map deref ags))
(recur (cons (last lon) (map deref ags)))
)
  )
)
  )
)
  )


Re: roll call of production use?

2009-11-30 Thread prhlava

Hello,

> i'd be interested to hear who has successfully used clojure in
> production. i know of some, as some folks have been vocal; any other
> interesting-but-so-far-silent uses people'd be willing to fess up
> about?

I have done a smallish project (mainly to stop my friend doing some
monkey
work) - it basically opened an ms excel spreadsheet (using library
developed
by apache project folk), validated input, categorised groups of rows
by needed criteria and
wrote the results to a new spread-sheet (formated), with interesting
results on separate page
(these were done by hand before).

In the proces, I have re-written the application once (as I learnt
more over time +
switched to apache library for excel files) and was very pleased with
the result (the code) -
both, performance and "beauty".

Kind regards,

Vladimir

-- 
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


uploading file(s) to the "Files" section of this group

2009-11-30 Thread prhlava

Hello,

What is the correct way these days to upload a file to the "Files"
section of the Clojure google group?

I checked the info on the group, it looks that only "managers" can
upload files, but how do I do this (i.e.
who do I send the files to)?

The files in question are small bugfixes to the parallel-factorial*
code (there are 2 versions) which I would like to submit.

Kind regards,

Vladimir

-- 
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: "arithmetic" change between 1.0.0 and 1.1. 0

2009-11-30 Thread prhlava

Hello Steve,

> As an alternative to the code you posted, for positive integers n and m,
>         (int (Math/floor (/ n m))
> is equivalent to
>         (quot n m)
> If negative values are possible, you could write a function based on quot 
> that would give the appropriate answer in all cases.

Thank you, this makes sense + makes the code simpler :-)  (as negative
values would be "wrong" in this particular case).

Kind regards,

Vlado

-- 
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


(range 1.0 10.0) versus (range 1 10) in clojure versions 1.0.0-snapshot 1.1.0-alpha

2009-11-16 Thread prhlava

Hello,

( this is related to 
http://groups.google.com/group/clojure/browse_thread/thread/d894a933dcb5d0f6
)

In Clojure 1.0.0-snapshot, the

(range 1.0 10.0) ; 1)
(range 1 10)   ; 2)

both yield integer numbers in result.

In clojure 1.1.0-alpha-snapshot (recent), the 1) yield floats and 2)
integers.

Is this intentional? (I searched assembla dev site and did not find
anything)

(also, please do not take this as a rant, I am just curious)

Kind regards,

Vladimir

-- 
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


"arithmetic" change between 1.0.0 and 1.1. 0

2009-11-16 Thread prhlava

Hello,

I was testing if my code works with Clojure 1.1.0-alpha-SNAPSHOT - the
full code is attached to this group (in files section) as parallel-
factorial*.clj .

The code works in 1.0.0, but blows up in 1.1.0 for bigger numbers.
After a bit of digging, I found that following function is the culprit
(working version shown):

;--
(defn part-num [#^Integer n #^Integer m]
  (let [z (int (Math/floor (/ n m))) ; it generates float ranges
without the cast to int
last-range (range (+ (* z m) 1) (+ n 1))
]
(println z)
(println last-range)
(cons (if last-range last-range '(1))
  (for [x (range m)]
(range (+ (* x z) 1) (+ (* (+ x 1) z) 1))
)
  )
)
  )
;--

The problem is that without casting "z" to integer, the generated list
of ranges will have float numbers (and not integers), and that will
over-flow to infinity for large numbers when used in pfactorial
function.

No big deal, the fix is simple - this is heads up if more people find
their code broke with over-flow to infinity with the new version of
clojure.

It looks that float type "propagates" into arithmetics (and it did not
before) - better explanation welcome.

Kind regards,

Vladimir

-- 
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 write performant functions in clojure (and other functional languages)

2009-07-26 Thread prhlava


Hello,

> I wonder if any of the Clojurians on here might like to describe how
> one might write the factorial function as a parallel one?



Look at the files section of this group, I wrote 2 examples of
parallel factorial and the sources are uploaded there...



Kind regards,

Vlad
--~--~-~--~~~---~--~~
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: breaking early from a "tight loop"

2009-06-13 Thread prhlava


Hello James,

Thank you for more examples.

> > (count (take-while belowCount (filter identity (map isInteresting
> > pixels
> This particular piece of code doesn't look like it would work, unless
> I've misunderstood what Vlad is asking. I think you'd want something
> more like:

If I understood the Patrick's code right, it works as:

1. The (map isInteresting ...) returns lazy sequence of true/false
values for each pixel (true for interesting pixel)
2. The (filter identity ...) returns a lazy sequence of only true
values from the above
3. The (take-while belowCount ...) will return items of lazy sequence
while the predicate "belowCount"
 holds. This implies that the predicate would have to be stateful
(i.e. increment a counter
 on each invocation and return false when this counter == count-I-
am-interested-in . So the
 take-while "stops" once the count is reached
4. the result of (count ...) would be compared with count-I-am-
interested-in and if ==, the image is
"interesting"

>   (defn interesting? [pixels c]
> (>= c (count (take c (filter in-interval? pixels)
>
> Where c is the number past which an image is considered "interesting".
> However, if c is very large, then (take c ...) is going to result in a
> large sequence.

The large sequence should not be a problem for this particular
application.

> We'd probably want to define a function:
>
>   (defn count-more-than? [n xs]
> (or (zero? n)
> (if (seq xs)
>   (recur (dec n) (rest xs)
>
>   (defn interesting? [pixels c]
> (count-more-than? c (filter in-interval? pixels)))

Cheers, I will try to code different variants, see how fast they are,
+ report back at some point with the findings.

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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: breaking early from a "tight loop"

2009-06-12 Thread prhlava



Hello Patrick,

> I would approach it like this, and make full use of Clojure's lazy
> sequences:
>
> (count (take-while belowCount (filter identity (map isInteresting
> pixels

Interesting approach - I have not thought of this. Also, it looks that
I can get an array of pixels (as ints) from BufferedImage so it should
be fast.

Thank you for the pointer.

Kind regards,

Vlad

PS: Other option occured to me later - using loop/recur, but I like
the above...
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



breaking early from a "tight loop"

2009-06-12 Thread prhlava


Hello,

I am writing a (crude) image classification which basically counts
pixels within a specific RGB interval and if the count is over certain
number, the image is considered
"interesting". (the app runs on a grid BTW)

The point is that once the count is reached, there is no point
processing the rest of the pixels (which saves time).

So the question is, how do I "break early" from sequence (or loop)
processing?

Only option I found so far, would be using the "while" macro - any
other (clojure) options?

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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, GridGain and serialization error

2009-06-09 Thread prhlava

> I am playing with GridGain http://www.gridgain.com from Clojure and I
> am getting
> exception related to serialization.

Never mind, I tool a wrong approach at first. Now I have it running,
apologies for the noise...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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, GridGain and serialization error

2009-06-09 Thread prhlava


Hello,

I am playing with GridGain http://www.gridgain.com from Clojure and I
am getting
exception related to serialization.

>>> Type: org.gridgain.grid.GridException
>>> Message: Failed to deserialize object with given class loader: 
>>> clojure.lang.dynamicclassloa...@667cbde6

(the full stack trace is very long)

The method declaration (of GridJobAdapter class) in Java is along the
lines:

public Serializable execute() {  return result}

I tried to declare the execute() method as:

(#^Serializable execute []) in the GridJobAdapter proxy but it made no
difference.

Did anyone used GridGain with clojure successfully? Any hint on what
to try/do next welcome, as at the moment I am stuck...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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: What books have helped you wrap your brain around FP and Clojure?

2009-06-06 Thread prhlava

> Going beyond the language-specific Programming Clojure book, what
> other books have best helped you make the (sometimes mind-bending)

I have not yet read anything more mind-bending than this:

http://www.gp-field-guide.org.uk/

(A field guide to genetic programming)

It is free download - the book is under Creative Commons license...

A clojure example of the above is at:

http://npcontemplation.blogspot.com/2009/01/clojure-genetic-mona-lisa-problem-in.html

(but the code did not work in the latest clojure for me)

Kind regards,

Vlad

PS: Apart from being a fascinating subject - the book made the "code
is data" idea obvious...
--~--~-~--~~~---~--~~
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: improoved version of parallel factorial uploaded - is it possible to push the performance further?

2009-06-06 Thread prhlava


Oops - the link above is broken, but the code is in the files section,
called:

parallel-factorial-example-2.clj

Vlad
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



improoved version of parallel factorial uploaded - is it possible to push the performance further?

2009-06-06 Thread prhlava


Hello,

Just uploaded better version of parallel factorial...

Is is possible to push the performance further (short of implementing
parallel multiplication algorithm)?

Comments welcome.

http://groups.google.com/group/clojure/files/parallel-factorial-example-2.clj

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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: off topic - sending and receiving raw Ethernet frames from clojure/java

2009-05-24 Thread prhlava


Hello Mark,

> Can't be done using the standard Java library.  You'll have to write
> some JNI code or find a JNI library.

Thanks for the confirmation, after long search and asking around, the
conclusion was the same - not possible without JNI or using jpcap...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



off topic - sending and receiving raw Ethernet frames from clojure/java

2009-05-20 Thread prhlava


Hello,

Apologies for off topic post.

I would like to send and receive raw ethernet frames from Clojure.

So far, I found:

http://netresearch.ics.uci.edu/kfujii/jpcap/doc/

but is sending and receiving raw ethernet packets possible with the
latest JDK using standard networking stack of JVM?

Info I found is contradictory and most of it is old.

The target platform this should work on are Linux, MacOS, and Windows.
My development platform is Linux.

Kind regards,

Vlad

PS: I am not after UDP or any TCP/IP related stuff but trying to send/
receive ethernet stuff directly.
--~--~-~--~~~---~--~~
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 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 do you "boot-strap" clojure from java?

2009-04-26 Thread prhlava



Hello Christophe,

Thank you.

> clojure.lang.RT.load("my/script.clj") ; your script must be on the classpath
> clojure.lang.RT.var("my.ns", "my-var").invoke("hello") ; to call a function

This is good (so I should read more then main.clj source code nex
time ;-) ).

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Google announcement, version 1.0 & SCM Holy War (not really)

2009-04-26 Thread prhlava


Hello Dan,

> Which version did you try? msysgit works very well.

Pity that VM I used is now no-existent, but as I said it was a while
ago. Maybe msysgit improoved since.

The reasons I had for choosing mercurial were:

1. The hg code base is simpler and smaller that git's
2. It is more easily portable (but this is debatable, if there is a
platform without python)
3. Performs well enough for what I need (simple stuff)
4. Good integration in netbeans
5. If it is good enough for Open Solaris, OpenJDK and Xen, it is good
enough for me ;-)

But I have nothing against git. Personally, I use mainly linux so
either would work well for me.

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 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 do you "boot-strap" clojure from java?

2009-04-26 Thread prhlava



Hello James,

> Are you aware you can compile Clojure code directly into Java class
> files?

Yes, this was my 1st method of distributing clojure apps (in a .jar).
It works.

But what would be really cool, if I could distribute clojure code in
the source form, load it into a java appliation _and_ call the clojure
code (which got compiled on the fly when loaded) from java. But maybe
the nature of
the java language does not permit this.

OTOH, possibly extending the build process in netbeans with
automatically compiling the .clj files to .class files would be
another way...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: possibly interesting ui 'framework'

2009-04-25 Thread prhlava


Hello Pinocchio,

> So, I looked at it... it doesn't seem to be a UI framework as in a
> framework for creating UIs. Its more to do with an programming editor
> which helps write logically convolved code better (actually a great
> talk...).

I look at is as a "transactional change propagation" framework and
to some extent, it is automatically parallel.

It is also a different model of computation (if I understood
correctly) by using trees.

The talk was definitely worth reading...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



How do you "boot-strap" clojure from java?

2009-04-25 Thread prhlava


Hello,

Currently, I do the following (the clojure application is called
"isi"):

1. set-up a java netbeans project (called isi) with main class
2. add the clojure.jar (and other libraries) to the project
3. in the main class:

package isi;

/**
 * loads the clojure script
 */
public class Main {
public static final String[] script =  {"@/app/isi.clj"};

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws java.lang.Exception
{
clojure.main.main(script);
}

}

The isi.clj (the clojure application) lives in "java" package called
"app" (under src directory).

When the project is run, the main class loads the isi.clj script. This
also works when project .jar is build and works as expected (and the
isi.clj clojure script gets stored in the source form).

What do you do?

Kind regards,

Vlad

PS: Not that there is a problem (so far) with the above approach, but
I would like to know what other possibilities exist...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Google announcement, version 1.0 & SCM Holy War (not really)

2009-04-25 Thread prhlava


> Git even works relatively well on Windows (I've used it lightly and not 
> encountered a bug yet).

The last time I tried, it did not (few months back) compared to
mercurial.

Personally I prefer mercurial to git, but did not use either for too
advanced stuff yet...

Kind regards,

Vlad

--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: [solved] java.lang.String cannot be cast to [Ljava.lang.CharSequence;

2009-04-16 Thread prhlava


Hello Paul,

> Are you trying to give it a string, or an array of strings?
> Maybe it will work with (into-array ["string"])?

Thank you, this was spot on, the correct call looks like:

(. query (sendKeys (into-array ["my-string"])))

Cheers!

Vlad

PS: Embarassingly, the hint is also in the FAQ...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



java.lang.String cannot be cast to [Ljava.lang.CharSequence;

2009-04-16 Thread prhlava


Hello,

I am trying to use a java library ( http://code.google.com/p/webdriver/
), the method I need to call has signature:

sendKeys(java.lang.CharSequence... keysToSend)

If I give it a clojure string, the "cannot be cast" message appears in
the stack trace.

I have tried explicit (cast java.lang.CharSequence "my-string") but
the cast does only "compare" AFAIK.

Is there a way to give the library what it wants from Clojure?

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Is it possible to use clojure to build NetBeans rich client application?

2009-02-19 Thread prhlava


Hello,

I am thinking of using NetBeans RCP and clojure to build an
application. The clojure would be used for as much application logic
as possible...

Has anyone else attemted this? How would I go about it?

I know that it is possible with e.g. groovy, but with clojure?

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: building a class or jar file from clojure

2009-02-09 Thread prhlava



Hello hank,

> How does one make a standard clojure based class file or jar file without
> embedding clojure source files.

Shameful plug:

http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Distributing_application_as_self_contained_.jar

(the above URL should be 1 line..., it looks that google breaks it)

It is very basic but it should get you started...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-05 Thread prhlava

> 2) The current directory (parent of gui2) is in the class-path -cp
> option when launching Clojure

Updated the guide with note about CLASSPATH - basicaly, I have current
directory (".") listed in it.

Also, replaced quote character with "quote" word in the code.

Updated version so far only here:

http://clojure.googlegroups.com/web/clojure-gui-and-netbeans.pdf

Vlad

--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-04 Thread prhlava


Hello Tim,

> Feel free to use it as you wish.

I have added the code (with attribution) to the guide.

Also, the .java generated code listing should now compile.

Updated guide is now on the same locations (including the files
section of this group).

>... So calling
> MainFrame.main() runs the static method, but you cannot do m = new
> MainFrame(); m.main();
> The generated "main" creates a new instance of MainFrame and makes it
> visible. There is no way for you to provide the object to "main" or
> get the object from "main" without modifying the java code.

Thank you for the explanation, now I get it...

Vlad

PS: Fixing the quote to be paste friendly is maybe possible somewhere
in LyX but so far I did not find out how...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-03 Thread prhlava



> > You can call main very easily: (MainFrame/main nil) however seeing the
> > default implementation does not return the created object, you can't
> > add the action listeners, so it isn't much use.
>
> I thought of using it as the "start" function to make the GUI visible
> (instead of .setVisible). Cheers for showing me how to call the
> function.

It looks that the main is class method? It can be called as above but
I do not know if/how to call that after the MainFrame has being
created (i.e calling it on resulting object). In any case it does not
matter much (but I am still curious).

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-03 Thread prhlava


Hello Tim,

Thanks for pointing the mistakes in code and the quote thing. Will be
fixed in the next version of the guide...

> You can call main very easily: (MainFrame/main nil) however seeing the
> default implementation does not return the created object, you can't
> add the action listeners, so it isn't much use.

I thought of using it as the "start" function to make the GUI visible
(instead of .setVisible). Cheers for showing me how to call the
function.

> http://groups.google.com/group/clojure/web/app.clj

Options are good :-). Any objections on including your variant in the
guide?

> I found the guide very well written and easy to follow.

:-)

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-02 Thread prhlava


Cool, at least one positive response so far :-).

I have also put the .pdf file into this group's files section, called:

clojure-gui-and-netbeans.pdf


Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



A short guide on how to use NetBeans to create GUI and then use this GUI from clojure available

2009-02-02 Thread prhlava


Hello,

I have put a short guide on how to create Swing GUI using NetBenans
and how to get hands on this generated
GUI JForm (java class) from clojure.

I hope someone will find this useful...

http://www.dearm.co.uk/cgan/

or (.pdf version):

http://www.dearm.co.uk/cgan/cgan.pdf

Vlad

PS: Comments welcome...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Clojure, GUI and NetBeans (a short guide on line and for download)

2009-02-02 Thread prhlava


Hello,

In an attempt of returnig favour (i.e. being able to use so much good
free software and getting free help while doing so), I have put
together a short guide (very basic) on how to use NetBeans GUI (Swing)
designer and then get hands on it from Clojure.

The guide is available in 2 forms (HTML and PDF) where the PDF version
has better images (for some reason export from LyX to .html scales
images down).

PDF: http://www.dearm.co.uk/cgan/cgan.pdf

HTML: http://www.dearm.co.uk/cgan/

Comments, suggestions, experiences welcome...

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: London Clojurians

2009-02-02 Thread prhlava


Hello Tom,

>   If not, would anyone be interested?

I live in London and would be interested...

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: agents, memory usage and threads

2008-12-22 Thread prhlava



> What I found that when the JVM memory usage goes to around 26% of
> available RAM, only one thread runs at the time from then on. Is this
> JVM optimising?

Well, it was hitting the JVM default amount of heap limit - works as
expected with proper parameters to java...

Sorry for the noise,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



agents, memory usage and threads

2008-12-20 Thread prhlava


Hello,

What is you experience with using agents on multi core CPU when agents
hold a considerable amount of memory allocated?

What I found that when the JVM memory usage goes to around 26% of
available RAM, only one thread runs at the time from then on. Is this
JVM optimising?

What I am trying to find out if i is my code or it is expected to
happen...

Kind regards,

Vlad

PS: In this particular code, the agents run "doall" on lazy (iterate)
sequence to produce the results used later...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



parallel factorial (code in the files section)

2008-12-18 Thread prhlava


Hello folks,

In the process of learning agents I have written a parallel
implementation of factorial
function.

The code is in files section as "parallel-factorial-example.clj",
shared in the hope that it can help others to understand the agents.

It is by no means a production code...

Comments welcome.

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ants.clj demo and old single core CPU

2008-12-16 Thread prhlava


Well,

Reducing the number of ants helped and it works...

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



ants.clj demo and old single core CPU

2008-12-16 Thread prhlava


Hello,

Is the ants.clj supposed to work on single core ~700MHZ CPU?

The program loads and runs, but all ants "stay at home" (but the CPU
is busy).

I am using latest svn version of clojure on:

java version "1.6.0_0"
IcedTea6 1.3.1 Runtime Environment (build 1.6.0_0-b12)
OpenJDK Client VM (build 1.6.0_0-b12, mixed mode)

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Swing GUI Builder and Clojure

2008-12-12 Thread prhlava


Hello Rock,

> Does anyone know of such a possibility? And, if not, what are the
> chances of coming up with a tool like that? I'm not a Java nor a Swing
> expert, so I haven't the faintest clue as to what the difficulties may
> be.

There is such a tool for jruby (which I tried for a basic gui) called
monkeybars:

http://monkeybars.rubyforge.org/

It would be a perfect candidate for borrowing the concept and
approach...

Basically, one uses netbeans (but it is not tied to netbeans) swing
gui builder to define the gui, the monkeybars does the plumbing and
the programmer uses jruby to do the programming in ruby...

Kind regards,

Vlad

PS: The jruby is ruby language implementation running on java virtual
machine...
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Swing GUI Builder and Clojure

2008-12-12 Thread prhlava


Swing - as it comes built in with java

Vlad
--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



distributing a clojure application as self contained .jar - guide

2008-12-12 Thread prhlava

Hello,

What is the position on distributing clojure classes with user
application classes in single .jar file. Is including the license for
clojure in the .jar as a text file enough?

I would like to amend:

http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips

section 1.9 so the "the right stuff" happens from licensing and
distribution point of view...

Kind regards,

Vlad

--~--~-~--~~~---~--~~
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 group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



distributing a cliojure application as .jar - guide

2008-12-12 Thread prhlava


Hello,

What is the position on distributing clojure classes with user
application classes in single .jar file. Is including the license for
clojure in the .jar as a text file enough?

I would like to amend:

http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips

section 1.9 so the "the right stuff" happens from licensing and
distribution point of view...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 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 built in HTTP server, proxy and HttpHandler interface

2008-12-09 Thread prhlava


Hello Steve,

> It may be that *out* gets redirected. Another difference between out
> and err is that System/err is often associated with an "autoflush"
> stream. It's possible that your output to *out* has ben buffered and
> that you need a call to (flush) to ensure it's displayed.

Not calling the flush could be the culprit...

> On a separate note, one convenient thing about Clojure namespaces is
> that they are created with "java.lang" already (effectively) imported.
> An unqualified call like
>
> (.println System/err "something")

Just learnt that *err* is defined in clojure so:

(. *err* println "something")

works :-).

Kind regards,

Vlad

PS: uploaded example of handling "post" in http server: http-server-
post.clj
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-09 Thread prhlava


Well,

The

(. java.lang.System/err println "something")

works from in handler (it looks that *out* gets re-directed)...

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-09 Thread prhlava


Hello Kyle,

What got me started is java code on:

http://www.java2s.com/Code/Java/JDK-6/LightweightHTTPServer.htm

But what is strange that java code handler can print to console and
clojure version (if run as a script) does not.

How do you go about debugging the handler?

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java built in HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava


Well, it turns out that the following works, but it only prints the
"exchange" to stdout,
if the code is cut and pasted to the REPL but _not_ if run as .clj
script)...

(import
 '(java.io IOException)
 '(java.io OutputStream)
 '(java.util Iterator)
 '(java.util List)
 '(java.util Set)
 '(com.sun.net.httpserver Headers)
 '(com.sun.net.httpserver HttpExchange)
 '(com.sun.net.httpserver HttpHandler)
 '(java.net InetSocketAddress)
 '(java.util.concurrent Executors)
 '(com.sun.net.httpserver HttpServer)
 )

(def port )

(let [server (. HttpServer create (new InetSocketAddress port) 0)
  handler (proxy [HttpHandler] []
(handle [#^HttpExchange exchange]
(println exchange) ; this does not get printed if run 
as script
(but it does if all of the code is pasted to the REPL)
(. exchange close)
))
  ]
  (. server createContext "/" handler)
  (. server setExecutor (. Executors newCachedThreadPool))
  (. server start)
  (print "server listening on port: ")(println port)
  )

--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java build it HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava

Oops,

The subject should have read:

java built in HTTP server, proxy and HttpHandler interface...
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



java build it HTTP server, proxy and HttpHandler interface

2008-12-08 Thread prhlava


Hello again,

I am trying to use java built in HttpServer and it looks that the
handle method of HttpHandler interface does not get called at all (but
the server "works" - returns a blank page, which is expected as I do
not write anything in the handle method).

The following example is minimal implementation (cut down version of
the original code), what I do not understad is why the "handle" method
of HttpHandler interface does not get called at all. (I would expect
the server to print "exchange" object to the shell window on every
request handled.)

; imports omitted

(def port )

(def handler (proxy [HttpHandler] []
   (handle [#^HttpExchange exchange]
   (println exchange

(let [server (. HttpServer create (new InetSocketAddress port) 0)]
  (. server createContext "/" handler)
  (. server setExecutor (. Executors newCachedThreadPool))
  (. server start)
  (print "server listening on port: ")(println port)
  )

Is the proxy route wrong for this and I should use gen-class instead?

Kind regards,

Vlad

PS: The HttpHandler is an interface with one method called "handle".
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-08 Thread prhlava


Hello Samantha,

> Why not just stream it into a JDBC Blob to your database?

The "daemon" does more than just storing it in the database (it is
basicaly a postfix mail filter something like spamassassin in
principle, but does different things with the e-mails).

>   Is there  some reason the mail to be stored needs to be read remotely to the
> machine storing messages to the database BTW?

It goes to a database server - so potentialy it could be also read
(from database) on the machine doing the storing...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-08 Thread prhlava


Hello Randall,

> If your application is client/server, you really should just go with an
> ordinary TCP connection (or, conceivably, a UDP port), define a proper
> protocol and do the whole thing properly.

This makes sense (if done right, the submitter can be invoked several
times in parallel and submit
more than one e-mail in parallel to the daemon - and this is needed).

> Realistically, I'd start by looking at the ordinary Servlet /
> HttpServlet mechanism. You get so much from existing servlet containers
> (Tomcat, Jetty, GlassFish, etc.) that it's very hard to justify
> starting from scratch.

Will see if I learn how to deploy clojure application in a Tomcat
container...

> Named pipes have peculiar semantics and, of course, do not cross machine
> boundaries (unless you're running in one of the now-rare distributed
> Unix kernels—I say this as a one-time employee of Locus Computing
> Corporation...). I can't say named pipes really useful for much other
> than their use by shells for their <( command ) syntax.

So it looks that named pipe does not cut it here.

Thanks for all the info, and I can proceed in other way(s) now...

But would you not expect that the working code still works when
enclosed in the "while" construct?

Kind regards,

Vlad

--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-07 Thread prhlava


> You're asking for the pipe to be repeatedly opened, one uninterrupted glob of 
> bytes read and processed and then the pipe closed. Is that really what you 
> intend?

Yes, that was my intention, maybe a rethink is in order...

> As written, this suggest a kind of "daemon" that monitors the pipe,
> waiting for successive writers, each of which must write everything
> they want processed by the far side in a single write call and
> furthermore that transmission must not exceed the operating system's
> pipe high-water mark. All this seems a bit fragile to me.
>
> But more practically, you should _say_ what you want your code to
> accomplish.

Store e-mail messages in a database (I am porting a program that
already does this, as an exercise) + making it work through pipe (as
java start-up is longish) => therefore I will have submitter and
"daemon" receiver...

> > Thanks for the explanations, the blocking is not a problem. ...
> It was not clear whether or not your mention of the blocking behavior
> was something you considered unexpected or problematic.

No worries, I ment it as a hint, but this is also the 1st time I am
woking with named pipe, so the explanations were welcome...

But why it does not work with the "while" around the code still
escapes me...

Kind regards,

Vlad

PS: back tomorrow
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: linux, named pipe (fifo) and (while ...)

2008-12-07 Thread prhlava

> > The following does not work, but if I remove the (while true , it
> > does...
>
> Characterize "does not work," if you would.

Well, nothing happens with "(while" around the code... But if I take
the
"while" out, and run the remaining code, it does what expected -
prints the content of the buffer (once, of course).

> (explanations snipped)

Thanks for the explanations, the blocking is not a problem. The way I
expected it to work is "open-read-close" on one end and "open-write-
close" on the other...

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



linux, named pipe (fifo) and (while ...)

2008-12-07 Thread prhlava


Hello everyone,

I am trying to read (repeatedly) from named pipe (fifo) on linux (the
program will be a long running process...).

The following does not work, but if I remove the (while true , it
does...

(def pipe-name "/tmp/my-pipe")

(def buffer-size (* 1 1024))

(while true
   (with-open [pipe (new java.io.FileInputStream pipe-name)]
 (print pipe)
 (let [buffer (make-array Byte/TYPE buffer-size)]
   (. pipe read buffer)
   (map print buffer

I am lost here...

Vlad

PS: The new java.io.FileInputStream call blocks until the pipe is
closed at the "other" end...
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: one way to write a factorial function

2008-11-24 Thread prhlava


user=> (= (range 10) (for [x (range 10)] x))
true

:-)

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: one way to write a factorial function

2008-11-24 Thread prhlava

> Help me understand why this isn't written
>
> (defn factorial [n]
>   (apply * (range 1 (+ n 1)))
>
> instead. That is, I don't get the purpose of the for statement.

Neither do I now ;-),

nice,

Vlad

--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: one way to write a factorial function

2008-11-23 Thread prhlava


Wow, the apply version above is faster (but not much) than the version
on:

http://clojure.org/special_forms

the "apply" version run 8.55 [minutes]
the special_forms version run 9.50 [minutes]

(this was for n=10 on and old P3)

Beginners luck I suppose...

Vlad

PS: Displaying the number takes a long time, I had run (time
(factorial 10)) in both cases, which prints the time before
displaying the result...
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



one way to write a factorial function

2008-11-23 Thread prhlava


Hello folks,

While learning, it occured to me that factorial function can be
written as:


(defn factorial [n]
 (apply * (for [x (range 1 (+ n 1))] x)))


I know that it has big argument list for large numbers, but it seems
to scale nicely (at least in clojure).

I am sure this was discussed to death in lisp groups - have searched
the net and did not find this version...

kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: writing binary values (bytes) to a file

2008-11-21 Thread prhlava


Hello Jeffrey,

> Code is located at: 
> http://github.com/jbester/cljext/tree/master/cljext%2Fbinpack.clj

Thanks for the link, more food for study on how to write a generic
library...

Basically, I am scheme/lisp noob, learning it in my spare time, the
progress is slow but rewarding...

Few observations about my own experience with starting with lisp:

1. concentrate on meaning and what fuctions do, not on the form and
""
2. name your functions well
3. use tools to have your code idented properly
4. learn ways of creating abstracions and recognising when one is
asking to be written
(this thread kickstarted 4.)

Kind regards,

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: writing binary values (bytes) to a file

2008-11-20 Thread prhlava


Hello Graham,

> Bonus question for the bored reader: write a function,
> (byte-array-maker N), that takes a width N, and returns a function
> that takes an Integer as input and returns an N-width byte array
> containing the Integer in big-endian order. E.g.
>
> ((byte-array-maker 4) 652187261)
> => [4-byte array: 26, df, 96, 7d]

:-) writing the function thought me quite a bit :-)

Vlad
--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread prhlava


Hello again,

Thank you all for the posts and explanations,

After getting the clojure SVN version and few tweaks in the code, the
working result looks like:

 (with-open [ofile (new java.io.FileOutputStream
(str result-directory
 "/"
 (make-filename x y))
(boolean true))] ; I am appending only
(. ofile write
  (into-array Byte/TYPE
  [(byte (bit-shift-right pix 16))
   (byte (bit-shift-right pix 8))
   (byte pix)])) ; the pix is of the 
Integer type

Vlad


--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-19 Thread prhlava


> I'm from Slovakia. :)

I am from my mum who was in Slovakia at the time of my birth ;-) (and
I have grown up in Slovakia)

Vlad

--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



writing binary values (bytes) to a file

2008-11-19 Thread prhlava


Hello all,

I have started to play with the clojure a day ago and today I have
almost finished porting simple program (from plt-scheme).

The place I got stuck in is - how to write a binary value (multiple
bytes) in one write operation to a file... The code uses
java.io.FileWriter, but this wants string.

What I need to write is 3 RHS bytes from an integer, (the pix is
Integer in following code):

(. ofile write (str
   (char (bit-shift-right pix 16))
   (char (bit-shift-right pix 8))
   (char pix)))
   )

writes wrong stuff. Is this unicode thing, my noob status thing or
something else?

Kind regards,

Vlad

--~--~-~--~~~---~--~~
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 group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---