Re: Why is the compiler more strict on one of my machines?

2013-04-16 Thread Jim foo.bar
It sounds to me that you forgot to run 'lein clean' at work, leaving 
certain classfiles present in 'target'. This would explain why you got 
your uberjar at work but not at home (presumably .class files are being 
ignored by git)


Jim


On 16/04/13 13:59, larry google groups wrote:

I have a Mac at work and I have a Mac at home. At work, while working
on my project, I decided to delete my file "validation.clj". There was
still a reference to it in the ns declaration in import_data.clj, but
I did not know that. I ran "lein uberjar" and everything compiled. I
did not use any functions in import_data.clj, but the app seemed to
run. Then I did:

git add .
git comment -m "some comment"
git push origin master

Then I got home and did "git pull origin master".

Then I ran "lein uberjar" and got a compile error because of the ns
declaration in import_data.clj.

Why would one compiler be more strict than the other? Could I have set
some config variable that I've now forgotten about?



--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




nice Clojure at Nokia talk

2013-04-12 Thread Jim foo.bar

Nice talk :)

http://skillsmatter.com/podcast/scala/clojure-at-nokia-entertainment/wd-23

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: defrecord and namespace-qualified symbols

2013-04-10 Thread Jim foo.bar

On 10/04/13 14:03, Simon Katz wrote:
Second, Clojure supports namespace-qualified keywords, presumably 
because it's possible that different libraries might want to use the 
same keyword for different purposes.


I don't think that is the reason for having namespace-qualified 
keywords...different libraries might want to use the same keyword for 
different purposes and that is fine - no clashes (or at elast I've not 
understood what you mean).


It's my understanding that ::foo has (or should have) actual 'meaning' 
in whatever namespace it exists whereas :foo doesn’t really have any 
'meaning'.


I don't really think you want to access your record fields with a 
namespace-qualified keyword, do you? How would that work exactly? what 
if you got an instance of the record outside the namespace where the 
namespace-qualified keyword is defined? It doesn't make sense to me at 
all...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Something goofy you can do in Clojure.

2013-04-09 Thread Jim foo.bar

Hey Mark, don't get paranoid :)... this is all Cedric did!

user=> (def .3 0.4)
#'user/.3
user=> (+ .3 1.7)
2.1

Jim



On 09/04/13 10:46, Mark Engelberg wrote:

What version are you running?

As far as I know, .3 isn't even a valid representation for a number -- 
you'd have to write it as 0.3.  So I'm not sure where you're running 
that code snippet such that you don't get an immediate error.


On 1.5.1:

=> (+ 0.3 1.7)
2.0

That said, I think most programmers know that floating point 
representations of numbers are inexact.  That's why, if you care about 
exactness, you should write:


=> (+ 0.3M 1.7M)
2.0M

On Tue, Apr 9, 2013 at 1:53 AM, Cedric Greevey > wrote:


This may look mildly surprising, and suggests one more thing *not*
to ever do in production code:

user=> (+ .3 1.7)
2.1
user=>

:)

Shouldn't be hard to figure out how to put a repl in a state where
that expression will evaluate to that result. I'm sure
mathematicians everywhere are deeply offended by the clojure
reader now. :)

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.



--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using update-in to produce vectors from nothing

2013-04-05 Thread Jim foo.bar

aaa Laurent beat me to it! :)

it seems we both understood the same thing so fnil is indeed your friend...

Jim


On 05/04/13 12:29, Jim foo.bar wrote:

if I understood correctly you're looking for 'fnil' :

=>(update-in {} [:foo :bar] (fnil conj []) :a :b :c)
{:foo {:bar [:a :b :c]}}

Jim


On 05/04/13 12:25, Simon Katz wrote:

Hi.

Is there an idiomatic way to have update-in create a vector when the 
supplied keys do not already exist? (Or maybe I should use something 
other than update-in?)


For example...

This gives me a sequence of things in the reverse of the order I want:

(update-in {} [:foo :bar] conj :a)
;; => {:foo {:bar (:a)}}

(update-in *1 [:foo :bar] conj :b)
;; => {:foo {:bar (:b :a)}}

This does what I want, but at the expense of creating a new vector 
each time:


(update-in {} [:foo :bar] (comp vec conj) :a)
;; => {:foo {:bar [:a]}}

(update-in *1 [:foo :bar] (comp vec conj) :b)
;; => {:foo {:bar [:a :b]}}

(I know about laziness and structure sharing, and that this expense 
may not be large.)


The following works, but at the expense of a new function that the 
reader has to understand:


(defn conj-vec
  "Like conj, but returns a vector if coll is empty.
   Useful in conjunction with update-in."
  [coll x]
  (if (empty? coll) [x] (conj coll x)))

(update-in {} [:foo :bar] conj-vec :a)
;; => {:foo {:bar [:a]}}

(update-in *1 [:foo :bar] conj-vec :b)
;; => {:foo {:bar [:a :b]}}

Is there a better way?
--
--
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 unsubscribe from this group and stop receiving emails from it, 
send an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.






--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using update-in to produce vectors from nothing

2013-04-05 Thread Jim foo.bar

if I understood correctly you're looking for 'fnil' :

=>(update-in {} [:foo :bar] (fnil conj []) :a :b :c)
{:foo {:bar [:a :b :c]}}

Jim


On 05/04/13 12:25, Simon Katz wrote:

Hi.

Is there an idiomatic way to have update-in create a vector when the 
supplied keys do not already exist? (Or maybe I should use something 
other than update-in?)


For example...

This gives me a sequence of things in the reverse of the order I want:

(update-in {} [:foo :bar] conj :a)
;; => {:foo {:bar (:a)}}

(update-in *1 [:foo :bar] conj :b)
;; => {:foo {:bar (:b :a)}}

This does what I want, but at the expense of creating a new vector 
each time:


(update-in {} [:foo :bar] (comp vec conj) :a)
;; => {:foo {:bar [:a]}}

(update-in *1 [:foo :bar] (comp vec conj) :b)
;; => {:foo {:bar [:a :b]}}

(I know about laziness and structure sharing, and that this expense 
may not be large.)


The following works, but at the expense of a new function that the 
reader has to understand:


(defn conj-vec
  "Like conj, but returns a vector if coll is empty.
   Useful in conjunction with update-in."
  [coll x]
  (if (empty? coll) [x] (conj coll x)))

(update-in {} [:foo :bar] conj-vec :a)
;; => {:foo {:bar [:a]}}

(update-in *1 [:foo :bar] conj-vec :b)
;; => {:foo {:bar [:a :b]}}

Is there a better way?
--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Apply elements in a vector as arguments to function

2013-03-27 Thread Jim foo.bar

On 27/03/13 03:13, Michael Klishin wrote:
Complain loudly to maintainers on this list that their documentation 
has gaps and they should
clarify this and that. The idea that people should read the source to 
get reasonably straightforward

stuff done is wrong and does a lot of long term damage to the community.



what I really meant was that both of us (Ryan and me) would have 
benefited by looking at the sources. It would have been immediately 
clear that 'fields' expects a vector argumentI even rushed to infer 
what the fn expects which proved wrong 2 minutes later!


In any case, for me, reading the sources has always helped...in fact, 
unless you read/study the sources there is no way to make meaningful 
comments/corrections about a library. Yes, the docs should always be 
clear with regards to usage but being able to consult the source 
relatively easily, is invaluable (at least for me)...


Jim

ps: by no means I meant "read the source before posting here"...my 
comment was closer to "read the sources - it's good for you - you'll 
learn stuff and potentially save time & effort" :)


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: cannot get more than 94 fibonacci numbers -> integer overflow

2013-03-25 Thread Jim foo.bar

Cool, thanks guys :)

Jim


On 25/03/13 15:34, David Powell wrote:



On Mon, Mar 25, 2013 at 3:24 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


On 25/03/13 15:22, Ben Wolfson wrote:

The 94th fibonacci number is greater than Long/MAX_VALUE, so it
overflows. It is using longs.


I seeshouldn't Clojure auto-promote it to a BigInt then?


It doesn't by default.

There are two options:

a) artithmetic is polymorphic, and given a bigint argument, will use 
bigint arithmetic, so use 0N as suggested.


b) use the auto-promoting arithmentic forms: +'  -'  *'  inc'  etc.

Clojure used to do auto-promotion, but it is off by default now as it 
has a significant performance impact.  In Java, a slot can either be a 
primitive or an object, so the auto-promoting forms are forced to box 
primitive objects in java.lang.Long wrappers.



--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: cannot get more than 94 fibonacci numbers -> integer overflow

2013-03-25 Thread Jim foo.bar

On 25/03/13 15:22, Ben Wolfson wrote:

The 94th fibonacci number is greater than Long/MAX_VALUE, so it
overflows. It is using longs.


I seeshouldn't Clojure auto-promote it to a BigInt then?

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




cannot get more than 94 fibonacci numbers -> integer overflow

2013-03-25 Thread Jim foo.bar
I've literally tried all the variations of fibonaci sequences i could 
find! all of them throw an ArithmeticException integer overflow  
clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)

 as soon as I try more than 94 elements!

my favourite version is this (from Christophe Grand ):

(defn fibo-seq "Generates a lazy-seq of all the Fibonacci numbers or up 
to a certain limit."

 ([]  (map first (iterate (fn fib-step [[a b]] [b (+ a b)]) [0 1])))
 ([limit] (take-while #(> limit %) (fibo-seq

Since Clojure prefers longs to ints and since I'm not using any type 
hints, I don't understand why I get an integer overflow...


any ideas?

Jim

ps: this is not 'important', I'm just messing about...

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 25/03/13 12:55, Michael Klishin wrote:

Take a look at https://blogs.oracle.com/jrose/entry/value_types_in_the_vm,
it indicates that there is interest in "true value types" on the JVM 
but at best they will

make it in JDK 9 in 2015.


thanks for thisvery interesting stuff indeed... :)

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 25/03/13 12:50, Shantanu Kumar wrote:
However, I'd consider they are just implementation details and 
intended for idiomatic use from within the Clojure language.


I think you meant "*not* intended for idiomatic use from within the 
Clojure language."


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 25/03/13 12:45, Michael Klishin wrote:


Not sure how strings and numerical types fit into this discussion 
about collection mutability.


I only asked because you said there is no 100% immutability on the JVM. 
I also found this blog-post where Doug Lea joined in for a discussion...


http://www.azulsystems.com/blog/cliff/2011-10-17-writing-to-final-fields-via-reflection

Jim


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 25/03/13 12:28, Michael Klishin wrote:
There is no absolute immutability on the JVM, .NET, in JavaScript. 
There is always a backdoor to mutability.

But 99.9% of projects won't use it.


Andy hinted this last night as well...is this true? if I declare a 
Integer/String object as private & final within a class, is there a way 
to mutate it? I do find this very scary, even in Java as it contradicts 
certain things we take for granted...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 25/03/13 12:08, Michael Klishin wrote:
How often do you see implementation details such as 
PersistentVector#tail used in Clojure code?

That is what matters.


I've never seen that in Clojure code but is 'how responsible a 
programmer is'  what really matters? In other words, are clojure's 
collection persistent by covention (up to the programmer)? I'd argue 
that when you call a collection 'persistent' what matters is 
'persistence' and not 'persistent usage'.


by the same token, when we label something as 'transactional' or 
'atomic' we expect certain properties by default - not by convention...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Concurrency and custom types.

2013-03-25 Thread Jim foo.bar

On 24/03/13 22:59, Andy Fingerhut wrote:
It might not be obvious at first, but Clojure's "immutable" types are 
*not* immutable in the sense of "they cannot be modified in place from 
within the JVM", but only in the sense of "they cannot be modified in 
place by using Clojure's functions alone on them".  This surprised me 
at first when I learned it. For example, try this at a REPL:


user=> (def v [1 2 3])
#'user/v
user=> (class v)
clojure.lang.PersistentVector
user=> v
[1 2 3]
user=> (aset (.tail v) 1 -2)
-2
user=> v
[1 -2 3]



OMG! I read your message very quickly late last night and honestly I 
thought you were pulling my leg...I just tried this at a repl though, 
and you're indeed right...Am I the only one who finds this slightly 
disturbing? For almost 4 years, I've been hearing of how beautifully 
immutable (and performant) clojure's data-structures are. Being able to 
modify a vector in-place contradicts all that doesn't it? How can 
something be immutable when it exposes a public field (.tail) that can 
be mutated in place? Why is tail public anyway?


I feel like the ground has disappeared right under my feet...All the 
beautiful characteristics/properties of clojrue's collections seem to go 
hand in hand with proper usage rather than enforced immutability. Even 
though that is a 'win', it's not a big one since one can argue that an 
arraylist which is not mutated in place can serves the purpose equally 
good...


Moreover, consider the following scenario:

-someone has heard about clojure's collections and wants to use them 
from Java.
-he opens up his favourite IDE, imports Clojure and starts using a 
persistent vector-let's call it 'v'.
-he types 'v.' and the IDE autocomplete feature immediately comes up 
with suggestions.
-he immediately notices that .tail is accessible and assumes that this 
is the proper way of 'updating' the vector.

-now, the persistence has disappeared completely hasn't it?

what is the point in that? Why do we call it 'persistent' when the 
persistence is only guaranteed through proper usage? Isn't an arraylist 
persistent if I use it as such?


I am seriously puzzled...I gave a presentation about Clojure last year 
at Manchester University and the thing I spent the most time on was the 
foundation of Clojure - its data-structures. I basically concluded that 
this is the 1 thing in Clojure that essentially makes everything else 
play nicely... I feel slightly 'betrayed' now...ok 'betrayed' may be a 
bit of a stretch but you get the idea...I can no longer claim that 
Clojure's collections are values, can I?


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: ANN: Illegal Argument podcast on Typed Clojure

2013-03-21 Thread Jim foo.bar

thanks guys! I enjoyed this.. :)

Jim


On 21/03/13 08:32, Mark Derricutt wrote:

Hey all,

We couldn't let everyone at Clojure/West have all the fun so our 
latest podcast is an awesome chat with Ambrose Bonnaire Sergeant all 
about Typed Clojure.


http://illegalargument.com/illegal-argument-episode-98-typed-clojure

Enjoy.

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Apparent interaction of libraries with lein

2013-03-14 Thread Jim foo.bar
Could it be that you're using lein1 instead of lein2? Is lein1 still 
actively maintained? In any case I suggest you upgrade to lein2...


Jim


On 14/03/13 12:48, Nico Swart wrote:

The Leiningen project file I use include these dependancies:

(defproject fb20try "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.4.0"]
 [org.clojure/clojure-contrib "1.2.0"]
 [dds/ndds "1.0"]
 [quil "1.6.0"]]
  :dev-dependencies [[swank-clojure "1.4.2"]])

[dds/ndds "1.0"] is a third part library that I installed in my local 
maven repository with the command


mvn install:install-file -Dfile=nddsjava.jar -DgroupId=dds 
-DartifactId=ndds -Dversion=1.0 -Dpackaging=jar
Everything works well if  [quil "1.6.0"] is not included. If it is 
included, I get this error when the project is loaded:


C:\Clojure\lein\fb20try>lein repl
REPL started; server listening on localhost port 24467
user=> (use 'dyndata.model.ddsdata)
The library nddsjava.dll could not be loaded by Windows.
Make sure that the library is in your Path environment variable.
UnsatisfiedLinkError no nddsjava in java.library.path 
 java.lang.ClassLoader.loadLibrary (ClassLoader.java:1738)


Can anyone explain why a dll is referenced at all ?

Thanks
Nico
--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: fold over a sequence

2013-03-13 Thread Jim foo.bar

there was a memory leak hence the 1.5.1 release the next day...

Jim

On 13/03/13 14:12, Paul Butcher wrote:
On 13 Mar 2013, at 14:05, "Jim foo.bar" <mailto:jimpil1...@gmail.com>> wrote:



how come your project depends on the problematic version 1.5.0?


1.5.0 is problematic?

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com <mailto:p...@paulbutcher.com>
AIM: paulrabutcher
Skype: paulrabutcher

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: fold over a sequence

2013-03-13 Thread Jim foo.bar

how come your project depends on the problematic version 1.5.0?

Jim

On 13/03/13 14:03, Paul Butcher wrote:

Thanks Stuart - my Contributor Agreement is on its way.

In the meantime, I've published foldable-seq as a library:

https://clojars.org/foldable-seq

I'd be very interested in any feedback on the code or how it works.

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com /
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com 
AIM: paulrabutcher
Skype: paulrabutcher

On 12 Mar 2013, at 21:48, Stuart Sierra > wrote:



See clojure.org/contributing 

it's all there.

On Tuesday, March 12, 2013, Paul Butcher wrote:

On 12 Mar 2013, at 18:26, Stuart Sierra
> wrote:


This might be an interesting contribution to
clojure.core.reducers. I haven't looked at your code in detail,
so I can't say for sure, but being able to do parallel fold over
semi-lazy sequences would be very useful.


I'd be delighted if this (or something like it) could make it
into clojure.core.reducers, Stuart. What would I need to do to
make this happen?

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com /
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com 
AIM: paulrabutcher
Skype: paulrabutcher


-- 
-- 
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 a topic
in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/clojure/8RKCjF00ukQ/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email
to clojure+unsubscr...@googlegroups.com .
For more options, visit https://groups.google.com/groups/opt_out.



--
--
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 unsubscribe from this group and stop receiving emails from it, 
send an email to clojure+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: What's the point of -> ?

2013-03-11 Thread Jim foo.bar

On 11/03/13 15:08, Dave Kincaid wrote:
I'm with you. I don't like it personally. Every time I come across it 
reading code I have to stop and think about what exactly it does.


I didn't use to like it either but after coding rubik's cube I've come 
to appreciate it more...imagine this:



(-> cube
   (rotate-left)
   (rotate-up)
   ...
   ...
   ...
   ...
   ...
)

In other words when you have serious nesting of similar actions, then it 
does read a lot cleaner...now, having said that, you will find in 
several Clojure books the same thing without any serious nesting (e.g: 
(-> m :some-key (+ 1))). I guess for such occasions it is purely a mater 
of taste...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: fold over a sequence

2013-03-11 Thread Jim foo.bar
I don't think you will be able to do a parallel fold on a lazy-seq which 
is what clojure.data.xml/parse returns. Vectors are the only persistent 
collection that supports parallel fold and something tells me it's 
because they are NOT lazy...


why can't you 'vec' the result of xml/parse and then use fold on that? 
Is it a massive seq?


Jim


On 11/03/13 00:40, Paul Butcher wrote:
As things currently stand, fold can be used on a sequence-based 
reducible collection, but won't be parallel.


I'm currently working on code that processes XML generated by 
clojure.data.xml/parse, and would love to do so in parallel. I can't 
immediately see any reason why it wouldn't be possible to create a 
version of CollFold that takes a sequence and "chunks" it so that it 
can be folded in parallel. Has anyone tried this yet? Is there some 
gotcha lurking to catch me out?


--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com /
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: p...@paulbutcher.com 
AIM: paulrabutcher
Skype: paulrabutcher

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: what on earth is happening?

2013-02-28 Thread Jim foo.bar

On 28/02/13 15:36, Softaddicts wrote:

Hi,

can you post the JVM used, maybe a snippet of the code around line 68,
the dependencies tree (lein deps :tree) and your project.clj ?

With these we can probably find the root cause of this.

Luc P.


Hi Luc,

thanks for your interest but I think I've cracked it...:) the code that 
was causing this is the following record. You will notice that 'deploy' 
delegates to 'run' per component. But then, since a WorkFlow can be a 
Component as well, the 'run' fn should NOT delegate to 'deploy' as it 
will only go round in circles!
So, from what I understand '(deploy this text)' should be '(reduce #(run 
%2 %) text components))' which is basically what 'deploy' does! This is 
in-line with what Marko / Meikel suggested...



(defrecord Workflow [components] ;;a seq of components - the workflow 
can itself be a component

IWorkflow
(getComponents [this] components) ;;just return all components
(appendComponent [this c] (conj (vec components) c))
(addComponent [this pos c] (addC components pos c))
(removeComponent [this pos] (removeC components pos))
(replaceComponent [this pos replacement] (replaceC components pos 
replacement))

(deploy [_ text intermediates?]
((if intermediates? reductions reduce)
(fn [init c] (run c init)) text components))
(deploy [this text] (deploy this text false))
;(deploy [this] (deploy this))
IComponent
(link [this pos other]
(Workflow. (help/link this pos other)))
;(run [this] (deploy this))
(run [this text] (deploy this text) ;(reduce #(run %2 %) text components))
;(run [this text & more] (deploy this text (first more)))
clojure.lang.IFn ;;can act as an fn
(invoke [this arg]
(deploy this arg))
(applyTo [this args]
(apply deploy this args)) ) Jim


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: what on earth is happening?

2013-02-28 Thread Jim foo.bar
WOW! Clojure compiles in parallel? I did not know that!!! I didn't even 
know that was possible since there is a clear class hierarchy that needs 
to be loaded...I must do some reading...


As a side note, I hope you all had a good laugh with my major 
grammar-error (throwed instead of threw)... hehe :)


Jim


On 28/02/13 15:21, Marko Topolnik wrote:
Nondeterministic behavior -> suspect race conditions. Maybe 
compilation was happening concurrently on several threads and the 
resulting bytecode got mangled.


On Thursday, February 28, 2013 4:17:52 PM UTC+1, Jim foo.bar wrote:

On 28/02/13 15:12, Alex Robbins wrote:
> Maybe you are already doing this, but as soon as I get into "This
> doesn't seem possible" territory, I run a "lein clean". That has
> resolved the problem for me several times.

I've got nothing in "/target"...I am not AOT-compiling anything!

I think i found the problem though...There was an invocation on a
protocol method that was being delegated into some other protocol
method
which again was trying to delegate to the first one! This piece of
code
however has been there for almost 3 weeks and this is the 1st day
that
it manifested! Also, I'm nowhere near at understanding why
sometimes it
worked and other times it throwed!

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: what on earth is happening?

2013-02-28 Thread Jim foo.bar

On 28/02/13 15:12, Alex Robbins wrote:
Maybe you are already doing this, but as soon as I get into "This 
doesn't seem possible" territory, I run a "lein clean". That has 
resolved the problem for me several times.


I've got nothing in "/target"...I am not AOT-compiling anything!

I think i found the problem though...There was an invocation on a 
protocol method that was being delegated into some other protocol method 
which again was trying to delegate to the first one! This piece of code 
however has been there for almost 3 weeks and this is the 1st day that 
it manifested! Also, I'm nowhere near at understanding why sometimes it 
worked and other times it throwed!


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: what on earth is happening?

2013-02-28 Thread Jim foo.bar

On 28/02/13 14:34, Marko Topolnik wrote:
So it makes sense that it blows up only when you try to actually run 
the code.


It doesn't low up when I try to run the code...as I said, I can easily 
navigate into any namespace from the repl and run any code that I 
wantso there is no problem compiling /running the actual code. I 
seem to be getting this error at random occasions without changing any 
code This is what's driving me nuts!


2 minutes ago I did:

*> lein2 test hotel_nlp.core *[ALL-GOOD]

lein test hotel_nlp.core

Testing hotel_nlp.core

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

then I did:

*> lein2 test hotel_nlp.helper * [ALL-GOOD]*

*lein test hotel_nlp.helper

Testing hotel_nlp.helper

Ran 7 tests containing 30 assertions.
0 failures, 0 errors.*
*
so it *seems* everything is working fine...However, without changing any 
code:


*>lein2 test hotel_nlp.core hotel_nlp.helper*  [BAD]

Exception in thread "main" java.lang.VerifyError: (class: 
hotel_nlp/concretions/models/Workflow, method: run signature: 
()Ljava/lang/Object;) Unable to pop operand off an empty stack, 
compiling:(hotel_nlp/concretions/models.clj:68:1)


then immediately after I did the same

*>lein2 test hotel_nlp.core hotel_nlp.helper*  [ALL-GOOD]

lein test hotel_nlp.core

Testing hotel_nlp.core

lein test hotel_nlp.helper

Testing hotel_nlp.helper

Ran 7 tests containing 30 assertions.
0 failures, 0 errors.

That is what I mean it occurs at random...Has anyone ever had this before?

@Dave:

You're absolutely right Dave, I should have been be more specific in the 
subject heading. I do apologise though on behalf of my frustration which 
is to blame for this! It won't happen again


Jim




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




what on earth is happening?

2013-02-28 Thread Jim foo.bar

I've got a project

1. I can /'lein2 repl'/ in it and navigate to any namespace - no problem
2. I can /'lein2 check'/ it and it compiles everything  - no problem
3. I can /'lein2 test'/ or /'lein2 test some-namespace'/ and BOOM!  -
   *PROBLEM! *


*Exception in thread "main" java.lang.VerifyError: (class: 
hotel_nlp/concretions/models/Workflow, method: run signature: 
()Ljava/lang/Object;) Unable to pop operand off an empty stack, 
compiling:(hotel_nlp/concretions/models.clj:68:1)*


*
*What on earth does that mean? I've never had that before!!! The 
'models' namespace has not been modified for 3 days now so it can't be 
the culprit! The thing is I don't understand the error message!


anyone? going slightly mental here!

To add to the confusion, sometimes the same thing happens with 'lein2 
repl' + 'load' but only *some* times. Most times it doesn't complain !   
I'm not AOT-ing...



Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar

On 27/02/13 13:10, Marko Topolnik wrote:
A side note: since /spans?/ is a constant within the /map/ transform, 
it would pay to decide up-front which function to use:


nice catch!

Jim

ps: thanks a lot for your comments :)

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar

On 27/02/13 12:52, Marko Topolnik wrote:

In this line:

(map (if even? (fn [num _] (identity spans)) str)  some-seq1 some-seq2)

you appear to involve /identity/ in a way that makes no sense since 
(identity spans) is just spans. You also don't involve the 
/num/ argument at all; but maybe you meant


Ooops!
I do apologize cos in my effort to provide a minimal example I 
copy-pasted wrongly! The actual code looks like this:


(let [tok-array (into-array ^String token-seq)]
(map
 #((if spans? (fn [span _] span) spans->strings) ;;decide what fn to use
 (.find this tok-array) tok-array)
token-seq)

As you can see I am sort of creating my own version of identity (fn 
[span _] span) because I cannot use 'identity' with 2 args. This is my 
use-case...It should make sense now yes?


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar

On 27/02/13 12:35, Marko Topolnik wrote:
it is a function that transforms its argument into itself. It is 
useful in the context of higher-order functions where it plays the 
role of a no-op


that is exactly what I'm trying to do..a no-op based on some 
condition...Though, I can see why  it would be confusing to just return 
the first arg...what exactly makes no sense?


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar
thinking about it a bit more, it would certainly make sense to return a 
seq with all the identities. Then I can just ask for the first...hmm 
interesting :)


Jim


On 27/02/13 12:20, Jim foo.bar wrote:

On 27/02/13 12:12, Chris Ford wrote:

Can you give an example use case?


sure... sometimes I do something this:

(map (if even? (fn [num _] (identity spans)) str)  some-seq1 some-seq2)

but I'd like to write this instead:

(map (if even? identity str)  some-seq1 some-seq2)

Personally, I would be a little surprised to find out that identity 
worked like this. After all, why return the first argument, why not 
the last? Or a vector of all the arguments?


the idea is to we keep the same semantics as we currently have...

Jim





--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar

On 27/02/13 12:12, Chris Ford wrote:

Can you give an example use case?


sure... sometimes I do something this:

(map (if even? (fn [num _] (identity spans)) str)  some-seq1 some-seq2)

but I'd like to write this instead:

(map (if even? identity str)  some-seq1 some-seq2)

Personally, I would be a little surprised to find out that identity 
worked like this. After all, why return the first argument, why not 
the last? Or a vector of all the arguments?


the idea is to we keep the same semantics as we currently have...

Jim



--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




wouldn't it make sense for identity to take variadic args?

2013-02-27 Thread Jim foo.bar
I often find myself asking for identity of something but identity takes 
a single argument! Why not have it take as many as one likes but only 
return the identity of the first? I find that very handy...do people agree?


(defn identity
"Returns its argument or its first argument when there are more."
{:added "1.0"
:static true}
([x] x)
([x & more] x))

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

I apologise...this works almost perfectly:

(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c#) "Not a valid IComponent")
  (def ~name c#)))

the only slight problem is the error thrown which has the gensym symbol 
in the flailing condition...Well, I can't have everything can I? :)


Jim

On 21/02/13 14:51, AtKaaZ wrote:
I think the assert is working but either something eats up the thrown 
exception silently which would explain why def isn't reached, OR the 
defcomponent is never called, OR it is called with a different name 
param as you'd have expected. Try putting something before the assert 
to log if that point was ever reached.



On Thu, Feb 21, 2013 at 3:29 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


oops major typo! the correct is:


(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c#) "Not a valid IComponent")
  (def ~name c#)))

However, this doesn't work! Something weird with the
assertion...If I comment it out it works as expected, otherwise
the var is unbound at the end! strange stuffI may end up using
'eval' as I used to...

Jim



On 21/02/13 14:20, Jim foo.bar wrote:

I settled for:

(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c# "Not a valid IComponent"))
  (def ~name c#)))

Jim

On 21/02/13 14:18, AtKaaZ wrote:

that one doesn't actually work, maybe, not sure why exactly but
the assert is ignored

=> (def component? number?)
#'runtime.q/component?

=> (defmacro defcomponent [name co]
`(assert (component? ~co) "Not a valid IComponent")
`(def ~name ~co))
#'runtime.q/defcomponent

=> (defcomponent a "a")
#'runtime.q/a


The `(do ...) one works though,
=> (defmacro a []
 `(println 1)
 `(println 2)
 )
#'runtime.q/a
=> (a)
2
nil

=> (defmacro a []
 `(do
(println 1)
        (println 2)
)
 )
#'runtime.q/a
=> (a)
1
2
nil




On Thu, Feb 21, 2013 at 3:14 PM, Jim foo.bar
mailto:jimpil1...@gmail.com>> wrote:

I tried this and it works, but I need 2 backticks and I'm
essentially generating the assert-form when the macro is
called...I'd like to generate only the def-form at run-time...

(defmacro defcomponent [name co]
  `(assert (component? ~co) "Not a valid IComponent")
  `(def ~name ~co))

it looks ugly doesn't it?

Jim




On 21/02/13 14:11, AtKaaZ wrote:

or you could place the assert inside the backquote


On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar
mailto:jimpil1...@gmail.com>> wrote:

On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but
preferably without the 'eval' inside the assertion
form:

(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid
IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I
pass a var in...However if I pass in something like
(String. "jam") it is not being evaluated and thus
is a list not an object...and it will never satisfy
IComponent.

any thoughts?
thanks in advance :)

Jim



I could have phrased this better...One of my arguments
has to NOT be evaluated (name) but the other needs to
be evaluated (co) so I can assert whatever I want to
assert on it...I cannot use 'defn' (it will cause
'name' to be evaluated) so my only option is a macro
that forces eval on the second arg, yes?


Jim

-- 
-- 
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 <mailto: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
<mailto:clojure%2bunsubscr...@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 "

Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar
Moreover, now the exception thrown when the validation fails is not very 
informative!


IllegalStateException Invalid reference state clojure.lang.ARef.validate 
(ARef.java:33)


assert let's you speciy the message you want that is why I preferred it...

Jim





On 21/02/13 14:56, Jim foo.bar wrote:
Yes you're right, this does the trick...However now I've ended up 
unquoting 'name' 3 times! I'm pretty sure this not a good practice in 
general, is it? On the other hand I cannot use 'gensym' cos I want the 
name intact or later access...hmmm...I never expected this would be so 
confusing!


Jim


On 21/02/13 14:52, Meikel Brandmeyer (kotarak) wrote:

Then simply add a (var ~name) as last statement in the do.

Kind regards
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
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 unsubscribe from this group and stop receiving emails from it, 
send an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.






--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar
Yes you're right, this does the trick...However now I've ended up 
unquoting 'name' 3 times! I'm pretty sure this not a good practice in 
general, is it? On the other hand I cannot use 'gensym' cos I want the 
name intact or later access...hmmm...I never expected this would be so 
confusing!


Jim


On 21/02/13 14:52, Meikel Brandmeyer (kotarak) wrote:

Then simply add a (var ~name) as last statement in the do.

Kind regards
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
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

Hi Meikel,

This seems to work but returns nil and so you can't see that a new var 
has been defined!


cluja.core=> (defcomponent maxent-person maxent)
nil
cluja.core=> maxent-person ;;was it defined?
# ;;yes it was!

Jim


On 21/02/13 14:42, Meikel Brandmeyer (kotarak) wrote:

(defmacro defcomponent
  [name co]
  `(do
 (def ~name ~co)
 (set-validator! (var ~name) component?)))

Maybe like this? (Untested)

Kind regards
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
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

oops major typo! the correct is:

(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c#) "Not a valid IComponent")
  (def ~name c#)))

However, this doesn't work! Something weird with the assertion...If I 
comment it out it works as expected, otherwise the var is unbound at the 
end! strange stuffI may end up using 'eval' as I used to...


Jim


On 21/02/13 14:20, Jim foo.bar wrote:

I settled for:

(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c# "Not a valid IComponent"))
  (def ~name c#)))

Jim

On 21/02/13 14:18, AtKaaZ wrote:
that one doesn't actually work, maybe, not sure why exactly but the 
assert is ignored


=> (def component? number?)
#'runtime.q/component?

=> (defmacro defcomponent [name co]
`(assert (component? ~co) "Not a valid IComponent")
`(def ~name ~co))
#'runtime.q/defcomponent

=> (defcomponent a "a")
#'runtime.q/a


The `(do ...) one works though,
=> (defmacro a []
 `(println 1)
 `(println 2)
 )
#'runtime.q/a
=> (a)
2
nil

=> (defmacro a []
 `(do
(println 1)
    (println 2)
)
 )
#'runtime.q/a
=> (a)
1
2
nil




On Thu, Feb 21, 2013 at 3:14 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


I tried this and it works, but I need 2 backticks and I'm
essentially generating the assert-form when the macro is
called...I'd like to generate only the def-form at run-time...

(defmacro defcomponent [name co]
  `(assert (component? ~co) "Not a valid IComponent")
  `(def ~name ~co))

it looks ugly doesn't it?

Jim




    On 21/02/13 14:11, AtKaaZ wrote:

or you could place the assert inside the backquote


On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar
mailto:jimpil1...@gmail.com>> wrote:

On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but
preferably without the 'eval' inside the assertion form:

(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass
a var in...However if I pass in something like (String.
"jam") it is not being evaluated and thus is a list not
an object...and it will never satisfy IComponent.

any thoughts?
thanks in advance :)

Jim



I could have phrased this better...One of my arguments has
to NOT be evaluated (name) but the other needs to be
evaluated (co) so I can assert whatever I want to assert on
it...I cannot use 'defn' (it will cause 'name' to be
evaluated) so my only option is a macro that forces eval on
the second arg, yes?


Jim

-- 
-- 
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 <mailto: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
<mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails
from it, send an email to
clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>.
For more options, visit
https://groups.google.com/groups/opt_out.





-- 
Please correct me if I'm wrong or incomplete,

even if you think I'll subconsciously hate it.

-- 
-- 
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
<mailto: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
<mailto: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 unsubscribe from this group and stop receiving emails from
it, send an email to clojur

Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

I settled for:

(defmacro defcomponent [name co]
`(let [c# ~co]
  (assert (component? c# "Not a valid IComponent"))
  (def ~name c#)))

Jim

On 21/02/13 14:18, AtKaaZ wrote:
that one doesn't actually work, maybe, not sure why exactly but the 
assert is ignored


=> (def component? number?)
#'runtime.q/component?

=> (defmacro defcomponent [name co]
`(assert (component? ~co) "Not a valid IComponent")
`(def ~name ~co))
#'runtime.q/defcomponent

=> (defcomponent a "a")
#'runtime.q/a


The `(do ...) one works though,
=> (defmacro a []
 `(println 1)
 `(println 2)
 )
#'runtime.q/a
=> (a)
2
nil

=> (defmacro a []
 `(do
(println 1)
(println 2)
)
     )
#'runtime.q/a
=> (a)
1
2
nil




On Thu, Feb 21, 2013 at 3:14 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


I tried this and it works, but I need 2 backticks and I'm
essentially generating the assert-form when the macro is
called...I'd like to generate only the def-form at run-time...

(defmacro defcomponent [name co]
  `(assert (component? ~co) "Not a valid IComponent")
  `(def ~name ~co))

it looks ugly doesn't it?

Jim




On 21/02/13 14:11, AtKaaZ wrote:

or you could place the assert inside the backquote


    On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar
mailto:jimpil1...@gmail.com>> wrote:

On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but
preferably without the 'eval' inside the assertion form:

(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass a
var in...However if I pass in something like (String.
"jam") it is not being evaluated and thus is a list not
an object...and it will never satisfy IComponent.

any thoughts?
thanks in advance :)

Jim



I could have phrased this better...One of my arguments has to
NOT be evaluated (name) but the other needs to be evaluated
(co) so I can assert whatever I want to assert on it...I
cannot use 'defn' (it will cause 'name' to be evaluated) so
my only option is a macro that forces eval on the second arg,
yes?


Jim

-- 
-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from
it, send an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.





-- 
Please correct me if I'm wrong or incomplete,

even if you think I'll subconsciously hate it.

-- 
-- 
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
<mailto: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
<mailto: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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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
<mailto:clojure@googlegroups.com>
Note that posts from new members are m

Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

aaa I see! How can I be so naive some times? ;)

Jim



On 21/02/13 14:15, AtKaaZ wrote:

=> (def component? number?)
#'runtime.q/component?

=> (defmacro defcomponent [name co]
`(do
   (assert (component? ~co) "Not a valid IComponent")
   (def ~name ~co)
   )
)
#'runtime.q/defcomponent

=> (defcomponent a (str "a"))
AssertionError Assert failed: Not a valid IComponent
(runtime.q/component? (str "a"))  runtime.q/eval6570 (NO_SOURCE_FILE:1)

=> (defcomponent a "a")
AssertionError Assert failed: Not a valid IComponent
(runtime.q/component? "a")  runtime.q/eval6572 (NO_SOURCE_FILE:1)
=> (defcomponent a 1)
#'runtime.q/a

=> (defcomponent a (+ 1 3))
#'runtime.q/a




On Thu, Feb 21, 2013 at 3:11 PM, AtKaaZ <mailto:atk...@gmail.com>> wrote:


    or you could place the assert inside the backquote


On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar mailto:jimpil1...@gmail.com>> wrote:

On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but
preferably without the 'eval' inside the assertion form:

(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass a
var in...However if I pass in something like (String.
"jam") it is not being evaluated and thus is a list not an
object...and it will never satisfy IComponent.

any thoughts?
thanks in advance :)

Jim



I could have phrased this better...One of my arguments has to
NOT be evaluated (name) but the other needs to be evaluated
(co) so I can assert whatever I want to assert on it...I
cannot use 'defn' (it will cause 'name' to be evaluated) so my
only option is a macro that forces eval on the second arg, yes?


Jim

-- 
-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from
it, send an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.





-- 
Please correct me if I'm wrong or incomplete,

even if you think I'll subconsciously hate it.




--
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar
I tried this and it works, but I need 2 backticks and I'm essentially 
generating the assert-form when the macro is called...I'd like to 
generate only the def-form at run-time...


(defmacro defcomponent [name co]
`(assert (component? ~co) "Not a valid IComponent")
  `(def ~name ~co))

it looks ugly doesn't it?

Jim



On 21/02/13 14:11, AtKaaZ wrote:

or you could place the assert inside the backquote


On Thu, Feb 21, 2013 at 3:10 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but preferably
without the 'eval' inside the assertion form:

(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass a var
in...However if I pass in something like (String. "jam") it is
not being evaluated and thus is a list not an object...and it
will never satisfy IComponent.

any thoughts?
thanks in advance :)

Jim



I could have phrased this better...One of my arguments has to NOT
be evaluated (name) but the other needs to be evaluated (co) so I
can assert whatever I want to assert on it...I cannot use 'defn'
(it will cause 'name' to be evaluated) so my only option is a
macro that forces eval on the second arg, yes?


Jim

-- 
-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
<mailto:clojure%2bunsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.





--
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

On 21/02/13 14:07, Jim foo.bar wrote:

Hi all,

I''d like to have a macro like the following but preferably without 
the 'eval' inside the assertion form:


(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass a var 
in...However if I pass in something like (String. "jam") it is not 
being evaluated and thus is a list not an object...and it will never 
satisfy IComponent.


any thoughts?
thanks in advance :)

Jim




I could have phrased this better...One of my arguments has to NOT be 
evaluated (name) but the other needs to be evaluated (co) so I can 
assert whatever I want to assert on it...I cannot use 'defn' (it will 
cause 'name' to be evaluated) so my only option is a macro that forces 
eval on the second arg, yes?


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




assertion-forms inside macros without using eval?

2013-02-21 Thread Jim foo.bar

Hi all,

I''d like to have a macro like the following but preferably without the 
'eval' inside the assertion form:


(defmacro defcomponent [name co]
 (assert (component? (eval co)) "Not a valid IComponent")
 `(def ~name ~co))

If I don't use eval, everything works as long as I pass a var 
in...However if I pass in something like (String. "jam") it is not being 
evaluated and thus is a list not an object...and it will never satisfy 
IComponent.


any thoughts?
thanks in advance :)

Jim


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Create map from vector of keywords and other items

2013-02-20 Thread Jim foo.bar
'keycollect-partition' looks sensible and idiomatic to me... perhaps 
juxt can come into play here? Of course, both versions will only work 
with keys as keywords and non-keys as non-keywords. If you use anything 
else other than a keyword for a key or a keyword for an item, both will 
break...


Jim


On 20/02/13 11:50, Stefan Kamphausen wrote:

Hi,

given a vector of the form


  [:key1 1 2 3 :key2 4 :key3 5 6 7]

I wand to create a map collecting the items behind each keyword as a vector 
like this:

  {:key1 [1 2 3]
   :key2 [4]
   :key3 [5 6 7]}

I have already written two functions which achieve this, but neither of them "feels 
good" and I am interested in more elegant and idiomatic solutions.

(defn keycollect-partition [coll]
   (->> coll
(partition-by keyword?)  ; bundle at key
(partition 2); kw + its arg
(map (fn [[[sec] arg]] [sec (vec arg)])) ; destruct the mess
(into {}))) ; make it a map

(defn keycollect-reduce [coll]
   (apply zipmap
  (reduce
   (fn [ac x]
 (if (keyword? x)
   [(conj (first ac) x) (conj (second ac) [])]
   (update-in ac [1 (dec (count (first ac)))] conj x))) [[] []]
   coll)))

Added complexity: My original vector does not yet contain keywords, but I 
construct them in amap  regexp-matching each item and creating a keyword from 
the first group of the match.

Any pointers or ideas appreciated.

Regards,
Stefan

  
--

--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




:use an entire namespace full of protocols or stick with :require?

2013-02-14 Thread Jim foo.bar
I know that using a bare :use in the ns macro is generally frowned upon 
as it provides no hints about what is actually being used...


However, I 've got 2 namespaces 'abstractions.clj' and 
'concretions.clj'...concretions.clj will eventually use all the 
protocols defined in abstractions.clj...at the moment it doesn't but as 
I work through it I want to provide concrete records for *all* the 
protocols...


Should I just go and :use the entire thing or should I stick with 
:require and keep typing 'pro/XXX' a million times? That specific 
namespace is very central to my work...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Puzzle with lazy sequences

2013-02-05 Thread Jim foo.bar


Couldn't the compiler infer that the 2 expressions are identical with 
identical arguments and perform the reduce only once? Basically what the 
programmer would do in a let statement? Would that be too expensive?


Jim

On 05/02/13 15:21, Herwig Hochleitner wrote:
Clojure has a feature called locals clearing, which sets 'coll to nil 
before calling reduce in test1, because the compiler can prove it 
won't be used afterwards.
In test2, coll has to be retained, because reduce is called a second 
time on it.



2013/2/5 N8Dawgrr >


If the head is retained on a lazy sequence we have a potential
memory leak.

I set my JVM memory low, 64mb and ran the following:

user> (defn test1 [coll] (reduce + coll))
#'user/test1
user> (test1 (take 1000 (iterate inc 0)))
499500
user>

Now if we do:

user> (defn test2 [coll] [(reduce + coll) (reduce + coll)])
#'user/test2
user> (test2 (take 1000 (iterate inc 0)))
OutOfMemoryError Java heap space  [trace missing]
user>

Which OOMs as expected. The question is, why doens't the first
example blow up? What magics happening?

I would expect coll which is a function argument to be retained by
the garbage collector and hence blow up.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/groups/opt_out.



--
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: constructing matrix-like structures with list-comprehension

2013-02-05 Thread Jim foo.bar
I do hate writing code on thunderbird!!!  '(< counts 1)'  should 
obviously be '(> ~counts 1)'...


Jim


On 05/02/13 15:03, Jim foo.bar wrote:

Hi all,

I 'm a bit confused with this - I'm trying to think but I can't!!! 
Probably cos I've not had any food yet!
Up till now I thought I could construct matrices with 'for'...So (for 
[i (range 3)] i) gives us a 1d structure (a list)...
(for [i (range 3) j (range 4)] [i j]) gives us a 2d structure (list of 
vectors)


On that basis I wrote the following little macro thinking I'd be bale 
to create matrices with arbitrary dimensions:


(defn matrix [& dim-lengths]
(let [bindings (vec (mapcat #(vector (gensym) `(range ~%)) dim-lengths))
  symbols  (mapv first (partition 2 bindings))
  counts (count symbols)]
  `(for ~bindings  (if (< counts 1) ~symbols (first ~symbols)

Now, even though this expands to the 'for' I want I'm starting to 
think this is not the right approach for matrices...all I get is 2d 
structures regardless of how many dimensions I pass in...


any ideas anyone?

Jim






--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




constructing matrix-like structures with list-comprehension

2013-02-05 Thread Jim foo.bar

Hi all,

I 'm a bit confused with this - I'm trying to think but I can't!!! 
Probably cos I've not had any food yet!
Up till now I thought I could construct matrices with 'for'...So (for [i 
(range 3)] i) gives us a 1d structure (a list)...
(for [i (range 3) j (range 4)] [i j]) gives us a 2d structure (list of 
vectors)


On that basis I wrote the following little macro thinking I'd be bale to 
create matrices with arbitrary dimensions:


(defn matrix [& dim-lengths]
(let [bindings (vec (mapcat #(vector (gensym) `(range ~%)) dim-lengths))
  symbols  (mapv first (partition 2 bindings))
  counts (count symbols)]
  `(for ~bindings  (if (< counts 1) ~symbols (first ~symbols)

Now, even though this expands to the 'for' I want I'm starting to think 
this is not the right approach for matrices...all I get is 2d structures 
regardless of how many dimensions I pass in...


any ideas anyone?

Jim




--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




parallel dynamic-programing?

2013-01-29 Thread Jim foo.bar

Hi all,

I realise this may be a slightly naive question and my implementation is 
certainly naive, however I'd like to see if anyone else has attempted 
anything similar. Of course, by 'dynamic-programming' I 'm not referring 
to dyncamic scope but to the statistical technique which divides 
problems to subproblems and assembles optimal solutions from optimal 
subsolutions.


I recently implemented the smith-waterman algorithm (for local sequence 
allignment) which uses this and since functional D.P. is basically done 
by reducing from within a reduce I thought I'd try using r/reduce  (from 
reducers) instead of plain reduce.


I identified that the single most expensive operation in my algorithm is 
actually building the score-matrix. The fn that does this looks like this:


(defn- fill-scores "Fill the score-matrix."
[locations s1 s2 match mis]
(reduce #(scoring-fn s1 s2 match mis %1 %2) {} locations))

which I  (naively) turned into this:

(defn- fill-scores-par "Fill the score-matrix in parallel."
[locations s1 s2 match mis]
(r/fold (r/monoid (partial merge-with into) hash-map) assoc
(r/reduce #(scoring-fn s1 s2 match mis %1 %2) {} locations)))

Now, you probably have guessed what happensEven though they return 
the same thing, the parallel version takes twice the time than the 
original on a big sequence (23sec vs 11sec)! Observing the cpu, I can 
see certain spikes during the first 5-6 seconds but then all 4 cores 
suddenly become busy until the end! I understand that DP is an 
inherently serial operation (in a non-FP language you do it with nested 
for-loops), but a bit of googling revealed that other people have tried 
parallelising it as well. The most relevant paper is [1] where they use 
a concurrent hash-map and CAS operations (just like atoms in Clojure).


Has anyone else done any research on the matter? Is this something that 
can be done relatively easily with the beautiful reducers library? For 
example I've successfully parallelised minimax (still struggling with 
alpha-beta though) very easily with reducers whereas all the rest 
parallel implementations are ridiculously complex. This is why I thought 
perhaps DP can be easily parallelised with reducers.


Thanks a lot in advance...

Jim

[1] Lock-free Dynamic-Programming (Stivala, Stukey, de la Banda, 
Hermenegido & Wirth )


--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: pool-map - a more disciplined version of pmap on top of executors

2013-01-15 Thread Jim foo.bar

On 15/01/13 13:49, Marko Topolnik wrote:
It's not about futures, but about the way the ExecutorService is 
configured. Clojure's /future-call/ apparently uses the /agent 
send-off pool/, which is an unbounded thread pool executor. So you can 
use the same thing with /Executors/newCachedThreadPool/ or instantiate 
one directly with a constructor, which gives finer-grained control 
over the behavior.


That's more like it!!! /Executors/newCachedThreadPool/ works exactly as 
I 'd want without the risk of overwhelming the system with threads 
(which the fixed-size pool will if I initialize it with (count coll))...


I have used this thread pool before - I can't believe my mind completely 
forgot it! I think this  is the best version of pool-map so far:


(defn pool-map
"A saner, more disciplined version of pmap.
 Submits jobs eagerly but polls for results lazily.
 Don't use if original ordering of 'coll' matters."
[f coll]
 (let [exec (Executors/newCachedThreadPool)
   pool (ExecutorCompletionService. exec)
   futures (doall (for [x coll] (.submit pool #(f x]
(try
 (for [_ futures]  (.. pool take get))
(finally (.shutdown exec)


1. it keeps its semi-lazy nature which is good from memory-allocation
   standpoint
2. will not block small tasks from finishing first (that is the whole
   purpose of this pool)
3. completion service does what its supposed to do
4. the system will recycle threads accordingly

I'm feeling a lot more confident now... :)
Thanks a million Marko!

Jim



--
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: pool-map - a more disciplined version of pmap on top of executors

2013-01-15 Thread Jim foo.bar

On 15/01/13 12:57, Marko Topolnik wrote:
The tasks are waiting in the queue, they are not being executed at 
all. And the time they spend waiting cannot theoretically be a 
function of the time they will take to execute, once they get their 
chance.


a so Java Futures are not the same as Clojure futures then! A 
Clojure future will fire up as soon as you define it yes? If what you 
say is true, then Java Future objects are not the same! I was under the 
impression that as soon as you submit the job and get the Future Object 
back , the actual computation has started already! I was wrong then...


Hmmm... now everything you've said so far makes sense! So we can't have 
our cake and eat it too? What if I grew the size of the pool to (count 
coll) instead of cpu-no? Then there would be no futures waiting for 
their turn but it could have a bad impact on thread-coordination. 
However it seems to work as I previously described and a lot faster!


user=> (time (doall (pool-map #(do (Thread/sleep %) %) dummy-times))) 
;;pool of size: (count coll)

"Elapsed time: 3005.827802 msecs"
(1 2 3 4 6 5 7 8 9 10 3000 3000 3000 3000 3000 3000 3000)


user=> (time (doall (pool-map #(do (Thread/sleep %) %) dummy-times))) 
;;pool of size: cpu-no ->4

"Elapsed time: 12003.958141 msecs"
(3000 3000 3000 3000 3000 3000 10 9 8 7 6 5 4 3 2 1 3000)


Your version of pool-map behaves the same! It takes 4 times less!!! I 
wasn't expecting that improvement at all!




Jim



--
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: pool-map - a more disciplined version of pmap on top of executors

2013-01-15 Thread Jim foo.bar

On 15/01/13 09:25, Marko Topolnik wrote:
The order in which you are polling is not very relevant given the fact 
that /doall/ won't return until *all* futures are realized. It's just 
an internal detail.


I finally fully grasped what you were saying...So yes you're right - as 
long as I'm forcing realisation at the end there is nothing to be 
gained...However, what if I submit jobs eagerly and poll for results 
lazily? Then there must be some some gain from using the completion 
service which will bring back the results in the order they finished 
some basic testing:


(defn pool-map
"A saner, more disciplined version of pmap. Submits jobs eagerly but 
polls for results lazily.

 Don't use if original ordering of 'coll' matters."
[f coll]
 (let [cpu-no (.. Runtime getRuntime availableProcessors)
   exec (java.util.concurrent.Executors/newFixedThreadPool cpu-no)
   pool (java.util.concurrent.ExecutorCompletionService. exec)
   futures (doall (for [x coll] (.submit pool #(f x] ;;submit 
everything up front

(try
 (for [_ futures]  (.. pool take get))
(finally (.shutdown exec)

;;your version is 'pool-map1'
;;weirdly enough 'pool-map1' doesn't behave lazily (even though it has a 
call to 'map'!)!!!



user=> (def dummy-times [3000 10 9 8 7 6 5 4 3 2 1])
#'user/dummy-times
user=> (time  (pmap #(do (Thread/sleep %) %) dummy-times))
"Elapsed time: 16.213366 msecs"
(3000 10 9 8 7 6 5 4 3 2 1);;here you waited 3s before sleeping for 
0.01 s

user=> (time  (pool-map #(do (Thread/sleep %) %) dummy-times))
"Elapsed time: 21.004979 msecs"
(10 9 8 7 6 5 4 3 2 1 3000)  ;;here you've not waited at all - sleeping 
for 3s finished last and is last

user=> (time  (pool-map1 #(do (Thread/sleep %) %) dummy-times))
"Elapsed time: 3008.174631 msecs"  ;;non-lazy?
(3000 10 9 8 7 6 5 4 3 2 1)  ;;again your version will wait for the 
first item to finish before proceeding


I think what you trying to get across  is that the overall timings (if 
we do realise the result) will not differ much as all jobs have to 
finish eventually. In other words,  sleeping for 3 s first and for 1 
later is the same thing as sleeping for 1 s and then for 3 
seconds!...and of course this is generally true! However, there is no 
real benefit waiting for the 1st task  to finish when we don't mind 
about ordering. You 'll get the first item whenever it finishes in 
whatever position...This MUST be good but perhaps it needs to be paired 
with laziness to witness any effect?


aking into account all that was said, /pool-map/ can't offer much more 
than /pmap/. You can't know which tasks will take less time until they 
are already done. It is theoretically impossible to pre-order them 
according to execution time, thereby harvesting the results of the 
fastest ones earlier, eventually promoting total concurrency.


hmmm...so the completion service is useless? It can't be... You say 
that'You can't know which tasks will take less time until they are 
already done' but the way I see it you don't  need to...all you need to 
know at any given time is whether a or some  futures have completed. If 
one has indeed completed you invoke .get for the result. If it hasn't 
finished and you do .get it will block until it finishes just like 
deref-ing in Clojure... I honestly don't see why harvesting the results 
of the fastest ones earlier requires to know the execution times up 
front! As you go along you can ask the futures whether they finished or 
not, can't you?


I am in no way trying to contradict you ,I'm just trying to set things 
straight so we are all on the same page...again thanks for your time and 
comments! :)



Jim


--
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: macro: retrieving metadata for an object bound to a symbol passed as argument

2013-01-14 Thread Jim foo.bar
aaa ok now I understand what you meanI'm really sorry but I hadn't 
read all your original questions. So lets set things straight:


1. should I attach the meta to the object, or to its var? or maybe I 
shouldn't do it at all, and just omit such checks altogether? (but I 
would still like to know how to make it work ;d)

meta-data are always attached on the var if I'm not mistaken...

2. how do I retrieve the meta of an object that is specified by a 
symbol passed to a macro by the user?
the general answer here is that you use ~ inside a syntax-quote to jump 
right out of the quoting which results in evaluating the expression. If 
you're not in a syntax-quoted form then I can only think of 'eval' which 
will resolve the var anyway...


4. in the exception above, the symbol is resolved to the 
clojure.core/name, which is wrong as well; I know I can change the 
symbol name, but I have the feeling that this is not the way to go ;d
I'm not sure how to answer this...I know what t do inside the macro to 
avoid symbol capturing but I'm not sure what to do in the actual 
parameter list of the macro...



So, with all these in place I'd say you're looking for something like this:

(defmacro with-obj [ob]
 (if-let [obj-meta (eval `(meta ~ob))] (println "nice")
   (throw (IllegalArgumentException. (str ob " seems not be our 
object")



Let's see how it works:

user=> (def my-name "JIM")
#'user/my-name
user=> (defrecord NAME [^String s])
user.NAME
user=> (def your-name (NAME. "Wujek" {:surname "Srujek"} nil)) 
;;your-name has meta-data

#'user/your-name
user=>  (macroexpand '(with-obj my-name))
IllegalArgumentException my-name seems not be our object user/with-obj 
(NO_SOURCE_FILE:4)

user=>  (macroexpand '(with-obj your-name))
nice
nil

I think we 're getting there yes? Is this more helpful?

Jim



On 14/01/13 15:46, Wujek Srujek wrote:

When I invoke a macro:
(with-object someobject)
someobject is not evaluated, it is passed as a symbol to the macro. I 
need somehow to get the meta for the object that is hidden behind that 
symbol. So, I won't be passing objects in-line, as you did in your Foo 
example, I will first be doing:

(defobject foo {map of my functions / values})
(with-object foo (some-expressions))

Throwing an exception when meta is not there is one thing what I want 
(the missing part); the printing was just there to make the example 
shorter, it's not actually the real code - I don't need a macro for 
that. In reality, after all checks, there is code generated that 
desctructures the map in a (let) and executes some-expressions in this 
context, making certain bindings available for the expressions. This 
bit works fine, it's just the meta check that doesn't work as I don't 
know how to get the object that the symbol points to (in the macro, 
all I have is just a symbol):


user=> (def somename 17)
#'user/somename
user=> (defmacro testabc [name] (class name))
#'user/testabc
user=> (testabc somename)
clojure.lang.Symbol

When I change the macro like this:
user=> (defmacro testabc [name] name)

the object is returned:
user=> (testabc somename)
17

but it is because after macro expansion the returned symbol resolves 
to the object I set before. I would like to be able to get access to 
that object at macro call time.
But when I come to think about it now, I guess this would be 
impossible? Are the vars available when the macro is called? i.e.:


user=> (def somename 17)
user=> (testabc somename) ; <- in this macro, I need to take the 
'somename' symbol and retrieve value 17 from above - is this possible 
at all?


Thanks for your help,
wujek


On Mon, Jan 14, 2013 at 4:25 PM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


I am not sure I follow...Do you by any chance want the
macro-expansion to lead you directly to one of your two options
(printing or exception)? In this case you can do this:

(defmacro with-obj [ob]
 (if-let [obj-meta (meta ob)] (eval ob) ;not replacing any code
but eval-ing on the fly

   (throw (IllegalArgumentException. (str ob " seems not be our
object")

(defrecord Foo [a b])

user=> (macroexpand '(with-obj "Jim"))
IllegalArgumentException Jim seems not be our object user/with-obj
(NO_SOURCE_FILE:3)
user=> (macroexpand '(with-obj (with-meta (Foo. 'x 'y) {:t 1 :p 2})))
#user.Foo{:a x, :b y}

So now you get the exception or the actual object at
macro-expansion time...Does that help at all?

Jim



On 14/01/13 14:56, Wujek Srujek wrote:

Actually, the with-object mecro is very similar to
clojure.algo.monads/with-monad - it also lets a few bindings,
like m-bind or m-result, and executes user-defined expressi

Re: macro: retrieving metadata for an object bound to a symbol passed as argument

2013-01-14 Thread Jim foo.bar
I am not sure I follow...Do you by any chance want the macro-expansion 
to lead you directly to one of your two options (printing or exception)? 
In this case you can do this:


(defmacro with-obj [ob]
 (if-let [obj-meta (meta ob)] (eval ob) ;not replacing any code but 
eval-ing on the fly
   (throw (IllegalArgumentException. (str ob " seems not be our 
object")


(defrecord Foo [a b])

user=> (macroexpand '(with-obj "Jim"))
IllegalArgumentException Jim seems not be our object user/with-obj 
(NO_SOURCE_FILE:3)

user=> (macroexpand '(with-obj (with-meta (Foo. 'x 'y) {:t 1 :p 2})))
#user.Foo{:a x, :b y}

So now you get the exception or the actual object at macro-expansion 
time...Does that help at all?


Jim


On 14/01/13 14:56, Wujek Srujek wrote:
Actually, the with-object mecro is very similar to 
clojure.algo.monads/with-monad - it also lets a few bindings, like 
m-bind or m-result, and executes user-defined expressions in the 
context of the monad specified by a name. They just don't perform such 
checks, you can call with-monad with any symbol, and you will get an NPE:

user=> (require '[clojure.algo.monads :refer :all])
user=> (domonad identity-m [a 2 b 3] (* a b))
6
user=> (domonad whatever [a 2 b 3] (* a b))
NullPointerException   user/eval1803 (NO_SOURCE_FILE:1)

That's probably because the monad functions set up by with-monad are 
nils. (domonad uses with-monad under the hood.) If I perform my check, 
I will be able to give a much nicer error message, and there is a lot 
value in that.


wujek


On Mon, Jan 14, 2013 at 3:45 PM, Wujek Srujek <mailto:wujek.sru...@gmail.com>> wrote:


Because this is not the whole functionality ;d The check is just a
fragment, the one that doesn't work. There is much more to it,
like taking the object, taking some keys and values and using them
in (let) and then executing some code in this context (which is
another parameter, which is not in my example as I wanted to keep
it simple).
If I could do it with a function, I would of course prefer it, but
    I am not sure if it can work.

wujek


On Mon, Jan 14, 2013 at 3:41 PM, Jim foo.bar mailto:jimpil1...@gmail.com>> wrote:

Why does this have to be a macro? Why can't it be a
first-class function instead?

(defn with-obj [ob]
 (if-let [obj-meta (meta ob)]  name
  (throw (IllegalArgumentException. (str ob " seems not be our
object")

Jim



On 14/01/13 14:34, Jim foo.bar wrote:

Of course you should know that built-in java types do not
support meta-data...You need to  implement IObj in order
to provide meta-data support to your own types...otherwise
use records...

Jim


On 14/01/13 14:32, Jim foo.bar wrote:

On 14/01/13 14:27, wujek.sru...@gmail.com
<mailto:wujek.sru...@gmail.com> wrote:

(defmacro with-obj [name]
 (let [obj-meta (meta name)]
  (if (or (nil? obj-meta)) ; (not (::my-obj
obj-meta)))
   (throw (IllegalArgumentException. (str name "
seems not be our object")
 `(println "nice"))



Try this:


(defmacro with-obj [name]
 `(if-let [obj-meta# (meta ~name)]
(println "nice")
  (throw (IllegalArgumentException. (str ~name " seems
not be our object")

HTH...

Jim




-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from n

Re: macro: retrieving metadata for an object bound to a symbol passed as argument

2013-01-14 Thread Jim foo.bar
Why does this have to be a macro? Why can't it be a first-class function 
instead?


(defn with-obj [ob]
 (if-let [obj-meta (meta ob)]  name
  (throw (IllegalArgumentException. (str ob " seems not be our 
object")


Jim


On 14/01/13 14:34, Jim foo.bar wrote:
Of course you should know that built-in java types do not support 
meta-data...You need to  implement IObj in order to provide meta-data 
support to your own types...otherwise use records...


Jim


On 14/01/13 14:32, Jim foo.bar wrote:

On 14/01/13 14:27, wujek.sru...@gmail.com wrote:

(defmacro with-obj [name]
 (let [obj-meta (meta name)]
  (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta)))
   (throw (IllegalArgumentException. (str name " seems not be our 
object")

 `(println "nice"))




Try this:


(defmacro with-obj [name]
 `(if-let [obj-meta# (meta ~name)]
(println "nice")
  (throw (IllegalArgumentException. (str ~name " seems not be our 
object")


HTH...

Jim






--
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: macro: retrieving metadata for an object bound to a symbol passed as argument

2013-01-14 Thread Jim foo.bar
Of course you should know that built-in java types do not support 
meta-data...You need to  implement IObj in order to provide meta-data 
support to your own types...otherwise use records...


Jim


On 14/01/13 14:32, Jim foo.bar wrote:

On 14/01/13 14:27, wujek.sru...@gmail.com wrote:

(defmacro with-obj [name]
 (let [obj-meta (meta name)]
  (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta)))
   (throw (IllegalArgumentException. (str name " seems not be our 
object")

 `(println "nice"))




Try this:


(defmacro with-obj [name]
 `(if-let [obj-meta# (meta ~name)]
(println "nice")
  (throw (IllegalArgumentException. (str ~name " seems not be our 
object")


HTH...

Jim




--
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: macro: retrieving metadata for an object bound to a symbol passed as argument

2013-01-14 Thread Jim foo.bar

On 14/01/13 14:27, wujek.sru...@gmail.com wrote:

(defmacro with-obj [name]
 (let [obj-meta (meta name)]
  (if (or (nil? obj-meta)) ; (not (::my-obj obj-meta)))
   (throw (IllegalArgumentException. (str name " seems not be our 
object")

 `(println "nice"))




Try this:


(defmacro with-obj [name]
 `(if-let [obj-meta# (meta ~name)]
(println "nice")
  (throw (IllegalArgumentException. (str ~name " seems not be our 
object")


HTH...

Jim


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


replacing specific symbols in arbitrary expressions

2013-01-14 Thread Jim foo.bar

Hi everyone, I hope you're all well!

I recently faced a problem when i needed to receive some piece of code 
and replace all the invalid symbols in it with the proper (existent) 
ones. Imagine for example you have the following map from made-up 
characters to real characters:


(def reserved-chars
(zipmap [\P \M \T]
[\+ \- \*]) )

Now, I'm expecting code that includes the symbols P, M, T  but before 
evaluating that code I need to replace these non-valid symbols with the 
corresponding symbols Clojure knows about (+, -, * respectively). I 
could get around that by def-ing  P, M & T to +, - & * so that Clojure 
knows the symbols when the time comes to eval the fn. However, this 
solution is not ideal when there are many such symbols. My second 
thought was to create a macro that simply transforms the expressions 
replacing all the 'bad' symbols with 'good' ones...This is what I came 
up with:



(defmacro translate [& code]
`(let [code-string# (str '~@code)
   fake-to-real# reserved-chars]
 ;(eval
  (read-string ;;returns persistent-list
   (reduce-kv
 (fn [s# k# v#]
   (.replaceAll ^String s# (str k#) (str v#)))
 code-string# fake-to-real#

As you can probably gather, this macro treats the expression as a string 
and not as data...Even though it runs perfectly fine and gives the 
correct output , I was wondering if any of you macro-gurus has any 
better suggestions or alternativesAlternatively, if you can think of 
any cases that will break my little macro please share them...


thanks in advance...

Jim

--
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: Idiom for transforming a map

2013-01-10 Thread Jim foo.bar

On 10/01/13 12:57, Jonathon McKitrick wrote:

Excellent stuff, guys.  Thanks for the help.

I just got 'Joy of Clojure' and 'Clojure Programming' in the mail 
yesterday so hopefully I'll be up to speed quickly.


no worries...happy reading! :-)

Jim

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


String wrapper that supports meta-data...

2013-01-09 Thread Jim foo.bar

Hi all,

I often find myself wanting to attach meta-data to built-in Java classes 
and particularly to the 'String' class.  In a text-mining and NLP 
context, it is very useful for example to have a dictionary of strings 
where each string 'knows' its synonyms...Of course one can get around 
that by having a giant map from entities to synonyms. However, this adds 
an extra preprocessing step and also Java programmers enjoy this sort of 
encapsulation. Being able to store the synonyms as meta-data in the 
String object itself, essentially means that the object can be queried 
individually with no fuss...I'm not advocating any universally correct 
approaches here... I'm just sharing my experiences and where they led 
me...:-)

Both approaches (map-based, metadata-based) worked just fine...

In case anyone else is struggling to attach meta-data to any built-in 
Java type, here is what I did for the String class (file attached). It 
is very straight forward...basically you need to wrap the object in 
question and implement IObj...


Voila! Now MString instances support meta-data...YAY!

Jim

--
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=enpackage PAnnotator.java;

import clojure.lang.IPersistentMap;
import clojure.lang.IObj;

//a wrapper around the String class that supports Clojure maps as meta-data
public final class MString implements IObj {

	private final String value;
	private final IPersistentMap meta;

	public MString(IPersistentMap meta, String value) {
		this.meta = meta;
		this.value = value;
	}
	public MString(String value) {
		this(null, value);
	}
	
	public String getString(){
	return value;
	}

	public IObj withMeta(IPersistentMap meta) {
		return new MString(meta, value);
	}

	public IPersistentMap meta() {
		return meta;
	}
}


Re: Need ideas for carving project into namespaces

2012-12-12 Thread Jim foo.bar

On 12/12/12 00:16, Mark Engelberg wrote:
I would much prefer to have some sort of core function that serves as 
a polymorphic constructor.  This way users don't need to require the 
concrete implementations individually.


I faced the same sort of issue a couple of months ago. Just like you, I 
wanted end-users to be able to instantiate their own records via a 
polymorphic function in the core ns. In other words, I wanted a way of 
instantiating records by passing only the record name (fully qualified 
of course) and whatever parameters the constructor expects. If i 
understand correctly this is what you're after yes?


There is a simple way of doing this but it is very very slow. Basically 
you need to resort to reflection...Chris Houser had posted such  a 
record-factory fn on StackOverflow a while back. Here it is:


(defn record-factory [recordname]
(let [recordclass ^Class (resolve (symbol recordname))
max-arg-count (apply max (map #(count (.getParameterTypes 
^java.lang.reflect.Constructor %))

(.getConstructors recordclass)))
args (map #(symbol (str "x" %)) (range (- max-arg-count 2)))]
(eval `(fn [~@args] (new ~(symbol recordname) ~@args)

even though i was very excited at the time i saw this, I later decided 
that it's not worth the performance cost for my use-case.


Jim

--
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.string/capitalize API

2012-12-12 Thread Jim foo.bar
There is an easy solution to your problem...Just hange the fn definition 
slightly. For example I am regularly using this:


(defn un-capitalize [^String s]
(let [Cfirst (subs s 0 1)
Crest (subs s 1) ]
(str (.toLowerCase Cfirst) Crest)))


It is pretty obvious what you need to do to convert the above to 
"capitalize" which only capitalises the 1st charater...


I agree that with regards to 'least astonishment' the core fn should 
capitalize all characters. This is what I'd expect from a fn called 
'capitalize'.


Jim


On 12/12/12 14:12, Pierre Allix wrote:

Hello,

The clojure.string/capitalize function is defined as follow:

Converts first character of the string to upper-case, all other
characters to lower-case.
I think it does not followprinciple of least astonishment. I would have 
expected to convert only the first character. Moreover converting the other 
characters make the function almost useless, I for instance had this string to 
capitalize:
"if P is true then do W" which is converted into "If p is true then do w". This 
is not helpful.

Is there a good reason to convert the other characters? Shouldn't this be doneexplicitly by the user? Would it make sense to change the capitalize function in the next versions?  


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

Re: Meaning of "="

2012-12-11 Thread Jim foo.bar

Apologies...I did not realise this had already been answered... oops! :-)


On 11/12/12 13:32, Jim foo.bar wrote:
If you're looking for some truly unintuitive  equality behavior check 
this out:


user=> (def pred (Boolean. false)) ;;not a primitive but an object
#'user/pred
user=> (= pred false)
true
user=> (when pred (println "I really shouldn't print"))
I really shouldn't print
nil


Jim


On 11/12/12 13:19, Jim foo.bar wrote:

From the docs:


Equality. Returns true if x equals y, false if not. Same as
Java x.equals(y) except it also works for nil, and compares
numbers and collections in a type-independent manner. Clojure's 
immutable data

structures define equals() (and thus =) as a value,*not an identity*,
comparison.


hope that helps...

Jim



On 11/12/12 13:17, Jim foo.bar wrote:

I disagree...
One of the nice things about clojrue is that, at tis hear, lies the 
'equiv' operator which is basically the 'egal' fn as defined by 
Baker [1993] [Equal rights for functional objects or the mroe things 
change the more they stay the same]. When using '=' with 
data-structures you are essentially comparing values and not types.


To come back to your example, both are sequential seqs that contain 
the same values in the same order. Why shouldn't they be equal? 
Clojure would not be the language we all love, if they weren't equal...


Jim


On 03/10/12 06:24, Larry Travis wrote:

What is the rationale for this?

user> (=  [1 2 3 4]  '(1 2 3 4))
true

I was quite surprised when this turned out to be the cause of a bug 
in a function I am constructing. Vectors and lists differ so 
substantially in their implementation and in their behavior that a 
vector and a list should not be considered "equal" just because 
they contain the same elements in the same order.


  --Larry










--
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: Meaning of "="

2012-12-11 Thread Jim foo.bar
If you're looking for some truly unintuitive  equality behavior check 
this out:


user=> (def pred (Boolean. false)) ;;not a primitive but an object
#'user/pred
user=> (= pred false)
true
user=> (when pred (println "I really shouldn't print"))
I really shouldn't print
nil


Jim


On 11/12/12 13:19, Jim foo.bar wrote:

From the docs:


Equality. Returns true if x equals y, false if not. Same as
Java x.equals(y) except it also works for nil, and compares
numbers and collections in a type-independent manner. Clojure's 
immutable data

structures define equals() (and thus =) as a value,*not an identity*,
comparison.


hope that helps...

Jim



On 11/12/12 13:17, Jim foo.bar wrote:

I disagree...
One of the nice things about clojrue is that, at tis hear, lies the 
'equiv' operator which is basically the 'egal' fn as defined by Baker 
[1993] [Equal rights for functional objects or the mroe things change 
the more they stay the same]. When using '=' with data-structures you 
are essentially comparing values and not types.


To come back to your example, both are sequential seqs that contain 
the same values in the same order. Why shouldn't they be equal? 
Clojure would not be the language we all love, if they weren't equal...


Jim


On 03/10/12 06:24, Larry Travis wrote:

What is the rationale for this?

user> (=  [1 2 3 4]  '(1 2 3 4))
true

I was quite surprised when this turned out to be the cause of a bug 
in a function I am constructing. Vectors and lists differ so 
substantially in their implementation and in their behavior that a 
vector and a list should not be considered "equal" just because they 
contain the same elements in the same order.


  --Larry








--
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: Meaning of "="

2012-12-11 Thread Jim foo.bar

From the docs:


Equality. Returns true if x equals y, false if not. Same as
Java x.equals(y) except it also works for nil, and compares
numbers and collections in a type-independent manner. Clojure's 
immutable data

structures define equals() (and thus =) as a value,*not an identity*,
comparison.


hope that helps...

Jim



On 11/12/12 13:17, Jim foo.bar wrote:

I disagree...
One of the nice things about clojrue is that, at tis hear, lies the 
'equiv' operator which is basically the 'egal' fn as defined by Baker 
[1993] [Equal rights for functional objects or the mroe things change 
the more they stay the same]. When using '=' with data-structures you 
are essentially comparing values and not types.


To come back to your example, both are sequential seqs that contain 
the same values in the same order. Why shouldn't they be equal? 
Clojure would not be the language we all love, if they weren't equal...


Jim


On 03/10/12 06:24, Larry Travis wrote:

What is the rationale for this?

user> (=  [1 2 3 4]  '(1 2 3 4))
true

I was quite surprised when this turned out to be the cause of a bug 
in a function I am constructing. Vectors and lists differ so 
substantially in their implementation and in their behavior that a 
vector and a list should not be considered "equal" just because they 
contain the same elements in the same order.


  --Larry






--
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: Meaning of "="

2012-12-11 Thread Jim foo.bar

I disagree...
One of the nice things about clojrue is that, at tis hear, lies the 
'equiv' operator which is basically the 'egal' fn as defined by Baker 
[1993] [Equal rights for functional objects or the mroe things change 
the more they stay the same]. When using '=' with data-structures you 
are essentially comparing values and not types.


To come back to your example, both are sequential seqs that contain the 
same values in the same order. Why shouldn't they be equal? Clojure 
would not be the language we all love, if they weren't equal...


Jim


On 03/10/12 06:24, Larry Travis wrote:

What is the rationale for this?

user> (=  [1 2 3 4]  '(1 2 3 4))
true

I was quite surprised when this turned out to be the cause of a bug in 
a function I am constructing. Vectors and lists differ so 
substantially in their implementation and in their behavior that a 
vector and a list should not be considered "equal" just because they 
contain the same elements in the same order.


  --Larry




--
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: seq? vs sequential? vs coll?

2012-11-26 Thread Jim foo.bar

Ooops!!!
No, Mark asked this in his first  post...

sorry for the confusion!

Jim


On 26/11/12 14:31, Philip Potter wrote:

On 26 November 2012 14:27, Jim foo.bar  wrote:

On 26/11/12 14:19, Philip Potter wrote:

Has anyone compiled a little table of what things satisfy which
predicates?

I don't think I wrote this.



--
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: seq? vs sequential? vs coll?

2012-11-26 Thread Jim foo.bar

On 26/11/12 14:19, Philip Potter wrote:

Has anyone compiled a little table of what things satisfy which predicates?


I'm not 100% sure, but I think "Clojure Programming " has a table like 
this...I can confirm as soon as I get back home...


Jim

--
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: seq? vs sequential? vs coll?

2012-11-26 Thread Jim foo.bar
My understanding is that everything (all data-structures) is coll? 
(obviously not strings)

lists and vectors are sequential? (and coll?)
sets  are only coll?
maps are map? (and coll?)


All seq? are sequential?

Yes and also coll?


All sequential? are coll?
Well yeah but not only...all persistent data-structures are coll? which 
means that map? is also coll?


basically coll? is the top-level one, right? It tests whether something 
implements 'Collection' (all clojure data-structures do)


Jim



On 26/11/12 14:01, Mark Engelberg wrote:
I understand that these functions test for different interfaces, but I 
don't have a clear sense for which things respond differently to these 
predicates.  Has anyone compiled a little table of what things satisfy 
which predicates?


So far, I've figured out that although lists, strings, vectors, and 
sets all can seq:

lists are seq?, sequential? and coll?
vectors are not seq?, are sequential? and coll?
sets are not seq? and not sequential?, but are coll?
strings are not seq?, sequential? or coll?

From these examples, it appears that:
All seq? are sequential?
All sequential? are coll?

Is this really true, or have I just not found enough edge cases?

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


Re: core.logic and laziness...

2012-11-22 Thread Jim foo.bar

On 22/11/12 16:25, David Nolen wrote:

core.logic has lazy-run.


ooo thanks a lot!!!

Jim

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


core.logic and laziness...

2012-11-22 Thread Jim foo.bar

Hi all,

this question may sound stupid but I've got to ask it
given a fn like the one below, how would one make it lazy (assuming that 
it can be done)?
also if it can, I'd like to make it fully-lazy (instead of 
chunked-lazy)...any ideas? I remember something about restoring '1 at a 
time' laziness in the 'Joy of Clojure' but I 'm not sure if I rememer 
correctly and I don't have access to the book at the moment (lent it to 
someone for 2 weeks!)...


(def ^:const board (vec (range 8)))

(defn bishop-moves
"Returns the logical moves for a bishop (on a 8x8 grid) given its 
current position and direction."

[x y]
(run* [q]
(fresh [a b]
(membero a board)
(membero b board)
(!= a x)
(!= b y)
(project [x y a b]
(== (Math/abs ^long (- x a))
(Math/abs ^long (- y b)))
(== q [a b])


the reason I want to do this, believe it or not, is performance !!! why 
calculate all the moves if I'm not going to consume them all?it's a 
waste isn't it?



many thanks in advance...

Jim

--
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: feeding leiningen a local JAR file

2012-11-21 Thread Jim foo.bar

On 21/11/12 11:47, Dick Davies wrote:

Also, is it possible to 'override' a given dependency to favour a local JAR
over the 'official' maven one?


just install the jar into your local maven repo (~/.m2/) (with 
identifiable name)  and then pull it from whatever project you want. I 
think Leiningen will look first in your .m2 dir and only if it cannot 
find the jar it will ask maven, clojars etc etc...am I right?


Jim

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


deserialising records from Swing...

2012-11-21 Thread Jim foo.bar

Hi all,

I discovered yesterday that records cannot be deserialised from the EDT 
using the normal way (prn/read-string)...

NoClassDefFound Exception

trying the same thing from a bare repl (no swing), works just fine!!! 
Googling "deserialisng clojure records" pointed me to [1] where Stuart 
Sierra suggests (quite recently) binding *use-context-classloader*  to 
false or have an agent do the actual work...I'm going to try both as 
soon as I get back home...at the moment I'm just trying to understand 
what goes wrong and what *use-context-classloader* does...


Can anyone help?

Jim


[1] http://grokbase.com/t/gg/clojure/125v358eng/deserialization-of-a-record


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


defpromise?

2012-11-20 Thread Jim foo.bar
I was just wondering...we have a 'defsomething' macro for almost 
everything...


How come there is no 'defpromise'? It is very easy to write one and 
since we always initialize promises like this: (def x (promise)), I 
don't see any reason why not...


(defmacro defpromise [name]
  `(def ~name (promise)))

Jim


--
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: Edit/write Clojure code on Android

2012-11-20 Thread Jim foo.bar
The problem with that is that it will only work if there are no external 
dependencies! As long as your code depends only on clojure 1.4 it's all 
good...this is very unlikely though for a descent sized project...


Jim


On 20/11/12 16:14, Nenad Seke wrote:
You can write your clojure code in some editor and then evaluate that 
code from REPL with load-file function.


On 11/20/2012 4:43 PM, Nico Balestra wrote:

Hi there,
as per the subject of this email, supposing that I want to edit, 
write and potentially run a Clojure app on an Android device (Nexus 
7), is there any way to achieve this or should I stop looking for the 
right Android app on the market?
Unfortunately the Clojure REPL distributed by Sattvik software & 
technology doesn't support editing files (of course.. it's a REPL :) )


Any idea would be more than welcome given that I bought my nexus 7 
mainly for this :)


Thanks,
Nico
--
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 


--
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: question concerning macros by a newbie

2012-11-13 Thread Jim foo.bar
You can't convert to keyword simply by (str ":" (str (first 
components))...you need the (keyword (first components))...also why is 
your argument (symbol "obj")? I'd prefer obj# or (gensym obj)...


Jim

On 13/11/12 10:06, Johannes wrote:

Hi,

I define a record
(defrecord point [x y])

and the following macro:

(defmacro drg
  [typename components]
  `(def ~(symbol (str typename "-" (str (first components
 (fn [~(symbol "obj")] (get ~(symbol "obj") ~(symbol (str ":" (str 
(first components


the call
user> (macroexpand-1 '(drg point [x y]))

delivers what I expect:
(def point-x (clojure.core/fn [obj] (clojure.core/get obj :x)))

Evalutating this expression at the repl delivers what I expect:
user> (def point-x (clojure.core/fn [obj] (clojure.core/get obj :x)))
#'user/point-x

But calling the macro results in an error message:
user> (drg point [x y])
CompilerException java.lang.RuntimeException: Unable to resolve 
symbol: :x in this context, compiling:(NO_SOURCE_PATH:1)


Can anyone tell me what my mistake is?

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


Re: [Ann] Kibit 0.0.6

2012-11-12 Thread Jim foo.bar
Thank you Bronza...this is exactly what I meant! when using reducers 
'into' is the norm isn't it?
Couldn't kibit parse the ns declaration before it starts suggesting 
things? It seems that at least for namespaces that use core.logic or 
reducers kibit's suggestions will break your code! For example it keeps 
suggesting (zero? x) instead of (= x 0) even though in a logic program 
'=' & '==' do not mean the same thing as in other namespaces...


the same with 'into'. You cannot use vec with reducers as Bronza 
demonstrated!
In general, I think kibit should check the ns declaration for symbols 
that have been redefined like =, == <, > etc etc..This way it can resist 
making suggestions about these redefined symbols...Would that be too 
hard to implement?


Jim

On 12/11/12 13:28, Bronsa wrote:

it is not always true that using vec is equal to using "into []"

user=> (require '[clojure.core.reducers :as r])
nil
user=> (r/map inc (range 2))
#clojure.core.reducers$folder$reify__407@1358d955>

user=> (into [] *1)
[1 2]
user=> (vec *2)
RuntimeException Unable to convert: class 
clojure.core.reducers$folder$reify__407 to Object[] 
clojure.lang.Util.runtimeException (Util.java:170)



2012/11/12 Andreas Liljeqvist mailto:bon...@gmail.com>>

I would prefer the use of vec.

If I am using an empty 'to' then I would always replace it with
the type constructor.
Feels more clean to me.
You aren't logically taking an empty vector and filling it with
stuff, you are converting your original coll.

On Sun, Nov 11, 2012 at 5:04 PM, Jim - FooBar();
mailto:jimpil1...@gmail.com>> wrote:

Kibit is probably looking for syntactic patterns not for types
or anything like that... but still, why is it suggesting this?

Jim



On 11/11/12 15:58, Jim - FooBar(); wrote:

Kibit says:

Consider using:
  (vec (:children (game-tree dir b next-level)))
instead of:
  (into [] (:children (game-tree dir b next-level)))

why is that?
Does it make a difference if '(:children (game-tree dir b
next-level))' returns a reducer?

Jim



On 11/11/12 15:08, Jonas wrote:

Hi

Today I released version 0.0.6 of Kibit[1].

Kibit is a simple code analysis tool. The purpose of
the tool is to tell its users that "Hey, There's
already a function for that!". Kibit uses
core.logic[2]  to search for patterns of code
which can be simplified. For example, if the analyzer
finds `(apply concat (apply map ...)` It will notify
its user about the availability of `mapcat`.

For this release I have split the leiningen plugin
part of kibit of into it’s own project
(lein-kibit[3]). This was done in order for kibit to
be able to read tagged literals (using the Clojure 1.5
`*default-data-reader-fn*` var).

This release also includes several new rules
contributed by the community -- Many thanks!

I hope you enjoy Kibit

Jonas

[1] https://github.com/jonase/kibit
[2] https://github.com/clojure/core.logic
[3] https://github.com/jonase/lein-kibit
-- 
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


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

Re: Question about sets

2012-11-12 Thread Jim foo.bar
sorry 'set' will convert from a coll to a set...use 'hash-set' , 
'sorted-set' etc etc...


Jim


On 12/11/12 13:22, Jim foo.bar wrote:
Yes, this has been discussed extensively in the pastI think the 
convention is to use the ctor functions if you're passing data 
dynamically, otherwise if dealing with constants the literals should 
be just fine...In the case just replace the set literal with (hash-set 
...) or (set ...).


hope that helps...

Jim

On 12/11/12 08:48, Antony Lee wrote:
I may arrive at the party a little late but just to mention I got 
bitten by this too (while working on clojure-py, so I actually want 
to know about the weird edge cases...)


user=> #{(rand-int 100) (rand-int 100)}
IllegalArgumentException Duplicate key: (rand-int 100) 
 clojure.lang.PersistentHashSet.createWithCheck 
(PersistentHashSet.java:68)


Of course you can even replace rand-int by a function which is 
actually guaranteed to return different values on consecutive calls, 
e.g. a closure over an atom.

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


Re: Question about sets

2012-11-12 Thread Jim foo.bar
Yes, this has been discussed extensively in the pastI think the 
convention is to use the ctor functions if you're passing data 
dynamically, otherwise if dealing with constants the literals should be 
just fine...In the case just replace the set literal with (hash-set ...) 
or (set ...).


hope that helps...

Jim

On 12/11/12 08:48, Antony Lee wrote:
I may arrive at the party a little late but just to mention I got 
bitten by this too (while working on clojure-py, so I actually want to 
know about the weird edge cases...)


user=> #{(rand-int 100) (rand-int 100)}
IllegalArgumentException Duplicate key: (rand-int 100) 
 clojure.lang.PersistentHashSet.createWithCheck 
(PersistentHashSet.java:68)


Of course you can even replace rand-int by a function which is 
actually guaranteed to return different values on consecutive calls, 
e.g. a closure over an atom.

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


Re: does clojure.java.jdbc/with-connection db keep the connection alive?

2012-11-09 Thread Jim foo.bar
the general idiom with-some-resource means that resources will be 
cleared after leaving its scope. JUst like with 'with-open' which has a 
try/finally in order to .close() any closable resource upon exit. I've 
not used  clojure.java.jdbc but I suspect the same rationale applies for 
with-connection...


for example in one of my GUIs I have a 'with-busy-cursor' and a 
'with-block' macros. Every time an expensive operation happens on the 
gui I want a busy cursor but also I want my buttons to be non-reactive 
while the busy-cursor is visible (the user can click but nothing 
happens). so imagine i've got  the 'with-block' called from inside the 
'with-busy-cursor' and that removes all the boilerplate code for 
restoring the cursor and the reactive gui...


hope that helps...

Jim





On 09/11/12 17:42, larry google groups wrote:


Sorry this is such an ignorant question, but I am new to Clojure and 
the JVM. I am tring to find info about clojure.java.jdbc so I looked here:


http://corfield.org/blog/post.cfm/connecting-clojure-and-mysql

and saw this example:

(ns mysql.core
   (:require [clojure.java.jdbc :as sql]))

(def db {:classname "com.mysql.jdbc.Driver"
  :subprotocol "mysql"
  :subname "//localhost:3306/dbname"
  :user "dbuser"
  :password "secret"})

(defn list-users []
   (sql/with-connection db
 (sql/with-query-results rows
   ["select * from user"]
   (println rows
Can I assume thatsql/with-connection does some magic in the background to 
manage the connection? I would not want the connection to get shut down, and 
then restarted, everytime I run a query.


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

Re: Slow image convolution

2012-11-09 Thread Jim foo.bar
I thought 'definline' addresses exactly that...cases where one might 
want to pull out small pieces of first class functionality without 
sacrificing performance and without macros (which are not 
first-class)...am I mistaken?


Jim

ps: the only similarly big function that I've ever written (still 
smaller than this one) was for a GUI of mine and basically the Java 
interop caused it to be that big - it's not doing anything complicated 
like this one. I could not maintain such a function like the one shown 
here



On 09/11/12 17:32, Andy Fingerhut wrote:
Having worked on Clojure benchmarks on the Computer Language 
Benchmarks Game web site, that is sometimes the kind of Clojure code 
one needs to write if you want it to be as fast as it can be.


http://shootout.alioth.debian.org/u64q/compare.php?lang=clojure

Also, splitting it out into smaller chunks, if by that you mean 
functions, requires care in Clojure to avoid boxing and unboxing of 
primitive numbers.  It is possible, but can be an additional hurdle 
when trying to optimize code.  Macros can be better in that regard.


--
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: transient/persistent! not worth for less than 7-8 operations

2012-11-09 Thread Jim foo.bar
exactly the point I was trying to make! However, other peoples' 
experiment seem not to agree with that!


Jim


On 09/11/12 15:09, Cedric Greevey wrote:
In the real world, it's more complicated than that, and N could end up 
not only depending on which transient operations and on vector vs. map 
but even on details of the system hardware, Clojure version, and JVM 
version. However it's likely to be a small integer in every case, so 
if you're doing dozens or hundreds or more of operations, transients 
will generally help, and if you're only doing one or two, don't bother.


--
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: Could not locate clojure/data/json__init.class or clojure/data/json.clj on classpath

2012-10-25 Thread Jim foo.bar

On 25/10/12 18:01, larry google groups wrote:

(:require clojure.string clojure.java.io who-is-logged-in.memory_display
[clojure.data.json :as json])


I don't like this line...

try:

(:require [clojure.string :as st]
[clojure.java.io :as io]
[clojure.data.json :as json]
[who-is-logged-in.memory_display :as who]) ;;assuming this 
is an ns you can reach


also try deleting all your class files and recompile...keep your eye on 
the mailing list cos I think something changed with data.json...there is 
a discussion currently going on...


Jim

--
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: thinking in data, polymorphism, etc.

2012-10-25 Thread Jim foo.bar

On 25/10/12 16:59, Brian Craft wrote:
I have a fairly common scenario where I have a set of operations that 
need to work on two types of data (not "data types" in the clojure 
sense) that have different internal structure (i.e. maps with 
different keys). I could write a generic function that operates on 
both types of map.


I'm not sure I follow why you need polymorphic behavior of any 
form...the operations that need to operate on 2 internally different 
maps can take the keys to 'touch' as parameters couldn't they? Then it 
is truly generic...if this is not practical you can always make a HOF 
that returns the appropriate handler for the data-type you're examining 
at any given time...meta-data could help you distinguish between the maps...


am I missing something?

Jim

--
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 is the modern equivalent of clojure.contrib.java-utils/file?

2012-10-25 Thread Jim foo.bar
are you aot compiling? If yes delete all the calss files and 
re-compile...also there is no reason to require it unless you alias it 
to something... a common one would be (:require [clojure.java.io :as 
io])...personally, for clojure.java.io,  I just use the fully qualified 
name most of the times


Jim

On 25/10/12 13:58, larry google groups wrote:


Hmm, how do I include this? I have a strange error. I had an app that 
was working fine, and then I added this one line at the the :require 
block in core.clj:


  (:require clojure.string clojure.java.io who-is-logged-in.memory_display
[clojure.data.json :as json]
[clojure.java.io])

I added that last line, and now, when I compile, I get:

Caused by: java.io.FileNotFoundException: Could not locate 
clojure/data/json__init.class or clojure/data/json.clj on classpath:


This makes no sense to me, since the JSON was working fine the last 
time I compiled.





On Wednesday, October 24, 2012 11:11:11 PM UTC-4, yangsx wrote:

clojure.java.io/file 

On Thu, Oct 25, 2012 at 11:08 AM, larry google groups
> wrote:
>
> I want to use clojure.contrib.java-utils/file. I am using
Clojure 1.3 and
> leinengen. What is the modern equivalent of
clojure.contrib.java-utils/file?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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 


--
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: Troubles working with nl.bitwalker.useragentutils

2012-10-24 Thread Jim foo.bar
aaa sorry I can see from a previous post that you already tried that! 
this is strange!


Jim


On 24/10/12 14:48, Jim foo.bar wrote:

On 24/10/12 14:41, AtKaaZ wrote:
The error doesn't help you solve the problem... which is: don't pass 
a seq to :import


You can easily pass seqs to :import...this works fine for me 
(importing 3 classes from the same package):


(:import [encog_java.customGA CustomNeuralGeneticAlgorithm 
CustomGeneticScoreAdapter Referee])


you just need a space after the package-name...

try

*(:import [nl.bitwalker.useragentutils UserAgent])

*hope that helps

Jim



--
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: Troubles working with nl.bitwalker.useragentutils

2012-10-24 Thread Jim foo.bar

On 24/10/12 14:41, AtKaaZ wrote:
The error doesn't help you solve the problem... which is: don't pass a 
seq to :import


You can easily pass seqs to :import...this works fine for me (importing 
3 classes from the same package):


(:import [encog_java.customGA CustomNeuralGeneticAlgorithm 
CustomGeneticScoreAdapter Referee])


you just need a space after the package-name...

try

*(:import [nl.bitwalker.useragentutils UserAgent])

*hope that helps

Jim

--
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: Calling name on a keyword gives nil??

2012-10-22 Thread Jim foo.bar

On 22/10/12 16:45, JvJ wrote:
The reason it starts with def (and ends in -fn) is because it is a 
function used by a macro, which has a global effect.


well, if you mean that the macro (which you've not shown) is the one 
that creates the top-level form, then macro's name should be the one 
starting with 'def' not the function's. Nothing is wrong really, you're 
just communicating the wrong thing to someone reading your function 
signature.


Jim

--
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: Meta data access

2012-10-22 Thread Jim foo.bar

well not quite!
you need (-> form
   var
   meta
   :test)
or the same thing written differently   (:test (meta (var form)))

Hope that helps,
Jim

ps: basically the meta-data sit with the var not the function



On 22/10/12 16:33, Jim foo.bar wrote:

If I've understood correctly all you need is (meta form)...

Jim

On 22/10/12 15:30, Mamun wrote:

Hi All,

I've a application with following structure. Now I would like to 
access meta data of f1 and f2 within process function.


(defn ^{:test true} f1 []
(println "call f1 fn"))

(defn ^{:test false} f2 []
(println "call f2 fn"))

(def f* (list f1 f2))

(defn process [form]
  (do
*//Would like to access meta data of form*
(println (str "-->" form

(map #(process %1) f*)

Does any one have any idea?


Regards,
Mamun

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

Re: Meta data access

2012-10-22 Thread Jim foo.bar

If I've understood correctly all you need is (meta form)...

Jim

On 22/10/12 15:30, Mamun wrote:

Hi All,

I've a application with following structure. Now I would like to 
access meta data of f1 and f2 within process function.


(defn ^{:test true} f1 []
(println "call f1 fn"))

(defn ^{:test false} f2 []
(println "call f2 fn"))

(def f* (list f1 f2))

(defn process [form]
  (do
*//Would like to access meta data of form*
(println (str "-->" form

(map #(process %1) f*)

Does any one have any idea?


Regards,
Mamun

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

Re: Calling name on a keyword gives nil??

2012-10-22 Thread Jim foo.bar
a pre-condition attached to your fn would be a nice and clean way to 
check for upper/lower case without 'polluting' the fn itself with if 
statements...just a thought ... :-)


Jim


On 22/10/12 16:16, Jim foo.bar wrote:

A couple of issues:

1) 'name' is a fn in core so it's almost never a good idea to shadow 
it like this...
2) also it is not a good idea for a fn to start with 'def' unless it 
actually defines a top-level form inside it like in macros
3)If you need all your keys in capital I think it would be faster to 
just capitalise them without checking...not sure though...


Jim


On 22/10/12 16:09, Bronsa wrote:

I've had this happening to me too.
Couldn't figure out wtf was going on.

Until somebody understands what's the problem is, you can(let [s 
(.sym ^clojure.lang.Keyword k)] ..) and call name on s


2012/10/22 JvJ mailto:kfjwhee...@gmail.com>>

I'm getting a REALLY weird error.  I'm trying to check if a set
of keywords are all uppercase.
When binding a value to 'res' in the let statement, I traverse a
list of keywords.  However, the calls to the name function on those
keywords give nil.  The debug print statement clearly shows that
the class of k is a keyword, and yet its name is nil?

I really don't get it.


;; Program
(defn defrel-fn
  "Adds a relation definition to the *relations* map."
  [name keys]
  (let [res (every? (fn [k]
  (println "k: " (name k) ", " (class k)) ;;
Added for debugging
  (= (name k) (.toUpperCase (name k keys)
;; keys need to be all in uppercase letters!
;;_ (when-not res (throw (Exception. "Error.  All keys
must be upper-case.")))
kns (apply hash-map (mapcat vector keys (range))) ;;
represents a map of keys to indices
]
(swap! *relations*
   assoc name {:fields kns
   :unfields (vec keys) ;; A map of indices
to keys is best represented as a vector
   })))

;; Output from repl
=> (worldrep.core/defrel-fn 'mother [:SELF :CHILD])
k:  nil ,  clojure.lang.Keyword
NullPointerException
clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:314)
-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 




--
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: Calling name on a keyword gives nil??

2012-10-22 Thread Jim foo.bar

A couple of issues:

1) 'name' is a fn in core so it's almost never a good idea to shadow it 
like this...
2) also it is not a good idea for a fn to start with 'def' unless it 
actually defines a top-level form inside it like in macros
3)If you need all your keys in capital I think it would be faster to 
just capitalise them without checking...not sure though...


Jim


On 22/10/12 16:09, Bronsa wrote:

I've had this happening to me too.
Couldn't figure out wtf was going on.

Until somebody understands what's the problem is, you can(let [s (.sym 
^clojure.lang.Keyword k)] ..) and call name on s


2012/10/22 JvJ mailto:kfjwhee...@gmail.com>>

I'm getting a REALLY weird error.  I'm trying to check if a set of
keywords are all uppercase.
When binding a value to 'res' in the let statement, I traverse a
list of keywords.  However, the calls to the name function on those
keywords give nil.  The debug print statement clearly shows that
the class of k is a keyword, and yet its name is nil?

I really don't get it.


;; Program
(defn defrel-fn
  "Adds a relation definition to the *relations* map."
  [name keys]
  (let [res (every? (fn [k]
  (println "k: " (name k) ", " (class k)) ;;
Added for debugging
  (= (name k) (.toUpperCase (name k keys)
;; keys need to be all in uppercase letters!
;;_ (when-not res (throw (Exception. "Error.  All keys
must be upper-case.")))
kns (apply hash-map (mapcat vector keys (range))) ;;
represents a map of keys to indices
]
(swap! *relations*
   assoc name {:fields kns
   :unfields (vec keys) ;; A map of indices to
keys is best represented as a vector
   })))

;; Output from repl
=> (worldrep.core/defrel-fn 'mother [:SELF :CHILD])
k:  nil ,  clojure.lang.Keyword
NullPointerException
clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:314)
-- 
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 


--
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: class name clashes on importing classes of same name from different Java packages into the same clojure namespace...

2012-10-18 Thread Jim foo.bar

On 18/10/12 16:27, Sunil S Nandihalli wrote:

Hi Everybody,
class name  clashes on importing same named classes from different 
java-packages into same clojure namespace. Is this expected. I think 
that it should be possible to import them and can be used by 
completely qualifying the class name with the appropriate java-package 
name.

Thanks,
Sunil.
--
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 


simply don't import them...just use the fully-qualified name

Jim

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

2012-10-17 Thread Jim foo.bar

On 17/10/12 15:41, Timothy Baldridge wrote:
So thank you Rich...thank you for ruining all other languages for me. 


+1
very well put...

Jim

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

2012-10-17 Thread Jim foo.bar
WOW! Has it been 5 years already? Thanks a lot Rich for this beautiful 
gift to all of us...You rock and Clojure rules!!!


Jim


On 17/10/12 02:54, Rich Hickey wrote:

I released Clojure 5 years ago today. It's been a terrific ride so far.

Thanks to everyone who contributes to making Clojure, and its community, great.

Rich



--
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: Simple way to get image from url

2012-10-16 Thread Jim foo.bar

On 16/10/12 13:25, Zhitong He wrote:

another way to solve this,  from
http://users.utu.fi/machra/posts/2011-08-24-2-reddit-clojure.html

(ns myapp.app
(:require [clojure.java.io :as io]))

  (defn copy [uri file]
  (with-open [in (io/input-stream uri)
  out (io/output-stream file)]
(io/copy in out)))


this looks nice...also, no dependencies - you can run this on your android!

Jim

--
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: Evaluating an anonymous function with closure

2012-10-16 Thread Jim foo.bar

On 16/10/12 13:20, Michael Gardner wrote:

On Oct 16, 2012, at 5:16 AM, Jim foo.bar wrote:


so you're saying that if I write a for-loop in Java that populates an array 
with constants from 1-1 and then a 2nd loop to add them up, it would happen 
at compile-time and i would get the same timing-result?

Maybe, maybe not. Compilers are very smart these days, but I don't know if they 
can fold complex expressions like for-loops.



I see... so Clojure macros could indeed have the advantage over regular 
Java methods with regards to my trivial example? I do understand that 
most of the times you simply don't have the data at compile time but 
there must be occasions where you do and replacing a complex expression 
with a scalar might provide stunning performance...I've not had the time 
to go back to the project of mine where performance really really 
matters but I will soon do and let you know if I find anything...


thanks again...

Jim

--
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: Evaluating an anonymous function with closure

2012-10-16 Thread Jim foo.bar

On 16/10/12 11:49, Tassilo Horn wrote:

One example that does things like constant-folding like macrology is the
unit conversion macro in Let Over Lambda that compiles to constants if
both value and unit are given literally (recursively).


unit conversion! this is exactly what i had in mind!!! when doing unit 
conversion we have all the numbers + the formula upfront! where can I 
find this macro that you're describing? Have you got the book? Could you 
copy and paste it here please?


could the same be done in Java?

Jim

--
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: Evaluating an anonymous function with closure

2012-10-16 Thread Jim foo.bar

On 16/10/12 03:50, Michael Gardner wrote:

On Oct 15, 2012, at 7:45 PM, Andy Fingerhut wrote:


For the case of arithmetic on compile-time constants, I believe that many C, 
Java, etc. compilers already perform the arithmetic at compile time.

Known as "constant folding", yes.



so you're saying that if I write a for-loop in Java that populates an 
array with constants from 1-1 and then a 2nd loop to add them up, it 
would happen at compile-time and i would get the same timing-result?


Jim

--
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: pmap performance degradation after 30-40 min of work?

2012-10-12 Thread Jim foo.bar
No i haven't profiled memory , only cpu but what you're saying makes 
perfect sense. In every single iteration (each file) I'm 'slurp'-ing the 
2 files (the dictionary and the file to annotate)  provided. Would you 
suggest a different GC if that is the case or simply stop slurping?


Jim


On 12/10/12 15:28, Adam wrote:
Have you tried running jconsole to monitor the memory usage?  It 
sounds like maybe you're running out of heap space and you're mainly 
seeing the garbage collector doing it's thing vs your actual program.


~Adam~


On Fri, Oct 12, 2012 at 9:23 AM, Jim foo.bar <mailto:jimpil1...@gmail.com>> wrote:


Hi all,

I finally found an ideal use-case for pmap, however something very
strange seems to be happening after roughly 30 minutes of execution!

Ok so here is the scenario:

I've got 383 raw scienific papers (.txt) in directory that i'm
grouping using 'file-seq' and so I want to pmap a fn on each
element of that seq (each document). The fn takes a document and a
dictionary and annotates the document with terms found in the
dictionary. Basically it uses regex to tag any occurrences of
words that exist in the dictionary. When pmapping is finished, I
should have a list of (annotated) strings that will be processed
serially (doseq) in order to produce a massive file with all these
strings separated by a new-line character (this is how most
adaptive feature generators expect the data to be).

So you can see, this is perfect for pmap and indeed it seems to be
doing extremely well but only for the first 240 papers roughly!
all the cpus are working hard but after approximately 30-40 min
 cpu utilisation and overall performance seems to degrade quite a
bit...For some strange reason, 2 of my cores seem to refuse to do
any work after these 240 papers which results in a really really
slow process. When I start the process it is going so fast that I
cannot even read the output but as I said after 30-40 min it is
getting unbelievably slow! Had the performance been stable I
reckon I  need less than 60 min in order to annotate all 383
papers but with the current behaviour I have no choice but to
abort and restart it passing it the leftovers...

any ideas? are there any issues involved with creating that many
futures?

Jim



-- 
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
<mailto: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
<mailto:clojure%2bunsubscr...@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 


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

  1   2   >