Re: minor pauses

2011-04-09 Thread Peter Schuller
 Perhaps I'm not reading the GC logging information correctly, but it didn't 
 appear to me that the GC was to blame for the pauses. Perhaps it might not 
 even be the JVM but the OS kernel? Until I have a good idea what's causing 
 them, it seems that throwing solutions (such as moving to a realtime VM) is 
 just stabbing at the dark.

From your GC logs it doesn't look like GC is the problem no so for now
the point is moot. However, if you are targeting 10 ms pause times you
may or may not at some point have a problem. For very small heap sizes
and moderate allocation rates it'll probably work okay. Once you start
having larger heap sizes or lots of allocation, it becomes more
difficult. Depending on your application, it may or may not be an
issue. Just be aware that there is no expectation that CMS will
*guarantee* you 10 ms pause times. Same for G1 (or JRockit for that
matter).

As for discovering the real cause of the pause: Without obvious
culprits I would probably just do a binary search of source, in
terms of the call stack. Keeping doing the timings at different places
and see where you're not seeing the pauses and where you are seeing
them, and drill down.

Another option, depending on how fast 'jstack' is in relation to your
pauses, is to try to get a 'jstack' on the process while you're seeing
a pause and see if there is a thread blocking in an unexpected
location. That's assuming there is something blocking for an extended
period of time that is causing it.

-- 
/ Peter Schuller

-- 
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: help--reading keyboard input from Clojure is surprisingly difficult

2011-04-09 Thread Lee Spector

On Apr 8, 2011, at 11:33 PM, Gregg Williams wrote:

 ... *How* does the
 word easier belong in that sentence, when I all I want to do is read
 input from the keyboard?!
 
 My modest proposal:
 ...

I'm writing to support the sentiment that Gregg expressed here with regard to 
this issue, and also his broader proposal.

List members offered several clever and helpful workarounds in response to 
Gregg's post, along with pointers to the reasons for the current situation. 
Great!

But still, I will humbly submit that it's totally freakin' nutso that it should 
be so hard to do basic user interaction.

FWIW I looked back at materials I used to teach clojure last semester and saw 
that I presented some stuff based on read-line in the REPL and it must have 
worked in the environment that I was using at the time, which was Eclipse/CCW 
on a mac. But now I do remember that some students who were using this for 
simple text adventure games had problems, although I don't remember the 
details. They may have been using other platforms. In any event I will include 
the code that I shared with the students at that time below... yes, I know that 
some of you will think that I shouldn't have used eval, etc., but for the 
purpose I think it was fine and my view that stuff like this should work 
without clever workarounds in any Clojure environment that isn't labeled as 
broken.

 -Lee

(ns commandline)

(defn read-and-do-line
  Get from the user and execute a command line without parentheses,
where the first thing on the line is the name of a function and the
rest of the line is arguments (which will not be evaluated).
  []
  (print command: )
  (flush)
  (let [line (read-line)
list-of-things (read-string (str ( line )))]
(apply (eval (first list-of-things)) (rest list-of-things


(defn inc-and-print [number] (println (inc number))) ;; just an example command 
to call
(defn list-and-print [ args] (println (apply list args))) ;; another

(def in-loop (atom false)) ;; just to control the command loop below

(defn quit [] (reset! in-loop false)) ;; a function to get out of the loop

(defn command-loop []
  (reset! in-loop true)
  (loop []
(when @in-loop
  (read-and-do-line)
  (recur

;; 1:3 commandline= (command-loop)
;; command: inc-and-print 3
;; 4
;; command: list-and-print :a :b :c 1 2 3
;; (:a :b :c 1 2 3)
;; command: quit
;; nil
;; 1:7 commandline= 

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread James Reeves
On 8 April 2011 23:21, Ken Wesson kwess...@gmail.com wrote:
 Better yet: maybe we're looking at this backwards. Maybe what we want
 isn't a predicate for *passed* validation, but a predicate for
 *failed* validation:

 (defn s-blank? [x]
  (if (empty? (.trim x)) must not be blank))

That particular example ties a predicate to a particular error
message. Error messages should be independent of predicates, otherwise
they can't be localized or changed to fit a specific situation.

 This takes advantage of the fact that the error messages we want are
 all truthy. It's also the case that you often want to detect and
 handle invalid input right away, then get to the meat of the logic.
 The natural ordering of if, if-let, etc. puts the true case first.
 Making the true case the error case lets you easily get it out of
 the way first in your code.

This would lead to a lot of validations with not in front of them.
i.e not-email-address?, not-integer?, etc.

- James

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread Ken Wesson
On Sat, Apr 9, 2011 at 9:56 AM, James Reeves jree...@weavejester.com wrote:
 On 8 April 2011 23:21, Ken Wesson kwess...@gmail.com wrote:
 Better yet: maybe we're looking at this backwards. Maybe what we want
 isn't a predicate for *passed* validation, but a predicate for
 *failed* validation:

 (defn s-blank? [x]
  (if (empty? (.trim x)) must not be blank))

 That particular example ties a predicate to a particular error
 message. Error messages should be independent of predicates, otherwise
 they can't be localized or changed to fit a specific situation.

It can always be an integer or a keyword (or a string!) used to look
up the localized or situation-specific message in a map.

 This takes advantage of the fact that the error messages we want are
 all truthy. It's also the case that you often want to detect and
 handle invalid input right away, then get to the meat of the logic.
 The natural ordering of if, if-let, etc. puts the true case first.
 Making the true case the error case lets you easily get it out of
 the way first in your code.

 This would lead to a lot of validations with not in front of them.
 i.e not-email-address?, not-integer?, etc.

So?

-- 
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: Where is the javadoc for clojure.lang ?

2011-04-09 Thread Stuart Sierra
Unfortunately, there is no JavaDoc for clojure.lang because there are no 
comments in the source.  If you want to understand Clojure's Java source 
code, you'll just have to read it.

-Stuart Sierra
clojure.com

-- 
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: Where is the javadoc for clojure.lang ?

2011-04-09 Thread rob levy
Also, there is the Clojure in Small Pieces doc that Tim Daly is working
on.

On Sat, Apr 9, 2011 at 11:00 AM, Stuart Sierra
the.stuart.sie...@gmail.comwrote:

 Unfortunately, there is no JavaDoc for clojure.lang because there are no
 comments in the source.  If you want to understand Clojure's Java source
 code, you'll just have to read it.

 -Stuart Sierra
 clojure.com

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


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

ANN: Logos v0.6 - Pattern matching, Tabling, Disequality Constraints, and now on Clojars

2011-04-09 Thread David Nolen
Logos is finally in good enough shape to be worth publishing to Clojars.
There are really too many changes to enumerate here, but if you're familiar
with Prolog, Logos is now far enough along that you can basically write
Prolog in Clojure and then some. Here's the evidence:

(defn-e nqueens-o [l]
  ([()])
  ([[[?x ?y] . ?others]]
 (exist []
  (nqueens-o ?others)
  (member-o ?y [1 2 3 4 5 6 7 8])
  (noattack-o [?x ?y] ?others

(defn-e noattack-o [q others]
  ([_ ()])
  ([[?x ?y] [[?x1 ?y1] . ?others]]
 (exist []
  (!= ?y ?y1)
  (nonrel/project [?y ?y1 ?x ?x1]
  (!= (- ?y1 ?y) (- ?x1 ?x))
  (!= (- ?y1 ?y) (- ?x ?x1)))
  (noattack-o [?x ?y] ?others

The big changes are:

* Pattern matching
* Goals can be tabled a la XSB
* Fairly efficient implementation of disequality constraints (and programs
w/o constraints are not penalized)

I've been begun porting some examples from Bratko's excellent Prolog book as
a guide for those who are interested here
https://github.com/swannodette/bratko-logos.

A note on performance: when the search space is not small Logos doesn't
perform as well as Prolog since it uses an interleaving strategy, and this
interleaving is currently implemented via liberal thunking. While I'm
interested in making Logos faster, I think many of the kinds of search
problems that are currently slower in Logos than in Prolog are best solved
with Constraint Logic Programming anyhow - which is the next major feature
for Logos.

Enjoy,
David

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

How to access specific java.awt.Color constructor?

2011-04-09 Thread stu
Hi,

I'm trying to create a java.awt.Color class instance from within
Clojure, using this constructor:

Color(ColorSpace cspace, float[] components, float alpha)

But always end up with a No matching ctor found for class
java.awt.Color exception.

I can create the ColorSpace instance as I expected, but I think I'm
missing something with the rest of the Color constructor.  I've tried
changing the components to a vector of floats or a Java array of
floats with no luck.

This is with Clojure 1.2 and the Java Platform SE 6 AWT classes.

Any advice much appreciated.

Stu

-- 
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: help--reading keyboard input from Clojure is surprisingly difficult

2011-04-09 Thread Sean Corfield
On Sat, Apr 9, 2011 at 6:46 AM, Lee Spector lspec...@hampshire.edu wrote:
 But still, I will humbly submit that it's totally freakin' nutso that it 
 should be so hard to do basic user interaction.

I'm curious as to what percentage of developers are writing
console-based applications (in any language)?

What do the processes look like in other languages? How are those
processes different to what happens with Clojure?

With the following test program, t.clj...

(println Testing...)
(let [a (read-line)]
(println   a))

...I can open up a REPL, do (load-file t.clj) and it runs as
expected. I can also type clj run t.clj and it works just fine (can't
remember where I got that script from - it just wraps the java command
to start Clojure).

Now, I will concede that lein run t.clj does not work - and that does
seem a bit odd given that lein repl then (load-file t.clj) works but
if it's a technical limitation with the run task, fair enough.

However, given the clj run command, I can add a #! line to my Clojure
scripts, make them execute and just run them:

#!/usr/bin/env clj run
(println Testing...)
(let [a (read-line)]
(println   a))

Now I can just type ./t.clj and it works as expected...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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 access specific java.awt.Color constructor?

2011-04-09 Thread Sean Corfield
Can you show a bit more of the code you have so we can see what you've tried?

On Sat, Apr 9, 2011 at 3:13 PM, stu stuart.hungerf...@gmail.com wrote:
 I'm trying to create a java.awt.Color class instance from within
 Clojure, using this constructor:

 Color(ColorSpace cspace, float[] components, float alpha)

 But always end up with a No matching ctor found for class
 java.awt.Color exception.

 I can create the ColorSpace instance as I expected, but I think I'm
 missing something with the rest of the Color constructor.  I've tried
 changing the components to a vector of floats or a Java array of
 floats with no luck.

-- 
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 access specific java.awt.Color constructor?

2011-04-09 Thread Alan
You probably weren't putting it into a java float array, but instead a
Float array (boxed type). Here's a repl session doing what you want. I
don't know anything about colorspaces so it's probably nonsense, but
it creates a Color with that constructor.

user= (import '(java.awt.color ICC_Profile ColorSpace ICC_ColorSpace)
java.awt.Color)
java.awt.Color
user= (def prf (ICC_Profile/getInstance (ColorSpace/CS_sRGB)))
#'user/prf
user= (def spc (ICC_ColorSpace. prf))
#'user/spc
user= (class spc)
java.awt.color.ICC_ColorSpace

;; the magic words
user= (def c (Color. spc (float-array [1 1 1]) (float 1)))
#'user/c
user= (def c (Color. spc (into-array Float/TYPE [1 1 1]) (float 1)))
#'user/c


On Apr 9, 3:21 pm, Sean Corfield seancorfi...@gmail.com wrote:
 Can you show a bit more of the code you have so we can see what you've tried?







 On Sat, Apr 9, 2011 at 3:13 PM, stu stuart.hungerf...@gmail.com wrote:
  I'm trying to create a java.awt.Color class instance from within
  Clojure, using this constructor:

  Color(ColorSpace cspace, float[] components, float alpha)

  But always end up with a No matching ctor found for class
  java.awt.Color exception.

  I can create the ColorSpace instance as I expected, but I think I'm
  missing something with the rest of the Color constructor.  I've tried
  changing the components to a vector of floats or a Java array of
  floats with no luck.

-- 
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: help--reading keyboard input from Clojure is surprisingly difficult

2011-04-09 Thread Lee Spector

On Apr 9, 2011, at 6:18 PM, Sean Corfield wrote:

 On Sat, Apr 9, 2011 at 6:46 AM, Lee Spector lspec...@hampshire.edu wrote:
 But still, I will humbly submit that it's totally freakin' nutso that it 
 should be so hard to do basic user interaction.
 
 I'm curious as to what percentage of developers are writing
 console-based applications (in any language)?
 

I don't know -- probably quite low -- but I would predict that the percentage 
of students learning Lisp-like languages who would be writing console-based 
interactive programs is quite high. Lots of curricula are based on this sort of 
thing, and even people who aren't students may do some of this first since it 
seems like it shouldn't rely on understanding libraries or the java ecosystem 
or whatever. So funky behavior related to simple text I/O may be confusing 
people who are least likely to know how to work around it.

 What do the processes look like in other languages? How are those
 processes different to what happens with Clojure?

Code for doing this sort of thing in Common Lisp or Scheme looks almost 
identical to the simple Clojure code we've seen on this thread, with the most 
significant difference being that the Clojure version apparently doesn't work 
if you launch your REPL and run your code in some of the commonly recommended 
ways. (Note: I haven't tried all of the ways that have been discussed, but the 
consensus seems to be that it does indeed fail.)

 -Lee

-- 
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: help--reading keyboard input from Clojure is surprisingly difficult

2011-04-09 Thread Mike Meyer
On Sat, 9 Apr 2011 19:27:13 -0400
Lee Spector lspec...@hampshire.edu wrote:
 On Apr 9, 2011, at 6:18 PM, Sean Corfield wrote:
  On Sat, Apr 9, 2011 at 6:46 AM, Lee Spector lspec...@hampshire.edu wrote:
  But still, I will humbly submit that it's totally freakin' nutso that it 
  should be so hard to do basic user interaction.
  I'm curious as to what percentage of developers are writing
  console-based applications (in any language)?
 I don't know -- probably quite low -- but I would predict that the
 percentage of students learning Lisp-like languages who would be
 writing console-based interactive programs is quite high.

I wouldn't expect it to be quite low, but I build them regularly,
and so do most of the people I work with. On unix systems, the
predominate way to plug to programs together is still via the standard
IO pipes, which the programs - even if normally invoked from some
visual tool - can be used from the command line. And many of us work
develop on one system, then deploy on something else via SSH, so being
able to deal with things on the command line - even if it also
provides some kind of GUI - is a useful feature.

Admittedly, JVM languages don't lend themselves to such things, what
with having to either start it on every command or have some kind of
server running to avoid that.

 Code for doing this sort of thing in Common Lisp or Scheme looks
 almost identical to the simple Clojure code we've seen on this
 thread, with the most significant difference being that the Clojure
 version apparently doesn't work if you launch your REPL and run your
 code in some of the commonly recommended ways.

This sounds more like an issue with those commonly recommended ways
than with clojure or it's REPL, since it works fine running from a
shell.

 mike
-- 
Mike Meyer m...@mired.org http://www.mired.org/consulting.html
Independent Software developer/SCM consultant, email for more information.

O ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: ANN: Logos v0.6 - Pattern matching, Tabling, Disequality Constraints, and now on Clojars

2011-04-09 Thread MarkSwanson
Fascinating!

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Announcement: pretzel - a predicate library + call for suggestions

2011-04-09 Thread James Reeves
On 9 April 2011 10:07, Ken Wesson kwess...@gmail.com wrote:
 That particular example ties a predicate to a particular error
 message. Error messages should be independent of predicates, otherwise
 they can't be localized or changed to fit a specific situation.

 It can always be an integer or a keyword (or a string!) used to look
 up the localized or situation-specific message in a map.

It's still not as flexible, because different keywords with the same
validation may require different error messages.

It could perhaps work with a Turing-complete localization system, i.e.
one where localizations are performed by arbitrary scripts, but I
don't think a validation system should depend on having a
sophisticated localization system.

I also don't like the idea of tying together two pieces of
functionality that could conceivably be separated. I prefer simple
functions over compound ones.

 This would lead to a lot of validations with not in front of them.
 i.e not-email-address?, not-integer?, etc.

 So?

It's redundant, doesn't read as well, and reverses people's usual
conceptions about validations. I'd prefer treating validations as a
contract, i.e. defining what user data must do to pass, rather than
what it must do to fail.

- James

-- 
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 access specific java.awt.Color constructor?

2011-04-09 Thread stu
On Apr 10, 8:35 am, Alan a...@malloys.org wrote:

 You probably weren't putting it into a java float array, but instead a
 Float array (boxed type). Here's a repl session doing what you want. I
 don't know anything about colorspaces so it's probably nonsense, but
 it creates a Color with that constructor.

   Thanks Alan -- I realize now there's a subtle but important
distinction there when doing Java interop.

Stu

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