Re: unchecked methods for floats/doubles?

2009-02-08 Thread Korny Sietsma

Excellent - thanks for clarifying this!

- Korny

On Sun, Feb 8, 2009 at 12:27 AM, Rich Hickey richhic...@gmail.com wrote:


 On Feb 7, 2009, at 3:43 AM, Korny Sietsma wrote:


 Ah - I didn't realise that.  I was trying to avoid the overhead, as I
 understood it, of both converting the parameters to Float/Double
 objects, and then of checking for overflow.

 So '*' and '+' don't do overflow checking - do they need to convert
 primitives to/from objects?  Specifically, when I call:
 (loop [x (double x) y (double y)]
  ... do maths to x and y
  (recur x y)
 )

 Is it going to have to convert x and y between 'double' and 'Double'
 at all, or will it just work with primitive types???


 This will declare the locals x and y to be primitive doubles,
 converting once on entry, and all math ops involving them and other
 primitives will be primitive. Also, if you accidentally try to recur
 with a boxed value you will get an error.

 Rich


 




-- 
Kornelis Sietsma  korny at my surname dot com
kornys on gmail, twitter, facebook, etc.
Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of

--~--~-~--~~~---~--~~
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: Newbie: applying arguments into a macro

2009-02-08 Thread Meikel Brandmeyer

Hi,

Am 08.02.2009 um 00:40 schrieb samppi:


(defn conc* [tokens  subrules]
 (loop [subrule-queue (seq subrules), remaining-tokens (seq tokens),
products []]
   (if (nil? subrule-queue)
 [products remaining-tokens]
 (let [[subrule-products subrule-remainder :as subrule-result]
   ((first subrule-queue) remaining-tokens)]
   (when-not (nil? subrule-result)
 (recur (rest subrule-queue) subrule-remainder
(conj products subrule-products)))
(defmacro conc [ subrules]
 `(fn [tokens#]
(conc* tokens# ~...@subrules)))

I had another function called factor=:
(defn factor= [factor subrule]
 (apply conc (replicate factor arg)))

When I changed conc to a macro, factor= didn't work anymore. Is there
no way of fixing factor=?


Why don't you call conc* directly?

(defn factor= [factor subrule]
  (fn [tokens]
(apply conc* tokens (replicate factor subrule

That's another nice example why to pack as much as possible
into a function, which is then called by the expanded macro
code.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: ANN: clojure.contrib.error-kit

2009-02-08 Thread David Nolen
So far this is fantastic! And I haven't even got around to playing with the
restart mechanism :) I'm using it in Spinoza to provide contextual errors
(malformed slot list, missing base class etc.).  I notice the contrib
libraries in general are very good at throwing exceptions so that consumers
have some idea of what is going on.  error-kit one ups this practice by
providing a standardized way to define your errors up front and presents a
definition system that removes the need to instantiate ugly Java Exceptions
inline with your code.
(defn protocol-fn [protocol-name fn-name]
  (let [protocol-keyword (symbol-to-keyword protocol-name)
dispatch (partial protocol-dispatch protocol-keyword)]
`(do
   (defmulti ~fn-name ~dispatch)
   (defmethod ~fn-name [:spinoza/object nil]
 [~'obj]
 (raise *missing-protocol-method-error*
 ~'obj ~(str protocol-name) ~(str fn-name))

Where the error is defined as you've described:

(deferror *missing-protocol-method-error* [*spinoza-error*]
  [obj protocol-name method-name]
  {:msg (str (:tag obj)
  class does not implement 
 method-name
  from protocol 
 protocol-name)})

Sweet!

That said I do have one minor annoyance and that is the need to leave an
empty bracket if you want to create a new error without inheriting from a
previously defined error.  Very minor.  Will provide feedback on restarts
when I get there.

--~--~-~--~~~---~--~~
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: ANN: clojure.contrib.error-kit

2009-02-08 Thread Chouser

On Sun, Feb 8, 2009 at 5:18 AM, David Nolen dnolen.li...@gmail.com wrote:

 Sweet!

I'm glad it's working for you, and that you have figured out how to
use it despite the almost complete lack of docs.  :-P

 That said I do have one minor annoyance and that is the need to leave an
 empty bracket if you want to create a new error without inheriting from a
 previously defined error.  Very minor.

This was actually intentional.  I had a pre-release version where
those brackets were optional, but the doc-string could still be
specified.  But I was worried this would be too confusing since it
meant that if you then inserted the parent vector, that would have to
come before the doc-string, but the args vector would have to be
inserted after.

(deferror *foo* Foo Error)
(deferror *foo* [*bar*] Foo Error)
(deferror *foo* Foo Error [arg1])
(deferror *foo* [*bar*] Foo Error [arg1])

And perhaps worst, if you got it wrong, I may not be able to detect
the mistake:

(deferror *foo* Foo Error)
(deferror *foo* Foo Error [*bar*])
(deferror *foo* Foo Error [*bar*] [arg1]) ; oops

That last line would be using [*bar*] as the arg vector and [arg1] as
the error object definition.

...anyway, that's reasoning behind requiring at least placeholder
empty brackets before the doc-string.  But I'm open to being persuaded
otherwise.  Perhaps allow no parent vector if there's also no
doc-string?

Oh, and by the way with an empty or missing parent vector, the error
would still be derived from kit/*error*.

 Will provide feedback on restarts when I get there.

Great!  But they're called continues.  :-)  Seriously, if you think
restart is a better name I'm willing to consider changing it.  But
Clojure already has retries in transactions, where code is actually
re-run from the beginning.  A restart doesn't re-run anything, it
just skips forward over a certain number of returns and runs an
alternate branch of code.  continue seemed a better description of
that to me than restart.

--Chouser

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



if-let

2009-02-08 Thread Mark Volkmann

Can someone show me an example of a good use of if-let?

I find its doc string a little confusing. It says If test is true,
evaluates then with binding-form bound to the value of test, if not,
yields else. However, it doesn't have a parameter named test. I
assume it means If the binding evaluates to true 

Also, it has a parameter named bindings, but it should perhaps be
named binding because it doesn't allow specifying more than one
binding.

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
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: if-let

2009-02-08 Thread Meikel Brandmeyer

Hi,

Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson:


Here's one, I'm setting basedir to either :basedir in a map in *locs
(a thread-local var) or to . if :basedir was not found in the map...

(let [basedir (if-let [bdir (:basedir *locs)] bdir .)]
   ...)

i.e bdir assumes the value of the test and if that is not false (or
nil) returns it otherwise the else part.


This can be written more concise with get or even with :basedir alone:

(let [basedir (get *locs :basedir .)] ...)
(let [basedir (:basedir *locs .)] ...)
(let [basedir (*locs :basedir .)] ...)

All but the last form work also if *locs is nil.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: if-let

2009-02-08 Thread Adrian Cuthbertson

Thanks Meikel. There's always something new to learn. I'm also fast
learning that if something doesn't look quite elegant in one's code,
then there's bound to be an elegant clojure way of doing it!


On Sun, Feb 8, 2009 at 4:51 PM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 08.02.2009 um 15:47 schrieb Adrian Cuthbertson:

 Here's one, I'm setting basedir to either :basedir in a map in *locs
 (a thread-local var) or to . if :basedir was not found in the map...

 (let [basedir (if-let [bdir (:basedir *locs)] bdir .)]
   ...)

 i.e bdir assumes the value of the test and if that is not false (or
 nil) returns it otherwise the else part.

 This can be written more concise with get or even with :basedir alone:

 (let [basedir (get *locs :basedir .)] ...)
 (let [basedir (:basedir *locs .)] ...)
 (let [basedir (*locs :basedir .)] ...)

 All but the last form work also if *locs is nil.

 Sincerely
 Meikel



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



Pmapping force over treed delays

2009-02-08 Thread Anand Patil

Hi all,

Say I have a collection of delays, some of which need to get others'
values in order to compute (there are no cyclic dependencies). If I
just pmap force over the entire collection, do I run the risk of
filling up a thread pool with operations that aren't ready to go yet?
Would it be better to represent the collection as a tree-seq and then
pmap force over that?

Many thanks,
Anand
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Discarding entire transactions

2009-02-08 Thread Anand Patil

Hello again,

In my application, I'll frequently want to quickly discard all the
changes made during a transaction involving many refs. I don't want to
force the refs to roll back to their values at the beginning of the
transaction, I just want to end the transaction immediately and skip
the write stage; updates made in other transactions should still
'stick'. What's the most efficient way to do this?

Thanks again!
Anand
--~--~-~--~~~---~--~~
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: Questions about a Clojure Datalog

2009-02-08 Thread John Fries
reposted to correct a  mistake in my use of X, Y and Z:
---
I agree with Jeffrey that there is no reason to have just one option.
Sometimes you want your reasoner to find a single model; sometimes you want
it to find all models (assuming you are reasoning over a finite set).

I've appended a long rant about SAT-based reasoners and open-world
semantics.  I hope it is relevant, and apologize for the length.

-John

Initially, I had a lot of trouble understanding why the concept of
satisfiability was relevant to reasoning.  I just wanted to know whether or
not a sentence was true; whether or not it was satisfiable didn't seem
relevant.  Here's how you *could* use a SAT solver to answer a practical
question (later I will explain why you would want to):

Let's say you have a list of sentences A:
A = ((man socrates) (for all X: man X - mortal X)).
A is your database of previous assertions.  Now let's say that you want to
determine the truth state of a new sentence B:
B = (mortal socrates)
In other words, you want to know whether or not B is true, given all your
previous assertions A.

So you form two new sentences, Y  Z:
Y = (A and B) = ((man socrates) and (for all X: man X - mortal X) and
(mortal socrates))
Z = (A and (not B)) = ((man socrates) and (for all X: man X - mortal X) and
(not (mortal socrates)))

You then plug Y into your SAT solver, and also plug Z into your SAT solver.
If Y is satisfiable and Z is satisfiable, then we say that B's truthstate,
relative to A, is UNKNOWN.
If Y is satisfiable and Z is unsatisfiable, then we say that B's truthstate,
relative to A, is TRUE.
If Y is unsatisifiable and Z is satisfiable, then we say that B's
truthstate, relative to A, is FALSE.
If Y is unsatisfiable and Z is unsatisfiable, then we say that B's
truthstate, relative to A, is CONTRADICTION.

In this example, I'm pretending we have a first-order logic SAT solver (i.e.
we can quantify, and our predicates take arguments), whereas usually we only
have a boolean logic SAT solver, but the former can be easily built upon the
latter (although it would be more efficient to build a first-order SAT
solver).  Also, the actual implementation can be much more optimized than
this; there is usually overlapping work done during the evaluation of X and
Y.

This example only shows you how to evaluate (truthstate A B).  If you wanted
to find a *model* (i.e. a list of tuples of things that satisfy some
sentence), then you would say something like get X: red X (i.e. get me all
X's that you can prove are red).  In a system with finitely many things, the
vanilla unoptimized reasoner simply loops through each thing in the system
and asks for its truthstate:
for each X:
  if (truthstate A (red X)) == TRUE:
add X to output

There can be situations where you would want, not just the things for which
the predicate is TRUE, but also the things for which the predicate is
UNKNOWN.  You can include that as a argument to your query.  Also, there is
a separate mechanism for performing default reasoning (which I am eliding
here because this is already a pretty long rant).

Why go through all this trouble to get open-world semantics?  Why not just
use a close-world reasoner?  First, I think open-world semantics does a
better job of mimicing human reasoning.  If humans don't know that a
sentence is true, they don't generally conclude that it's false.  Second,
basing your reasoner on a SAT solver makes a lot of sense computationally.
SAT is a hard problem (NP-complete), but so much work has been done on it
that in practice we can solve very large instances efficiently (and any SAT
problem is solvable given enough time and memory).  The underlying SAT
solvers seem to be improving at a tremendous rate, so a system that
interfaces to them benefits from all that work.

-John

On Sat, Feb 7, 2009 at 11:25 AM, John Fries john.a.fr...@gmail.com wrote:

 I agree with Jeffrey that there is no reason to have just one option.
 Sometimes you want your reasoner to find a single model; sometimes you want
 it to find all models (assuming you are reasoning over a finite set).

 I've appended a long rant about SAT-based reasoners and open-world
 semantics.  I hope it is relevant, and apologize for the length.

 -John

 Initially, I had a lot of trouble understanding why the concept of
 satisfiability was relevant to reasoning.  I just wanted to know whether or
 not a sentence was true; whether or not it was satisfiable didn't seem
 relevant.  Here's how you *could* use a SAT solver to answer a practical
 question (later I will explain why you would want to):

 Let's say you have a list of sentences A:
 A = ((man socrates) (for all X: man X - mortal X)).
 A is your database of previous assertions.  Now let's say that you want to
 determine the truth state of a new sentence B:
 B = (mortal socrates)
 In other words, you want to know whether or not B is true, given all your
 previous assertions A.

 So you form two new sentences, Y  Z:
 X = (A and B) 

Re: IntelliJ Plugin -- Wonderful News!

2009-02-08 Thread Peter Wolf

I am using IDEA 9164.  Make sure idea.jar is on your classpath (it is 
not part of the Development SDK).

BTW to original plugin is still available pre-built.  It works fine on 
Linux and Windows.  See

http://code.google.com/p/clojure-intellij-plugin/




Howard Lewis Ship wrote:
 I'm trying to build this locally; I haven't built an IDEA plugin before.

 Anyway, I've downloaded the 8.0.1 dev kit and installed it, but class
 com.intellij.openapi.module.JavaModuleType doesn't exist, although
 this a JAR with other classes from that package.

 I must have the wrong version of the dev kit; what's the correct
 version to be using?

 Thanks,

 Howard


 On Fri, Feb 6, 2009 at 7:53 AM, Tom Ayerst tom.aye...@gmail.com wrote:
   
 That is excellent news.  Now I just to learn enough Clojure to properly
 contribute to a pukka open Source project so I can get a free copy ;-)

 2009/2/6 Peter Wolf opus...@gmail.com
 
 Check out this email!  IntelliJ is going to get a *really* good plugin
 for Clojure :-D

 I have gladly turned control of the my plugin over to Ilya, and the code
 has been moved to the JetBrains SVN.  I will remain involved and fix
 bugs as they are found, but Ilya and his team are adding a real test
 suite, Mac support, and implementing things like the debugger that are
 not currently documented.

 I notice that Ilya has already added lots of new stuff, I am trying it
 now.

 There is not an release yet, but here is the new code location if you
 want to build it yourself.

 http://svn.jetbrains.org/idea/Trunk/clojure-plugin

 Enjoy (Greatly)
 Peter


Hello, Peter.

I'm going to develop plugin for IntelliJ IDEA for Clojure language.
Talking with Rich I knew about your plugin, which already has parser
and several nice features, based on it withou Program Structure
Interface. To not duplicate code I would like to suggest you to move
your source into JetBrains source repository and continue working on
plugin together. Of course, Clojure plugin will stay open-source
project. Moreover we already have off-the shelf process to build
such projects and perform continuous integartion using our
buildserver TeamCity.
As you might know, I was developing Groovy plugin (wich you took as
a base for your) for two years and now I lead development of Scala
plugin. Main feature of all of them is full interoperability with
main Java support, so I would like to keep it for Clojure too.
So, what do you think about this cooperation? If you agree I'll
submit existing code to our repository and provide commit rights for
you.

With best regards,
Ilya



   
 



   


--~--~-~--~~~---~--~~
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: Newbie: applying arguments into a macro

2009-02-08 Thread samppi

Oh, yeah. Silly me, I *can* do that.

Thanks a lot. It works like a charm now.

On Feb 8, 2:17 am, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 08.02.2009 um 00:40 schrieb samppi:



  (defn conc* [tokens  subrules]
   (loop [subrule-queue (seq subrules), remaining-tokens (seq tokens),
  products []]
     (if (nil? subrule-queue)
       [products remaining-tokens]
       (let [[subrule-products subrule-remainder :as subrule-result]
             ((first subrule-queue) remaining-tokens)]
         (when-not (nil? subrule-result)
           (recur (rest subrule-queue) subrule-remainder
                  (conj products subrule-products)))
  (defmacro conc [ subrules]
   `(fn [tokens#]
      (conc* tokens# ~...@subrules)))

  I had another function called factor=:
  (defn factor= [factor subrule]
   (apply conc (replicate factor arg)))

  When I changed conc to a macro, factor= didn't work anymore. Is there
  no way of fixing factor=?

 Why don't you call conc* directly?

 (defn factor= [factor subrule]
    (fn [tokens]
      (apply conc* tokens (replicate factor subrule

 That's another nice example why to pack as much as possible
 into a function, which is then called by the expanded macro
 code.

 Sincerely
 Meikel

  smime.p7s
 5KViewDownload
--~--~-~--~~~---~--~~
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: Discarding entire transactions

2009-02-08 Thread Jeffrey Straszheim
I don't think you can.  There is no rollback function available.

On Sun, Feb 8, 2009 at 12:23 PM, Anand Patil 
anand.prabhakar.pa...@gmail.com wrote:


 Hello again,

 In my application, I'll frequently want to quickly discard all the
 changes made during a transaction involving many refs. I don't want to
 force the refs to roll back to their values at the beginning of the
 transaction, I just want to end the transaction immediately and skip
 the write stage; updates made in other transactions should still
 'stick'. What's the most efficient way to do this?

 Thanks again!
 Anand
 


--~--~-~--~~~---~--~~
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: Discarding entire transactions

2009-02-08 Thread Anand Patil

On Feb 8, 7:29 pm, Shawn Hoover shawn.hoo...@gmail.com wrote:
 On Sun, Feb 8, 2009 at 12:23 PM, Anand Patil 

 anand.prabhakar.pa...@gmail.com wrote:

  Hello again,

  In my application, I'll frequently want to quickly discard all the
  changes made during a transaction involving many refs. I don't want to
  force the refs to roll back to their values at the beginning of the
  transaction, I just want to end the transaction immediately and skip
  the write stage; updates made in other transactions should still
  'stick'. What's the most efficient way to do this?

  Thanks again!
  Anand

 You can abort a transaction by throwing an exception, but in that case all
 refs automatically retain their pre-transaction values. You can't partially
 roll back a transaction, because by definition all changes to refs in a
 transaction occur or none do.

 By the way, what do you mean by other transactions?
   - Transactions running on other threads? Aborting in one thread does not
 affect refs in other threads.
   - Transactions that completed earlier in time on the same thread? Those
 values are not affected by aborting a later transaction.
   - dosync calling dosync on the same on the same thread? Aborting from an
 inner dosync aborts the whole stack of dosyncs in that thread.

I think your first response covers my case. Here's an example of what
I mean:

(def a (ref 1))
(def b (ref 1))

; Do these concurrently, either from separate agents or using pmap
(dosync (commute b error-throwing-fn a))
(dosync (commute a + @b))

I want to have the option to abort the first transaction without
rolling back the second. Based on what you said, if the first
transaction is aborted but the second is not then no matter what a's
value will be 2 and b's value will be 1, correct?

Thanks for the replies,
Anand
--~--~-~--~~~---~--~~
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.contrib.sql connections

2009-02-08 Thread Mark Volkmann

I'm trying to use the sql contrib library to connect to a Postgres
database. It's not clear to me how to specify a username and password.
Here's what I'm trying.

(use 'clojure.contrib.sql)

(let [db-host localhost
  db-name ct
  db-port 5432
  subname (str // db-host : db-port / db-name)]

  (println subname = subname)
  (def db {:classname org.postgresql.Driver ; must be in classpath
   :subprotocol postgresql
   :subname subname
   :username mvolkmann
   :password })
  (with-connection db
(with-query-results rs [select * from ElementType]
  (println rs

The error I get is org.postgresql.util.PSQLException: FATAL: no
PostgreSQL user name specified in startup packet. I think the problem
is that the username and password values in db aren't used by
with-connection unless a DataSource object is specified. However, it
doesn't seem like I should have to create one of those just to connect
to a relational database. Any idea what I'm doing wrong?

-- 
R. Mark Volkmann
Object Computing, Inc.

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



ClassFormatError on compile

2009-02-08 Thread Chas Emerick

I am intermittently getting the following error when I attempt to  
perform an incremental compilation of a set of Clojure source files.   
To be clear, I mean incremental where I've previously compiled the  
sources down to classfiles, then changed one or more source files, and  
then run clojure.lang.Compile over all of the libs in the project,  
which should only compile the changed source files if I understand  
correctly.  Cleaning the project (which deletes the classfiles from  
the old compilation run) and doing a full recompile of all libs works  
succeeds.

- Chas

Exception in thread main java.lang.ClassFormatError: Invalid method  
Code length 105496 in class file com/foo/MyClass__init
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
 at  
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
 at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java: 
288)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java: 
374)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:247)
 at clojure.lang.RT.loadClassForName(RT.java:1512)
 at clojure.lang.RT.load(RT.java:394)
 at clojure.lang.RT.load(RT.java:374)
 at clojure.core$load__4911$fn__4913.invoke(core.clj:3623)
 at clojure.core$load__4911.doInvoke(core.clj:3622)
 at clojure.lang.RestFn.invoke(RestFn.java:413)
 at clojure.core$load_one__4863.invoke(core.clj:3467)
 at clojure.core$compile__4918$fn__4920.invoke(core.clj:3633)
 at clojure.core$compile__4918.invoke(core.clj:3632)
 at clojure.lang.Var.invoke(Var.java:336)
 at clojure.lang.Compile.main(Compile.java:56)

--~--~-~--~~~---~--~~
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: clojure.contrib.sql connections

2009-02-08 Thread Stephen C. Gilardi


On Feb 8, 2009, at 4:04 PM, Mark Volkmann wrote:


The error I get is org.postgresql.util.PSQLException: FATAL: no
PostgreSQL user name specified in startup packet. I think the problem
is that the username and password values in db aren't used by
with-connection unless a DataSource object is specified.


That is not correct. When using the DriverManager parameter set, any  
other keys and values present in db will be passed along to the driver  
as properties.


Based on this:

http://jdbc.postgresql.org/documentation/81/connect.html

it looks like PostgreSQL expects the key for the property identifying  
the user to be user, not username.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: clojure.contrib.sql connections

2009-02-08 Thread Jeffrey Straszheim
Please let us know if this works.

On Sun, Feb 8, 2009 at 4:23 PM, Stephen C. Gilardi squee...@mac.com wrote:


 On Feb 8, 2009, at 4:04 PM, Mark Volkmann wrote:

 The error I get is org.postgresql.util.PSQLException: FATAL: no
 PostgreSQL user name specified in startup packet. I think the problem
 is that the username and password values in db aren't used by
 with-connection unless a DataSource object is specified.


 That is not correct. When using the DriverManager parameter set, any other
 keys and values present in db will be passed along to the driver as
 properties.

 Based on this:

 http://jdbc.postgresql.org/documentation/81/connect.html

 it looks like PostgreSQL expects the key for the property identifying the
 user to be user, not username.

 --Steve



--~--~-~--~~~---~--~~
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: clojure.contrib.sql connections

2009-02-08 Thread Mark Volkmann

On Sun, Feb 8, 2009 at 3:23 PM, Stephen C. Gilardi squee...@mac.com wrote:

 On Feb 8, 2009, at 4:04 PM, Mark Volkmann wrote:

 The error I get is org.postgresql.util.PSQLException: FATAL: no
 PostgreSQL user name specified in startup packet. I think the problem
 is that the username and password values in db aren't used by
 with-connection unless a DataSource object is specified.

 That is not correct. When using the DriverManager parameter set, any other
 keys and values present in db will be passed along to the driver as
 properties.
 Based on this:
 http://jdbc.postgresql.org/documentation/81/connect.html
 it looks like PostgreSQL expects the key for the property identifying the
 user to be user, not username.

That worked! Thanks Steve and Jeffrey!

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
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: clojure.contrib.sql connections

2009-02-08 Thread Jeffrey Straszheim
Great!

On Sun, Feb 8, 2009 at 5:05 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote:


 On Sun, Feb 8, 2009 at 3:23 PM, Stephen C. Gilardi squee...@mac.com
 wrote:
 
  On Feb 8, 2009, at 4:04 PM, Mark Volkmann wrote:
 
  The error I get is org.postgresql.util.PSQLException: FATAL: no
  PostgreSQL user name specified in startup packet. I think the problem
  is that the username and password values in db aren't used by
  with-connection unless a DataSource object is specified.
 
  That is not correct. When using the DriverManager parameter set, any
 other
  keys and values present in db will be passed along to the driver as
  properties.
  Based on this:
  http://jdbc.postgresql.org/documentation/81/connect.html
  it looks like PostgreSQL expects the key for the property identifying the
  user to be user, not username.

 That worked! Thanks Steve and Jeffrey!

 --
 R. Mark Volkmann
 Object Computing, Inc.

 


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



Am I holding on to the head here ?

2009-02-08 Thread Jeffrey Straszheim
I have this piece of code:

(defn- run-work-elements-in-parallel
  Runs a group of work elements in parallel. Returns an extended database.
  [elements database]
  (assert (set elements))
  (let [[rec simp] (separate :recursive elements)
results-simp (pmap #(run-simple-work-element % database) simp)
results-rec (map #(run-recursive-work-element % database) rec)
results (concat results-simp results-rec)]
(preduce union (cons database results

The exact details aren't important.

The let bindings results-simp, results-rec, and results are each a lazy
stream.  They can get quite large.  Assuming preduce can iterate over them,
is binding them in the let statement stopping them from getting garbage
collected?

If so, is the best solution to wrap them in a (fn [] ...) and then use them
like (results)?

Thanks

--~--~-~--~~~---~--~~
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: Am I holding on to the head here ?

2009-02-08 Thread Kevin Downey

I am not sure exactly how preduce differs from normal reduce, but
reduce is not a lazy operation, so it will result in the realization
of a lazy seq passed to it.

On Sun, Feb 8, 2009 at 2:13 PM, Jeffrey Straszheim
straszheimjeff...@gmail.com wrote:
 I have this piece of code:

 (defn- run-work-elements-in-parallel
   Runs a group of work elements in parallel. Returns an extended database.
   [elements database]
   (assert (set elements))
   (let [[rec simp] (separate :recursive elements)
 results-simp (pmap #(run-simple-work-element % database) simp)
 results-rec (map #(run-recursive-work-element % database) rec)
 results (concat results-simp results-rec)]
 (preduce union (cons database results

 The exact details aren't important.

 The let bindings results-simp, results-rec, and results are each a lazy
 stream.  They can get quite large.  Assuming preduce can iterate over them,
 is binding them in the let statement stopping them from getting garbage
 collected?

 If so, is the best solution to wrap them in a (fn [] ...) and then use them
 like (results)?

 Thanks

 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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



contrib sql - with-query-results macro

2009-02-08 Thread Mark Volkmann

The second argument to the with-query-results macro needs to be a
vector containing a query string and optional values to be inserted
into the query if it is parameterized. Would it be difficult to change
this so in the case that the query is not parameterized, a string can
be passed for the second argument instead of a vector containing a
single string?

-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~-~--~~~---~--~~
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: Am I holding on to the head here ?

2009-02-08 Thread Jeffrey Straszheim
You're probably correct, but I'm still interested in the question in the
more general sense.

On Sun, Feb 8, 2009 at 5:17 PM, Kevin Downey redc...@gmail.com wrote:


 I am not sure exactly how preduce differs from normal reduce, but
 reduce is not a lazy operation, so it will result in the realization
 of a lazy seq passed to it.

 On Sun, Feb 8, 2009 at 2:13 PM, Jeffrey Straszheim
 straszheimjeff...@gmail.com wrote:
  I have this piece of code:
 
  (defn- run-work-elements-in-parallel
Runs a group of work elements in parallel. Returns an extended
 database.
[elements database]
(assert (set elements))
(let [[rec simp] (separate :recursive elements)
  results-simp (pmap #(run-simple-work-element % database) simp)
  results-rec (map #(run-recursive-work-element % database) rec)
  results (concat results-simp results-rec)]
  (preduce union (cons database results
 
  The exact details aren't important.
 
  The let bindings results-simp, results-rec, and results are each a lazy
  stream.  They can get quite large.  Assuming preduce can iterate over
 them,
  is binding them in the let statement stopping them from getting garbage
  collected?
 
  If so, is the best solution to wrap them in a (fn [] ...) and then use
 them
  like (results)?
 
  Thanks
 
  
 



 --
 And what is good, Phaedrus,
 And what is not good—
 Need we ask anyone to tell us these things?

 


--~--~-~--~~~---~--~~
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.inspector doesn't work on sets?

2009-02-08 Thread Tim Martin

Hi all,

I was using clojure.inspector in my code, and to my surprise it failed
when I applied it to a structure containing sets. The error message
was that nth is not supported on the type PersistentHashSet. I've
included a trivial patch below that seems to fix the problem.

I'm not sure I understand why this is happening though. The API docs
note that nth works on seqs in O(n) time, and I thought that a set is-
a seq? Explicitly coercing it to a seq seems to work, but what exactly
is going on here? Is a new object being created, or are there any
other efficiency concerns?

Tim

Index: src/clj/clojure/inspector.clj
===
--- src/clj/clojure/inspector.clj   (revision 1252)
+++ src/clj/clojure/inspector.clj   (working copy)
@@ -31,7 +31,9 @@
 (defmethod is-leaf :default [node]
   (atom? node))
 (defmethod get-child :default [parent index]
-  (nth parent index))
+  (if (set? parent)
+(nth (seq parent) index)
+(nth parent index)))
 (defmethod get-child-count :default [parent]
   (count parent))

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



Stack overflow problem

2009-02-08 Thread jodocus

When I learn a new language, one of the programs I like to write as an
excercise is the n-queens problem (http://en.wikipedia.org/wiki/
8_queens). I wrote the program below which runs correctly. Using depth-
first search, I have used it to find the solutions for board sizes up
to 11 (after which it begins taking a lot of time).

But when I use breadth-first search it gives a stack overflow error at
boardsize 7. All recursive calls in the code are done using recur at
tail positions, and it is not clear to me what could otherwise cause
this. Does anyone have a suggestion how to track down the cause of
this stack overflow?

- code 
(def dim 6)
(def numsqrs (* dim dim))
(def queen \*)
(def empty-sqr \.)

;; a state in this program is nothing more
;; than a list of positions on the board

;; returns true when placing a queen on both p1 and p2 is disallowed
(defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

(defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

;; returns a list of all squares where a queen can be placed in given
state
(defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

;; given a state with n queens, returns all possible states with n+1
queens
(defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

(defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

(defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at: %s, 
searched: %d fnd
s (inc n
;(print-state s))
   (recur searchtype (add-children searchtype 
statelist) (inc n)
fnd))
 {:searched n :found found})))

(search :breadth-first)

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



Getting a result from a swing JDialog

2009-02-08 Thread Tim Martin

Hi all,

I was wanting to create a dialog box in a (predominantly command-line)
application where the action of the user on the dialog box is returned
to the code that requested the dialog so we can branch based on the
selection. It seems the most natural way of doing this in a functional
language is to block until the dialog box is closed and then return a
value, rather than messing with mutable state. This fits in well with
what I want to happen in my program.

I can do this quite easily with a JOptionPane, which has the right
semantics for me, and can return a single value to indicate what
option was chosen. So far so good.

However, if I want more control over the layout and content of the
dialog, I seem to be best served by building it myself out of a
JDIalog [1]. I've got code that creates the JDialog and then blocks
until it is closed, which I can control with a button and an
ActionListener in the obvious way. However, the snag is that it
doesn't return the outcome. The interface of JDialog seems to be built
around the idea of having mutable objects and state, and having an
action listener that can mutate the object and a getter method to find
the value assigned in the listener.

I imagine I can get round this by writing a thin wrapper for the
JDialog that will handle the state in Java, but is there a pure
Clojure way to do this kind of thing? [2] If not, is this (unlikely) a
general problem with GUI programming in functional languages or (most
likely, I assume) a paradigm mismatch between Swing and functional
languages. If the latter, would the Clojure community be well-served
by a standard library of shims for making Swing fit better into the
functional mould?

Tim

[1] My experience of Swing is minimal, so I'm ready to be corrected if
this turns out to be terribly naive.

[2] Aside from unscalable hacks like having a package-level mutable
ref that can be updated from within a listener

--~--~-~--~~~---~--~~
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 pipe macro for left-to-right coll streams

2009-02-08 Thread MattH

Hi,
I want to suggest a pipe macro for dealing with collection streams,
as a one-line variation on the built in - macro.

Instead of writing a nested stream like this:
  ; Take the first 3 elements of the odd numbers in the range 1 to
20
  (take 3 (filter odd? (range 1 20)))

you can write this:
  ; Take the range 1 to 20, filter the odd numbers, then take the
first 3
  (pipe (range 1 20) (filter odd?) (take 3))

I think both forms have their place. The piped form seems useful when
you want to emphasise the collection, or when the chain gets very
long. It's also close to how I'd draw the chain on a whiteboard or
describe it in speech, and helps me to reason about the chain from
left to right in small chunks.

The difference with - is this:
(- x (f a b)) = (f x a b)
(pipe x (f a b)) = (f a b x)

The definition is the equivalent of the - macro (defined in
core.clj, line 984), swapping ~@(rest form) ~x to ~x ~@(rest
form):


(defmacro pipe
  Threads the expr through the forms. Inserts x as the
  last item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  last item in second form, etc.
  ([x form] (if (seq? form)
  `(~(first form) ~@(rest form) ~x)
  (list form x)))
  ([x form  more] `(pipe (pipe ~x ~form) ~...@more)))


I've seen pipe written as a function with the use of reader macros, or
as macros built from scratch. I'm putting this one forward because the
tiny change in intention from - is reflected as a tiny delta in the
code.

Cheers,
Matt

--~--~-~--~~~---~--~~
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: Discarding entire transactions

2009-02-08 Thread Dan

 (def a (ref 1))
 (def b (ref 1))

 ; Do these concurrently, either from separate agents or using pmap
 (dosync (commute b error-throwing-fn a))
 (dosync (commute a + @b))

 I want to have the option to abort the first transaction without
 rolling back the second. Based on what you said, if the first
 transaction is aborted but the second is not then no matter what a's
 value will be 2 and b's value will be 1, correct?


That's correct.

--~--~-~--~~~---~--~~
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: Discarding entire transactions

2009-02-08 Thread Dan
On Sun, Feb 8, 2009 at 12:23 PM, Anand Patil 
anand.prabhakar.pa...@gmail.com wrote:


 Hello again,

 In my application, I'll frequently want to quickly discard all the
 changes made during a transaction involving many refs. I don't want to
 force the refs to roll back to their values at the beginning of the
 transaction, I just want to end the transaction immediately and skip
 the write stage; updates made in other transactions should still
 'stick'. What's the most efficient way to do this?

 Thanks again!
 Anand


Refs don't roll back their values to the beginning of the transaction.

Let say I'm moving money from account A to Account B.
Account B has $1000 at the beginning of the transaction.
I'm taking $200 from account A and put it into account B.
Therefore at the end of my transaction account be should have $1200.
However, when the transaction tries to put this result into B it discovers
that it has now $1500 in it.
This mean that another transaction changed the value first.
I clearly can't overwrite this with $1200 otherwise some money would have
disappeared!
So the STM decide the transaction actually never took place. It doesn't
revert B to the beginning of the transaction it  just forgot it computed
$1200.
So the transaction is restarted. This time, it finds out account B should
have $1700. If account B still have $1500 then its value will be updated.

The STM probably already work as you'd wish.

--~--~-~--~~~---~--~~
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: Datalog update

2009-02-08 Thread Jeffrey Straszheim

Stratified negation is working and in trunk.

I have some cool ideas of a simple, but powerful, way to implement
evaluable predicates.  They'll likely make it in by midweek.

The the hard part (magic sets) begins.

On Feb 8, 11:43 am, Jeffrey Straszheim straszheimjeff...@gmail.com
wrote:
 I now have recursive queries working.  My next 3 milestones are stratified
 negation, evaluable predicates, and then some version of magic sets
 optimization.  But now, as long as your queries are non-negated it is
 working.

 http://code.google.com/p/clojure-datalog/
--~--~-~--~~~---~--~~
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: Stack overflow problem

2009-02-08 Thread Jeffrey Straszheim
Perhaps you are forcing a very long lazy list?

Try (.printStackTrace *e)

On Sun, Feb 8, 2009 at 9:41 AM, jodocus rjek...@gmail.com wrote:


 When I learn a new language, one of the programs I like to write as an
 excercise is the n-queens problem (http://en.wikipedia.org/wiki/
 8_queens http://en.wikipedia.org/wiki/%0A8_queens). I wrote the program
 below which runs correctly. Using depth-
 first search, I have used it to find the solutions for board sizes up
 to 11 (after which it begins taking a lot of time).

 But when I use breadth-first search it gives a stack overflow error at
 boardsize 7. All recursive calls in the code are done using recur at
 tail positions, and it is not clear to me what could otherwise cause
 this. Does anyone have a suggestion how to track down the cause of
 this stack overflow?

 - code 
 (def dim 6)
 (def numsqrs (* dim dim))
 (def queen \*)
 (def empty-sqr \.)

 ;; a state in this program is nothing more
 ;; than a list of positions on the board

 ;; returns true when placing a queen on both p1 and p2 is disallowed
 (defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

 (defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

 ;; returns a list of all squares where a queen can be placed in given
 state
 (defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

 ;; given a state with n queens, returns all possible states with n+1
 queens
 (defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

 (defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

 (defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at:
 %s, searched: %d fnd
 s (inc n
 ;(print-state s))
   (recur searchtype (add-children searchtype
 statelist) (inc n)
 fnd))
 {:searched n :found found})))

 (search :breadth-first)

 


--~--~-~--~~~---~--~~
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: Stack overflow problem

2009-02-08 Thread Jeffrey Straszheim
In fact, try this:

(defn add-children [searchtype statelist]
 (let [c (children (first statelist))
   s (rest statelist)]
   (cond
(= searchtype :breadth-first) (doall (concat s c))
(= searchtype :depth-first) (doall (concat c s)


The doall forces the lists then and there.

On Sun, Feb 8, 2009 at 7:56 PM, Jeffrey Straszheim 
straszheimjeff...@gmail.com wrote:

 Perhaps you are forcing a very long lazy list?

 Try (.printStackTrace *e)


 On Sun, Feb 8, 2009 at 9:41 AM, jodocus rjek...@gmail.com wrote:


 When I learn a new language, one of the programs I like to write as an
 excercise is the n-queens problem (http://en.wikipedia.org/wiki/
 8_queens http://en.wikipedia.org/wiki/%0A8_queens). I wrote the program
 below which runs correctly. Using depth-
 first search, I have used it to find the solutions for board sizes up
 to 11 (after which it begins taking a lot of time).

 But when I use breadth-first search it gives a stack overflow error at
 boardsize 7. All recursive calls in the code are done using recur at
 tail positions, and it is not clear to me what could otherwise cause
 this. Does anyone have a suggestion how to track down the cause of
 this stack overflow?

 - code 
 (def dim 6)
 (def numsqrs (* dim dim))
 (def queen \*)
 (def empty-sqr \.)

 ;; a state in this program is nothing more
 ;; than a list of positions on the board

 ;; returns true when placing a queen on both p1 and p2 is disallowed
 (defn conflict? [p1 p2]
  (let [x1 (rem p1 dim)
x2 (rem p2 dim)
y1 (quot p1 dim)
y2 (quot p2 dim)]
(or
 (== x1 x2)
 (== y1 y2)
 ;; diagonals
 (let [dx (- x2 x1)
   dy (- y2 y1)]
   (or (== dx dy)
   (== (- dx) dy))

 (defn remove-conflicted [p ps]
  (remove #(conflict? p %) ps))

 ;; returns a list of all squares where a queen can be placed in given
 state
 (defn get-safe-squares [state]
  (loop [safe (range (inc (first state)) numsqrs), s state]
(when-not (empty? safe)
  (if-not (empty? s)
(recur (remove-conflicted (first s) safe) (rest s))
safe

 ;; given a state with n queens, returns all possible states with n+1
 queens
 (defn children [state]
  (if (empty? state)
(map #(list %) (range numsqrs))
(when ( (count state) dim)
  (map #(conj state %) (get-safe-squares state)

 (defn add-children [searchtype statelist]
  (let [c (children (first statelist))
s (rest statelist)]
(cond
 (= searchtype :breadth-first) (concat s c)
 (= searchtype :depth-first) (concat c s

 (defn search
  ([searchtype] (search searchtype (children ()) 0 0))
  ([searchtype statelist n found]
 (if-not (empty? statelist)
 (let [s (first statelist)
   is-solution (= (count s) dim)
   fnd (if is-solution (inc found) found)]
   (when is-solution
 (println (format Solution: %d, queens at:
 %s, searched: %d fnd
 s (inc n
 ;(print-state s))
   (recur searchtype (add-children searchtype
 statelist) (inc n)
 fnd))
 {:searched n :found found})))

 (search :breadth-first)

 



--~--~-~--~~~---~--~~
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: Getting a result from a swing JDialog

2009-02-08 Thread Jeffrey Straszheim
A JDialog is going to run on the GUI thread and you can't change that.

There are various concurrency tools in Java that will give you what you
want.  The easiest is to wait create a SynchronousQueue.  Check the Java API
docs.

On Sat, Feb 7, 2009 at 6:15 PM, Tim Martin t...@asymptotic.co.uk wrote:


 Hi all,

 I was wanting to create a dialog box in a (predominantly command-line)
 application where the action of the user on the dialog box is returned
 to the code that requested the dialog so we can branch based on the
 selection. It seems the most natural way of doing this in a functional
 language is to block until the dialog box is closed and then return a
 value, rather than messing with mutable state. This fits in well with
 what I want to happen in my program.

 I can do this quite easily with a JOptionPane, which has the right
 semantics for me, and can return a single value to indicate what
 option was chosen. So far so good.

 However, if I want more control over the layout and content of the
 dialog, I seem to be best served by building it myself out of a
 JDIalog [1]. I've got code that creates the JDialog and then blocks
 until it is closed, which I can control with a button and an
 ActionListener in the obvious way. However, the snag is that it
 doesn't return the outcome. The interface of JDialog seems to be built
 around the idea of having mutable objects and state, and having an
 action listener that can mutate the object and a getter method to find
 the value assigned in the listener.

 I imagine I can get round this by writing a thin wrapper for the
 JDialog that will handle the state in Java, but is there a pure
 Clojure way to do this kind of thing? [2] If not, is this (unlikely) a
 general problem with GUI programming in functional languages or (most
 likely, I assume) a paradigm mismatch between Swing and functional
 languages. If the latter, would the Clojure community be well-served
 by a standard library of shims for making Swing fit better into the
 functional mould?

 Tim

 [1] My experience of Swing is minimal, so I'm ready to be corrected if
 this turns out to be terribly naive.

 [2] Aside from unscalable hacks like having a package-level mutable
 ref that can be updated from within a listener

 


--~--~-~--~~~---~--~~
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: print/println vs. pr/prn

2009-02-08 Thread Chouser

On Sun, Feb 8, 2009 at 10:16 AM, Mark Volkmann
r.mark.volkm...@gmail.com wrote:

 I know print and println are intended for human readable output,
 whereas pr and prn produce output that can be read by the Clojure
 reader. I'm trying to find some cases where these differ. So far I've
 only found String where print/println output the value without quotes
 and pr/prn include the quotes. What are some other kinds of objects
 where the output differs?

The only other I see is Character:

user= (prn \tab \x end)
\tab \x end
nil

user= (println \tab \x end)
 x end
nil

--Chouser

--~--~-~--~~~---~--~~
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, Slime and multiple file projects

2009-02-08 Thread Bradbev

Hi folks,
I'm getting to the stage on a Clojure project that I want to start
breaking the code into multiple files.  My primary environment is
Emacs  Slime and interactive development.  Is there a standard way
for me to load all of my project's files into the running VM?
Right now I manually go to each file  load it.  I guess I could also
write a little function that loaded all the files in the correct
order, but if there is an actual framework tool (like ASDF) then I
would try to use that.

Cheers,
Brad
--~--~-~--~~~---~--~~
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: Clojure, Slime and multiple file projects

2009-02-08 Thread mikel



On Feb 9, 1:05 am, Bradbev brad.beveri...@gmail.com wrote:
 Hi folks,
 I'm getting to the stage on a Clojure project that I want to start
 breaking the code into multiple files.  My primary environment is
 Emacs  Slime and interactive development.  Is there a standard way
 for me to load all of my project's files into the running VM?
 Right now I manually go to each file  load it.  I guess I could also
 write a little function that loaded all the files in the correct
 order, but if there is an actual framework tool (like ASDF) then I
 would try to use that.

I use the time-honored lisp-hacker method of building a load-file. I
have a clojure source file that sits at the root of a project, named
build.clj. It contains a few simple functions that load project files
in order. As I get  closer to deployment, I start work on functions to
build the reployable versions of things.

If you want something more like make or ant or ASDF, you might look at
Lancet, from the Programming Clojure book. I haven't used it, but I do
belevei it's intended to scrath your itch.



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