Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-05-29 Thread dysinger

I personally have used the -lang qualifier in my own POM work so as to
have an (unspoken) consensus with Howard's POM work.

However, I would rather clojure proper just be named
"org.clojure:clojure" in maven/ivy-land myself and I have heard that
from quite a few others.

On May 10, 1:17 pm, d...@kronkltd.net (Daniel E. Renfer) wrote:
> Phil Hagelberg  writes:
> > Howard Lewis Ship  writes:
>
> >> clojure-lang because there will be a clojure-contrib artifact for the
> >> same group.
>
> > And this is ... a bad thing? I'm lost.
>
> > -Phil
>
> Good, at least I'm not the only one.
>
> Why can't we have both clojure and clojure-contrib as Id's?
>
> Daniel E. Renfer
--~--~-~--~~~---~--~~
You 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: "Currying" / Partial Application macro

2009-05-29 Thread Vagif Verdi



On May 27, 11:57 pm, kinghajj  wrote:
> Example:
> (def add5 ($ + 5))
>
> (add5 3)

I love partial application in haskell. But do not see the need for it
in clojure with its succinct syntax for anonymous functions:

(def add5 #(+ 5 %1))

(add5 3)

Besides clojure's anonymous function syntax allows you to replace any
argument, not just the last one, like your partial macro.

--~--~-~--~~~---~--~~
You 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: Weird Clojure Box - library issue

2009-05-29 Thread Shawn Hoover
On Tue, May 26, 2009 at 4:24 AM, hoeck  wrote:

>
>
>
> On 20 Mai, 14:25, Shawn Hoover  wrote:
> > I can't help with COM, but this patch might help slime automatically
> connect
> > to the REPL on Windows XP:
> http://bitbucket.org/shoover/clojure-box-swank-clojuremq/src/tip/hack...
>
> Hi Shawn,
>
> thanks for this patch, now starting swank-clojure on windows works
> like a charm.
> (Though it leaves my mind in an uncomfortable state when thinking
> about windows and the side-effect-voodoo)
>
> Erik
>

Yeah I do wish I had a better answer. It has to do with initializing
something in the Java hash/crypto stuff, but I could never get a grip on why
it behaves that way. The patch is not necessary on Vista, so maybe it's a
bug in XP or Java on XP.

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



Literal hash-maps with duplicate keys?

2009-05-29 Thread Brian Carper

Can anyone explain this?

user> (def x {:foo :bar :foo :baz :foo :quux})
#'user/x
user> x
{:foo :bar, :foo :baz, :foo :quux}
user> (count (keys x))
3
user> (map x (keys x))
(:bar :bar :bar)

It's understandable that a literal map which includes the same key
twice with different values could return any one of the given values.
But I would expect the resulting map to have one key and one of the
values.  Note:

user> (assoc {} :foo :bar :foo :baz :foo :quux)
{:foo :quux}
user> (conj {} [:foo :bar] [:foo :baz] [:foo :quux])
{:foo :quux}
user> (hash-map :foo :bar :foo :baz :foo :quux)
{:foo :quux}
--~--~-~--~~~---~--~~
You 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: Using generics

2009-05-29 Thread Stuart Sierra

As I understand it, generics aren't "real" types in the JVM.  They
don't even exist in the compiled bytecode instructions.  They're more
like casting hints to the compiler.  When you write List in
Java, what you get is more like a List that automatically
casts elements to Long when you retrieve them.
-Stuart Sierra

On May 28, 5:23 pm, tsuraan  wrote:
> I have a java class whose constructor expects (among other things) a
> BlockingQueue.  It's easy to create a BlockingQueue in clojure
> (obviously), but I can't figure out the syntax to specialize it to the
> Long type.  Is this possible, or does it even make sense?  I seem to
> recall that generics are just hints for the java compiler and not
> actually enforced by the runtime, which would imply that clojure has
> no need to support them.  Is that the case?
--~--~-~--~~~---~--~~
You 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: Instructions for Emacs+SLIME

2009-05-29 Thread Phil Hagelberg

Robert Stehwien  writes:

> Yes, Mac OSX 10.5.  Run into the same problem on my two macbook pros (haven't
> snuck onto my wife's mac pro to try there).

I've pushed out an update to the starter kit. Pull in the latest, remove
everything in your checkout's elpa/ directory, and relaunch Emacs. I
think this should solve it.

Let me know if you still run into it.

-Phil

--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread Kevin Downey

http://gist.github.com/120289 using queues and Threads instead of agents

On Fri, May 29, 2009 at 4:11 PM, Laurent PETIT  wrote:
>
> Hi,
>
> here is a second attempt, partly inspired by clojure's agents page,
> that looks better (true direct ring of agents, not just indirect ring
> via vector), and that performs similarly to my first attempt.
>
> Still room for progress, though.
>
> (ns shootout.ring2
>  (:gen-class))
>
> (def n-threads 503)
> (def nb-pass   5000)
>
> (defn agent-fn [state token-val stop-val print-result-fn start-time]
>        (if (= token-val stop-val)
>          (print-result-fn (:name state) start-time)
>          (send (:next state) agent-fn (inc token-val) stop-val
> print-result-fn start-time))
>        state)
>
> (defn main
>  "main function calling the benchmark test."
>  [n-threads N print-result-fn]
>  (let [agent-n  (agent {:name n-threads :next nil})
>       agent-1  (reduce (fn [a n] (agent {:name n :next a})) agent-n
> (range (dec n-threads) 0 -1))]
>   (send agent-n assoc :next agent-1)
>   (send agent-1 agent-fn 0 N print-result-fn (System/nanoTime))
>   nil))
>
> (defn repl-print-result-fn [thread-id start-time]
>  (println "\n"
>          "thread number: " thread-id "\n"
>          "time   (secs): " (/ (- (System/nanoTime) start-time) 10.0)))
>
> (defn benchmark-print-result-fn [thread-id _]
>  (println thread-id))
>
> (defn -main []
>  (main n-threads nb-pass benchmark-print-result-fn))
>
> (defn repl-test [nb-pass]
>  (main n-threads nb-pass repl-print-result-fn))
>
> 2009/5/29 Sean Devlin :
>>
>> Would type hints help at all?
>>
>> On May 29, 11:40 am, Laurent PETIT  wrote:
>>> Hi,
>>>
>>> Here is my attempt, for the real benchmark test, it has an honorable
>>> result of 62 sec. (if there is no flaw in my algorithm, of course).
>>>
>>> ;; file shootout/ring.clj
>>> (ns shootout.ring
>>>   (:gen-class))
>>>
>>> (def n-threads 503)
>>> (def nb-pass   5000)
>>>
>>> (defn main
>>>   "main function calling the benchmark test."
>>>   [n-threads N print-result-fn]
>>>   (let [start-time (System/nanoTime)
>>>         agents  (into [] (map #(agent {:name (inc %)}) (range n-threads)))
>>>         send-to (fn this [i token-val]
>>>                   (send (nth agents (mod i n-threads))
>>>                             (fn [state t-val]
>>>                               (if (= t-val N)
>>>                                 (print-result-fn (:name state) start-time)
>>>                                 (this (inc i) (inc t-val)))
>>>                               state)
>>>                             token-val))]
>>>     (send-to 0 0)
>>>     nil))
>>>
>>> (defn repl-print-result-fn [thread-id start-time]
>>>   (println "\n"
>>>            "thread number: " thread-id "\n"
>>>            "time   (secs): " (/ (- (System/nanoTime) start-time) 
>>> 10.0)))
>>>
>>> (defn benchmark-print-result-fn [thread-id _]
>>>   (println thread-id))
>>>
>>> (defn -main []
>>>   (main n-threads nb-pass benchmark-print-result-fn))
>>>
>>> (defn repl-test [nb-pass]
>>>   (main n-threads nb-pass repl-print-result-fn))
>>>
>>> ;; repl session
>>> Clojure
>>> 1:1 user=> (use 'shootout.ring)
>>> nil
>>> 1:2 user=> (do (repl-test 1000) (repl-test 5000))
>>> nil
>>> 1:3 user=>
>>>  thread number:  498
>>>  time   (secs):  0.128037133
>>>
>>>  thread number:  292
>>>  time   (secs):  62.724999733
>>>
>>> on a recent machine
>>>
>>> (and yes, I know something similar is on the clojure agents page, but
>>> sometimes it's rewarding not to look at the solution too early :-)
>>>
>>> Cheers,
>>>
>>> --
>>> Laurent
>>>
>>> 2009/5/29 Alvaro Vilanova Vidal :
>>>
>>> > Thanks, seems that I misunderstood Agents :)
>>>
>>> > The solution of Christian works well with full load, but maybe slow for 
>>> > the
>>> > benchmark. In my core2duo, with full load, takes about 28mins to compute 
>>> > the
>>> > result.
>>>
>>> > user=> (do (println (System/nanoTime)) (start 5000))
>>> > 22651751153117
>>> > #
>>> > user=> 292 ( 24319344452689 )
>>> > user=> (/ (- 24319344452689 22651751153117) 600.0)
>>> > 27.79322165954
>>>
>>> > 2009/5/29 Christian Vest Hansen 
>>>
>>> >> On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT 
>>> >> wrote:
>>> >> > when I try it with the 50,000,000 number of times the token is
>>> >> > exchanged (which is the number to be used for the benchmark)
>>>
>>> >> Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
>>> >> (time ...) makes no sense.
>>>
>>> >> > How would one fix this?
>>>
>>> >> With a CountDownLatch? That's what I'm currently trying.
>>>
>>> >> > 2009/5/29 Christian Vest Hansen :
>>>
>>> >> >> For kicks, I made an implementation* using agents:
>>>
>>> >> >>http://gist.github.com/119946
>>>
>>> >> >> I think that you may not want to use the STM so much and instead
>>> >> >> figure out a different approach to sending the token around the ring.
>>>
>>> >> >> *it may be a bit liberal in its interpretation of the rules... didn't
>>> >> >>

Re: The thread ring problem

2009-05-29 Thread Laurent PETIT

Hi,

here is a second attempt, partly inspired by clojure's agents page,
that looks better (true direct ring of agents, not just indirect ring
via vector), and that performs similarly to my first attempt.

Still room for progress, though.

(ns shootout.ring2
 (:gen-class))

(def n-threads 503)
(def nb-pass   5000)

(defn agent-fn [state token-val stop-val print-result-fn start-time]
(if (= token-val stop-val)
  (print-result-fn (:name state) start-time)
  (send (:next state) agent-fn (inc token-val) stop-val
print-result-fn start-time))
state)

(defn main
 "main function calling the benchmark test."
 [n-threads N print-result-fn]
 (let [agent-n  (agent {:name n-threads :next nil})
   agent-1  (reduce (fn [a n] (agent {:name n :next a})) agent-n
(range (dec n-threads) 0 -1))]
   (send agent-n assoc :next agent-1)
   (send agent-1 agent-fn 0 N print-result-fn (System/nanoTime))
   nil))

(defn repl-print-result-fn [thread-id start-time]
 (println "\n"
  "thread number: " thread-id "\n"
  "time   (secs): " (/ (- (System/nanoTime) start-time) 10.0)))

(defn benchmark-print-result-fn [thread-id _]
 (println thread-id))

(defn -main []
 (main n-threads nb-pass benchmark-print-result-fn))

(defn repl-test [nb-pass]
 (main n-threads nb-pass repl-print-result-fn))

2009/5/29 Sean Devlin :
>
> Would type hints help at all?
>
> On May 29, 11:40 am, Laurent PETIT  wrote:
>> Hi,
>>
>> Here is my attempt, for the real benchmark test, it has an honorable
>> result of 62 sec. (if there is no flaw in my algorithm, of course).
>>
>> ;; file shootout/ring.clj
>> (ns shootout.ring
>>   (:gen-class))
>>
>> (def n-threads 503)
>> (def nb-pass   5000)
>>
>> (defn main
>>   "main function calling the benchmark test."
>>   [n-threads N print-result-fn]
>>   (let [start-time (System/nanoTime)
>>         agents  (into [] (map #(agent {:name (inc %)}) (range n-threads)))
>>         send-to (fn this [i token-val]
>>                   (send (nth agents (mod i n-threads))
>>                             (fn [state t-val]
>>                               (if (= t-val N)
>>                                 (print-result-fn (:name state) start-time)
>>                                 (this (inc i) (inc t-val)))
>>                               state)
>>                             token-val))]
>>     (send-to 0 0)
>>     nil))
>>
>> (defn repl-print-result-fn [thread-id start-time]
>>   (println "\n"
>>            "thread number: " thread-id "\n"
>>            "time   (secs): " (/ (- (System/nanoTime) start-time) 
>> 10.0)))
>>
>> (defn benchmark-print-result-fn [thread-id _]
>>   (println thread-id))
>>
>> (defn -main []
>>   (main n-threads nb-pass benchmark-print-result-fn))
>>
>> (defn repl-test [nb-pass]
>>   (main n-threads nb-pass repl-print-result-fn))
>>
>> ;; repl session
>> Clojure
>> 1:1 user=> (use 'shootout.ring)
>> nil
>> 1:2 user=> (do (repl-test 1000) (repl-test 5000))
>> nil
>> 1:3 user=>
>>  thread number:  498
>>  time   (secs):  0.128037133
>>
>>  thread number:  292
>>  time   (secs):  62.724999733
>>
>> on a recent machine
>>
>> (and yes, I know something similar is on the clojure agents page, but
>> sometimes it's rewarding not to look at the solution too early :-)
>>
>> Cheers,
>>
>> --
>> Laurent
>>
>> 2009/5/29 Alvaro Vilanova Vidal :
>>
>> > Thanks, seems that I misunderstood Agents :)
>>
>> > The solution of Christian works well with full load, but maybe slow for the
>> > benchmark. In my core2duo, with full load, takes about 28mins to compute 
>> > the
>> > result.
>>
>> > user=> (do (println (System/nanoTime)) (start 5000))
>> > 22651751153117
>> > #
>> > user=> 292 ( 24319344452689 )
>> > user=> (/ (- 24319344452689 22651751153117) 600.0)
>> > 27.79322165954
>>
>> > 2009/5/29 Christian Vest Hansen 
>>
>> >> On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT 
>> >> wrote:
>> >> > when I try it with the 50,000,000 number of times the token is
>> >> > exchanged (which is the number to be used for the benchmark)
>>
>> >> Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
>> >> (time ...) makes no sense.
>>
>> >> > How would one fix this?
>>
>> >> With a CountDownLatch? That's what I'm currently trying.
>>
>> >> > 2009/5/29 Christian Vest Hansen :
>>
>> >> >> For kicks, I made an implementation* using agents:
>>
>> >> >>http://gist.github.com/119946
>>
>> >> >> I think that you may not want to use the STM so much and instead
>> >> >> figure out a different approach to sending the token around the ring.
>>
>> >> >> *it may be a bit liberal in its interpretation of the rules... didn't
>> >> >> read them that carefully.
>>
>> >> >> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal
>> >> >>  wrote:
>>
>> >> >>> Hi everyone,
>> >> >>> I am a newbie in clojure world, so I have some newbie's questions :)
>> >> >>> To
>> >> >>> learn about clojure, I am trying to do the thread ring problem of clgb
>>

Re: Instructions for Emacs+SLIME

2009-05-29 Thread steveT

Does anyone know if you can interrupt the repl with clojure/slime? In
the plain clojure repl from a terminal I can C-d to break. If I do
that in slime the clojure process seems to shut down.

user=> (read-line)
C-d
nil
user=>
Process inferior-lisp finished

This is with clojure 1.0, and the latest versions of clojure-swank and
slime.

On May 28, 12:54 pm, Phil Hagelberg  wrote:
> I just posted some instructions for getting up and running with
> SLIME. I've seen a lot of folks get confused with some of the more
> convoluted tutorials out there, so I thought it'd be helpful to document
> the simplest way to get started that I know:
>
>  http://technomancy.us/126
>
> I welcome feedback on this, particularly about using Common Lisp
> together with Clojure as this supposedly makes things a bit trickier.
>
> Hope this is useful to folks getting started.
>
> -Phil

--~--~-~--~~~---~--~~
You 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: Instructions for Emacs+SLIME

2009-05-29 Thread Robert Stehwien
On Fri, May 29, 2009 at 10:12 AM, Phil Hagelberg  wrote:

>
> Robert Stehwien  writes:
>
> > * I needed to do a "M-x load-file /clojure-mode.el" before being
> able to
> > call "clojure-install"
> >
> > * I needed to add the following to my ~/.emacs.d/.el so that
> "M-x
> > slime" was available on starting emacs
> > (Load-file
> "/Users//.emacs.d/elpa/clojure-mode-1.1/clojure-mode.el")
> > ;; suggestion from "clojure-install"
> > (setq clojure-src-root "/Users//src/clojure")
> > (eval-after-load 'clojure-mode '(clojure-slime-config))
> >
> > Not sure if this is the best way (my emacs is a bit rusty) so any
> suggestions
> > would be appreciated.
>
> That should get autoloaded for you without the load-file
> invocation... it sounds like you're running into an intermittent ELPA
> bug that I've been unable to reproduce. Are you running Mac OS X by any
> chance?
>
>
Yes, Mac OSX 10.5.  Run into the same problem on my two macbook pros
(haven't snuck onto my wife's mac pro to try there).

--Robert

--~--~-~--~~~---~--~~
You 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 Writing Helper?

2009-05-29 Thread CuppoJava

Macros are harder to write than functions.

For example, the macro you just wrote won't work on:

(with-surrounding-text (read_string_from_stream *standard-in*)
  (println "within surrounding text"))

I personally really don't like writing macros. I try to stay away from
it when I can.
-Patrick
--~--~-~--~~~---~--~~
You 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: "Currying" / Partial Application macro

2009-05-29 Thread Max Suica

Bleh, I've been completely wrong about what currying does. Here's a
correct definition:

(defn curry [f]
  (fn [a]
(fn [b] (f a b))

So curry basically takes a fn f that normally operates on a pair, and
creates an fn that "partially applies" f to an argument. That function
in turn will complete the computation when it receives the final
value, making a curried fn a kind of two stage partial application.
So:

(def add-n (curry +)) ; note that curry itself doesn't apply
anything

(def add-five (add-n 5))  ; first stage where the curried function
"applies" a first argument

(add-five 4) => 9   ; Blap :)

in general: (((curry f) a) b)  <=>  (f a b)

Note, this is kind of ackward in clojure! Curry is limited because its
purpose is to simplify functions on pairs of value, which is useful in
strict lambda calculus. Luckily we're in clojure. Here, it feels
ackward that we can give curry a function of variable arity just to
have curry turn it into a function on two args, and curry fails for
functions with more than 2 fixed arguments. So lets write a curry that
takes advantage of functions of [& args], like + above:

(defn curry2 [f]
  (fn [& x]
(fn [& y]
  (apply f (concat x y))

This allows us to give our curried function multiple arguments in each
stage, which, although not motivated for an associative function like
+, feels more 'clojurish':

(def add-n (curry2 +))

(def add-ten (add-n 1 2 3 4))

(add-ten 6 6 6) ; => 28

And lets see if we can take a function curried this way, and
reconstruct the original function:

(defn uncurry [f]
  (fn [& args]
((f args)) ))

((uncurry add-n) 1 2 3 4) => 10

In general, (uncurry (curry f)) => f

Neat! A curried function is a higher order function and unlike a
partially applied function, it remains equivalent to the original
function.

I'll admit, this all still seems a bit unmotivated here in clojure.
I'm sure we can break curry2 with functions of fixed arity, and it
doesn't allow us progressively partially apply a function of many
arguments, which could be a useful thing. But I think we can write one
interesting fact:

  partial = (curry apply)

What? Really? Heh, I don't know, I gotta check it out later, back to
work here :)

-max


--~--~-~--~~~---~--~~
You 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: integer overflow behavior multiply

2009-05-29 Thread Dex Wood

The failure to detect the integer overflow is not the fault of the
multiply function itself.  The integer argument has already overflown
by the time it reaches the multiply function.  Maybe adding overflow
detection to the coercion functions would be a solution?

On May 29, 1:51 pm, Dex Wood  wrote:
> I was experimenting with math operations and I came across the oddity:
>
> user=> (* (int 2) (int 35666))
> -1029352108
> user=>(* (int 2) (int 356))
> java.lang.ArithmeticException: integer overflow
>
> The top one should throw an integer overflow exception too, but in
> this case it does not.  I dived deep into Numbers.java to see how it
> detects an overflow in the multiplication, and I discovered that it
> does two tests. y != 0 and ret/y != x.  In the top case: ret:
> -1029352108 x: 2 y: -514676054
>
> The first test passes, because y is not 0 and the second test fails
> because ret/y does indeed equal x: -1029352108/-514676054 = 2. So it
> returns garbage without throwing the exception.  In this rare cast,
> the overflowed values divided equal x, which would normally signify
> that the calculation was correct.  Perhaps we should come up with a
> better overflow detection condition.
--~--~-~--~~~---~--~~
You 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
-~--~~~~--~~--~--~---



integer overflow behavior multiply

2009-05-29 Thread Dex Wood

I was experimenting with math operations and I came across the oddity:

user=> (* (int 2) (int 35666))
-1029352108
user=>(* (int 2) (int 356))
java.lang.ArithmeticException: integer overflow

The top one should throw an integer overflow exception too, but in
this case it does not.  I dived deep into Numbers.java to see how it
detects an overflow in the multiplication, and I discovered that it
does two tests. y != 0 and ret/y != x.  In the top case: ret:
-1029352108 x: 2 y: -514676054

The first test passes, because y is not 0 and the second test fails
because ret/y does indeed equal x: -1029352108/-514676054 = 2. So it
returns garbage without throwing the exception.  In this rare cast,
the overflowed values divided equal x, which would normally signify
that the calculation was correct.  Perhaps we should come up with a
better overflow detection condition.
--~--~-~--~~~---~--~~
You 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 know you've been writing too much Clojure when...

2009-05-29 Thread Paul Stadig
You meant to type disclosure, but instead you typed disclojure.

Paul

--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread Sean Devlin

Would type hints help at all?

On May 29, 11:40 am, Laurent PETIT  wrote:
> Hi,
>
> Here is my attempt, for the real benchmark test, it has an honorable
> result of 62 sec. (if there is no flaw in my algorithm, of course).
>
> ;; file shootout/ring.clj
> (ns shootout.ring
>   (:gen-class))
>
> (def n-threads 503)
> (def nb-pass   5000)
>
> (defn main
>   "main function calling the benchmark test."
>   [n-threads N print-result-fn]
>   (let [start-time (System/nanoTime)
>         agents  (into [] (map #(agent {:name (inc %)}) (range n-threads)))
>         send-to (fn this [i token-val]
>                   (send (nth agents (mod i n-threads))
>                             (fn [state t-val]
>                               (if (= t-val N)
>                                 (print-result-fn (:name state) start-time)
>                                 (this (inc i) (inc t-val)))
>                               state)
>                             token-val))]
>     (send-to 0 0)
>     nil))
>
> (defn repl-print-result-fn [thread-id start-time]
>   (println "\n"
>            "thread number: " thread-id "\n"
>            "time   (secs): " (/ (- (System/nanoTime) start-time) 
> 10.0)))
>
> (defn benchmark-print-result-fn [thread-id _]
>   (println thread-id))
>
> (defn -main []
>   (main n-threads nb-pass benchmark-print-result-fn))
>
> (defn repl-test [nb-pass]
>   (main n-threads nb-pass repl-print-result-fn))
>
> ;; repl session
> Clojure
> 1:1 user=> (use 'shootout.ring)
> nil
> 1:2 user=> (do (repl-test 1000) (repl-test 5000))
> nil
> 1:3 user=>
>  thread number:  498
>  time   (secs):  0.128037133
>
>  thread number:  292
>  time   (secs):  62.724999733
>
> on a recent machine
>
> (and yes, I know something similar is on the clojure agents page, but
> sometimes it's rewarding not to look at the solution too early :-)
>
> Cheers,
>
> --
> Laurent
>
> 2009/5/29 Alvaro Vilanova Vidal :
>
> > Thanks, seems that I misunderstood Agents :)
>
> > The solution of Christian works well with full load, but maybe slow for the
> > benchmark. In my core2duo, with full load, takes about 28mins to compute the
> > result.
>
> > user=> (do (println (System/nanoTime)) (start 5000))
> > 22651751153117
> > #
> > user=> 292 ( 24319344452689 )
> > user=> (/ (- 24319344452689 22651751153117) 600.0)
> > 27.79322165954
>
> > 2009/5/29 Christian Vest Hansen 
>
> >> On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT 
> >> wrote:
> >> > when I try it with the 50,000,000 number of times the token is
> >> > exchanged (which is the number to be used for the benchmark)
>
> >> Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
> >> (time ...) makes no sense.
>
> >> > How would one fix this?
>
> >> With a CountDownLatch? That's what I'm currently trying.
>
> >> > 2009/5/29 Christian Vest Hansen :
>
> >> >> For kicks, I made an implementation* using agents:
>
> >> >>http://gist.github.com/119946
>
> >> >> I think that you may not want to use the STM so much and instead
> >> >> figure out a different approach to sending the token around the ring.
>
> >> >> *it may be a bit liberal in its interpretation of the rules... didn't
> >> >> read them that carefully.
>
> >> >> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal
> >> >>  wrote:
>
> >> >>> Hi everyone,
> >> >>> I am a newbie in clojure world, so I have some newbie's questions :)
> >> >>> To
> >> >>> learn about clojure, I am trying to do the thread ring problem of clgb
> >> >>> in
> >> >>> clojure. The rules of problem are here, and my attempt here. It seems
> >> >>> that
> >> >>> works well, but I can only test it with a small load (5 - 15 threads,
> >> >>> 503 is
> >> >>> the target) because it runs extremely slow. I tried to use atoms,
> >> >>> hints, and
> >> >>> change the implementation, but always is slower. What am I doing
> >> >>> wrong? And,
> >> >>> by the way, why can't I compile the class?
>
> >> >>> Thanks a lot.
>
> >> >> --
> >> >> Venlig hilsen / Kind regards,
> >> >> Christian Vest Hansen.
>
> >> --
> >> Venlig hilsen / Kind regards,
> >> Christian Vest Hansen.
>
> > --
> > Álvaro Vilanova,
> >http://alvivi.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Macro Writing Helper?

2009-05-29 Thread James Reeves

On May 28, 9:23 pm, CuppoJava  wrote:
> (defblockfn with_surrounding_text [text func]
>   (println text)
>   (func)
>   (println text))

Okay, but it doesn't seem that much neater than just writing the macro
manually:

(defmacro with-surrounding-text [text & body]
  `(do (println ~text)
   ~...@body
   (println ~text)))

It also adds a layer of indirection. If someone familiar with Clojure
saw the macro, they'd understand what it does. If they saw defblockfn,
they'd have to spend longer working out what the defblockfn macro
does.

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



Re: Macro Writing Helper?

2009-05-29 Thread Meikel Brandmeyer

Hi,

Am 29.05.2009 um 18:28 schrieb CuppoJava:


I haven't thought of using an anonymous function. That cleans things
up a bit. Meikel points out that it is sometimes desirable to have
access to the original function though. I haven't had a need for it
before, but it seems useful.


There are other subtle differences...

Using an in place anonymous function suffers from the same
problems as the macro.

- You have to re-compile every code module using the macro
  when you change something in the anon fn.
- You get a new anon function whenever call the macro. So
  the code size is increased.

So you loose most of the advantages of using a function in
the first place..

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: Macro Writing Helper?

2009-05-29 Thread CuppoJava

Thanks Rock and Laurent for the explanation.

I haven't thought of using an anonymous function. That cleans things
up a bit. Meikel points out that it is sometimes desirable to have
access to the original function though. I haven't had a need for it
before, but it seems useful.

And thanks Rock for the step-by-step expansion instructions. That's
exactly the sort of reasoning I was looking for.
  -Patrick
--~--~-~--~~~---~--~~
You 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: Learning Clojure Wiki

2009-05-29 Thread Rock

Ok. I'll try to correct that. It was already there when I started
working on that section. My main concern is the part where I describe
the rules for the syntax-quote expansion. Does it seem correct to you?

Thanks so much for helping :)

Rock


On May 29, 5:47 pm, Rich Hickey  wrote:
> On May 29, 10:18 am, Rock  wrote:
>
> > By the way, here's the link:
>
> >http://en.wikibooks.org/w/index.php?title=Learning_Clojure&stable=0#R...
>
> > On May 29, 4:14 pm, Rock  wrote:
>
> > > Hi,
>
> > > I've just finished updating the "Reader Macros" section of the Wiki
> > > (especially the syntax-quote part), and I would like to know if it's
> > > reasonably correct. It'd be great to have Rich's blessing.
>
> A couple of things at first glance:
>
> #^ is not sugar for with-meta, see:
>
> http://groups.google.com/group/clojure/msg/919455504c57659e
>
> #"regex" should explain the difference in the use of \ vs. ordinary
> strings
>
> Thanks for working on the wiki!
>
> 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: Instructions for Emacs+SLIME

2009-05-29 Thread Phil Hagelberg

Robert Stehwien  writes:

> * I needed to do a "M-x load-file /clojure-mode.el" before being able to
> call "clojure-install"
>
> * I needed to add the following to my ~/.emacs.d/.el so that "M-x
> slime" was available on starting emacs
> (Load-file "/Users//.emacs.d/elpa/clojure-mode-1.1/clojure-mode.el")
> ;; suggestion from "clojure-install"
> (setq clojure-src-root "/Users//src/clojure")
> (eval-after-load 'clojure-mode '(clojure-slime-config))
>
> Not sure if this is the best way (my emacs is a bit rusty) so any suggestions
> would be appreciated.

That should get autoloaded for you without the load-file
invocation... it sounds like you're running into an intermittent ELPA
bug that I've been unable to reproduce. Are you running Mac OS X by any
chance?

-Phil

--~--~-~--~~~---~--~~
You 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: Learning Clojure Wiki

2009-05-29 Thread Rich Hickey



On May 29, 10:18 am, Rock  wrote:
> By the way, here's the link:
>
> http://en.wikibooks.org/w/index.php?title=Learning_Clojure&stable=0#R...
>
> On May 29, 4:14 pm, Rock  wrote:
>
> > Hi,
>
> > I've just finished updating the "Reader Macros" section of the Wiki
> > (especially the syntax-quote part), and I would like to know if it's
> > reasonably correct. It'd be great to have Rich's blessing.
>

A couple of things at first glance:

#^ is not sugar for with-meta, see:

http://groups.google.com/group/clojure/msg/919455504c57659e

#"regex" should explain the difference in the use of \ vs. ordinary
strings


Thanks for working on the wiki!

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: The thread ring problem

2009-05-29 Thread Laurent PETIT

Hi,

Here is my attempt, for the real benchmark test, it has an honorable
result of 62 sec. (if there is no flaw in my algorithm, of course).

;; file shootout/ring.clj
(ns shootout.ring
  (:gen-class))

(def n-threads 503)
(def nb-pass   5000)

(defn main
  "main function calling the benchmark test."
  [n-threads N print-result-fn]
  (let [start-time (System/nanoTime)
agents  (into [] (map #(agent {:name (inc %)}) (range n-threads)))
send-to (fn this [i token-val]
  (send (nth agents (mod i n-threads))
(fn [state t-val]
  (if (= t-val N)
(print-result-fn (:name state) start-time)
(this (inc i) (inc t-val)))
  state)
token-val))]
(send-to 0 0)
nil))

(defn repl-print-result-fn [thread-id start-time]
  (println "\n"
   "thread number: " thread-id "\n"
   "time   (secs): " (/ (- (System/nanoTime) start-time) 10.0)))

(defn benchmark-print-result-fn [thread-id _]
  (println thread-id))

(defn -main []
  (main n-threads nb-pass benchmark-print-result-fn))

(defn repl-test [nb-pass]
  (main n-threads nb-pass repl-print-result-fn))

;; repl session
Clojure
1:1 user=> (use 'shootout.ring)
nil
1:2 user=> (do (repl-test 1000) (repl-test 5000))
nil
1:3 user=>
 thread number:  498
 time   (secs):  0.128037133

 thread number:  292
 time   (secs):  62.724999733

on a recent machine

(and yes, I know something similar is on the clojure agents page, but
sometimes it's rewarding not to look at the solution too early :-)

Cheers,

-- 
Laurent

2009/5/29 Alvaro Vilanova Vidal :
> Thanks, seems that I misunderstood Agents :)
>
> The solution of Christian works well with full load, but maybe slow for the
> benchmark. In my core2duo, with full load, takes about 28mins to compute the
> result.
>
> user=> (do (println (System/nanoTime)) (start 5000))
> 22651751153117
> #
> user=> 292 ( 24319344452689 )
> user=> (/ (- 24319344452689 22651751153117) 600.0)
> 27.79322165954
>
>
> 2009/5/29 Christian Vest Hansen 
>>
>> On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT 
>> wrote:
>> > when I try it with the 50,000,000 number of times the token is
>> > exchanged (which is the number to be used for the benchmark)
>>
>> Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
>> (time ...) makes no sense.
>>
>> > How would one fix this?
>>
>> With a CountDownLatch? That's what I'm currently trying.
>>
>> >
>> > 2009/5/29 Christian Vest Hansen :
>> >>
>> >> For kicks, I made an implementation* using agents:
>> >>
>> >> http://gist.github.com/119946
>> >>
>> >> I think that you may not want to use the STM so much and instead
>> >> figure out a different approach to sending the token around the ring.
>> >>
>> >> *it may be a bit liberal in its interpretation of the rules... didn't
>> >> read them that carefully.
>> >>
>> >> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal
>> >>  wrote:
>> >>>
>> >>> Hi everyone,
>> >>> I am a newbie in clojure world, so I have some newbie's questions :)
>> >>> To
>> >>> learn about clojure, I am trying to do the thread ring problem of clgb
>> >>> in
>> >>> clojure. The rules of problem are here, and my attempt here. It seems
>> >>> that
>> >>> works well, but I can only test it with a small load (5 - 15 threads,
>> >>> 503 is
>> >>> the target) because it runs extremely slow. I tried to use atoms,
>> >>> hints, and
>> >>> change the implementation, but always is slower. What am I doing
>> >>> wrong? And,
>> >>> by the way, why can't I compile the class?
>> >>>
>> >>> Thanks a lot.
>> >>>
>> >>>
>> >>> >
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Venlig hilsen / Kind regards,
>> >> Christian Vest Hansen.
>> >>
>> >> >
>> >>
>> >
>> > >
>> >
>>
>>
>>
>> --
>> Venlig hilsen / Kind regards,
>> Christian Vest Hansen.
>>
>>
>
>
>
> --
> Álvaro Vilanova,
> http://alvivi.com
>
> >
>

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



Re: The thread ring problem

2009-05-29 Thread Alvaro Vilanova Vidal
Thanks, seems that I misunderstood Agents :)

The solution of Christian works well with full load, but maybe slow for the
benchmark. In my core2duo, with full load, takes about 28mins to compute the
result.

user=> (do (println (System/nanoTime)) (start 5000))
22651751153117
#
user=> 292 ( 24319344452689 )
user=> (/ (- 24319344452689 22651751153117) 600.0)
27.79322165954


2009/5/29 Christian Vest Hansen 

>
> On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT 
> wrote:
> > when I try it with the 50,000,000 number of times the token is
> > exchanged (which is the number to be used for the benchmark)
>
> Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
> (time ...) makes no sense.
>
> > How would one fix this?
>
> With a CountDownLatch? That's what I'm currently trying.
>
> >
> > 2009/5/29 Christian Vest Hansen :
> >>
> >> For kicks, I made an implementation* using agents:
> >>
> >> http://gist.github.com/119946
> >>
> >> I think that you may not want to use the STM so much and instead
> >> figure out a different approach to sending the token around the ring.
> >>
> >> *it may be a bit liberal in its interpretation of the rules... didn't
> >> read them that carefully.
> >>
> >> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal <
> alv...@gmail.com> wrote:
> >>>
> >>> Hi everyone,
> >>> I am a newbie in clojure world, so I have some newbie's questions :) To
> >>> learn about clojure, I am trying to do the thread ring problem of clgb
> in
> >>> clojure. The rules of problem are here, and my attempt here. It seems
> that
> >>> works well, but I can only test it with a small load (5 - 15 threads,
> 503 is
> >>> the target) because it runs extremely slow. I tried to use atoms,
> hints, and
> >>> change the implementation, but always is slower. What am I doing wrong?
> And,
> >>> by the way, why can't I compile the class?
> >>>
> >>> Thanks a lot.
> >>>
> >>>
> >>> >
> >>>
> >>
> >>
> >>
> >> --
> >> Venlig hilsen / Kind regards,
> >> Christian Vest Hansen.
> >>
> >> >
> >>
> >
> > >
> >
>
>
>
> --
> Venlig hilsen / Kind regards,
> Christian Vest Hansen.
>
> >
>


-- 
Álvaro Vilanova,
http://alvivi.com

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



Re: Macro Writing Helper?

2009-05-29 Thread Laurent PETIT

Hi Meikel,

Yes, you're right on full spots, as usual ;-)

But anyway, I don't regret the exercise, very cool !

-- 
Laurent

2009/5/29 Meikel Brandmeyer :
> Hi Laurent,
>
> Am 29.05.2009 um 14:21 schrieb Laurent PETIT:
>
>> I also didn't see whether it was interesting to have the explicit
>> defn, I thought that an anonymous function could do the trick.
>
> It is often desirable to have the driver function available,
> because it can be passed around, apply'd, etc. I terribly miss
> binding* as a driver for the binding macro, because I had
> the need to do the binding dynamically directly providing
> the map of Var-value pairs. But there is no binding* in core,
> so I have to reimplement it everytime.
>
> Note, that the naming problem didn't arise in my original
> solution, because the name of the driver function was
> derived from the final macro name. So two different macros
> wouldn't conflict.
>
> Sincerely
> Meikel
>
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: The thread ring problem

2009-05-29 Thread Christian Vest Hansen

On Fri, May 29, 2009 at 4:29 PM, Laurent PETIT  wrote:
> when I try it with the 50,000,000 number of times the token is
> exchanged (which is the number to be used for the benchmark)

Oh, right. I only noticed the 1000 mentioned at the bottom. Also, the
(time ...) makes no sense.

> How would one fix this?

With a CountDownLatch? That's what I'm currently trying.

>
> 2009/5/29 Christian Vest Hansen :
>>
>> For kicks, I made an implementation* using agents:
>>
>> http://gist.github.com/119946
>>
>> I think that you may not want to use the STM so much and instead
>> figure out a different approach to sending the token around the ring.
>>
>> *it may be a bit liberal in its interpretation of the rules... didn't
>> read them that carefully.
>>
>> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal  
>> wrote:
>>>
>>> Hi everyone,
>>> I am a newbie in clojure world, so I have some newbie's questions :) To
>>> learn about clojure, I am trying to do the thread ring problem of clgb in
>>> clojure. The rules of problem are here, and my attempt here. It seems that
>>> works well, but I can only test it with a small load (5 - 15 threads, 503 is
>>> the target) because it runs extremely slow. I tried to use atoms, hints, and
>>> change the implementation, but always is slower. What am I doing wrong? And,
>>> by the way, why can't I compile the class?
>>>
>>> Thanks a lot.
>>>
>>>
>>> >
>>>
>>
>>
>>
>> --
>> Venlig hilsen / Kind regards,
>> Christian Vest Hansen.
>>
>> >
>>
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread Michael Wood

On Fri, May 29, 2009 at 3:29 PM, Christian Vest Hansen
 wrote:
>
> For kicks, I made an implementation* using agents:
>
> http://gist.github.com/119946

The call to time returns almost immediately and the actual result
takes much longer to appear (with large values of token).  How would
one fix this?

> I think that you may not want to use the STM so much and instead
> figure out a different approach to sending the token around the ring.
>
> *it may be a bit liberal in its interpretation of the rules... didn't
> read them that carefully.

-- 
Michael Wood 

--~--~-~--~~~---~--~~
You 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 Writing Helper?

2009-05-29 Thread Meikel Brandmeyer

Hi Laurent,

Am 29.05.2009 um 14:21 schrieb Laurent PETIT:


I also didn't see whether it was interesting to have the explicit
defn, I thought that an anonymous function could do the trick.


It is often desirable to have the driver function available,
because it can be passed around, apply'd, etc. I terribly miss
binding* as a driver for the binding macro, because I had
the need to do the binding dynamically directly providing
the map of Var-value pairs. But there is no binding* in core,
so I have to reimplement it everytime.

Note, that the naming problem didn't arise in my original
solution, because the name of the driver function was
derived from the final macro name. So two different macros
wouldn't conflict.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: The thread ring problem

2009-05-29 Thread Laurent PETIT

Sorry, I understood that the (shutdown-agents) call is certainly
responsible for this.

2009/5/29 Laurent PETIT :
> Hi,
>
> didn't take time to analyse why, but your solution sends a
>
> java.util.concurrent.RejectedExecutionException
>
> when I try it with the 50,000,000 number of times the token is
> exchanged (which is the number to be used for the benchmark)
>
> 2009/5/29 Christian Vest Hansen :
>>
>> For kicks, I made an implementation* using agents:
>>
>> http://gist.github.com/119946
>>
>> I think that you may not want to use the STM so much and instead
>> figure out a different approach to sending the token around the ring.
>>
>> *it may be a bit liberal in its interpretation of the rules... didn't
>> read them that carefully.
>>
>> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal  
>> wrote:
>>>
>>> Hi everyone,
>>> I am a newbie in clojure world, so I have some newbie's questions :) To
>>> learn about clojure, I am trying to do the thread ring problem of clgb in
>>> clojure. The rules of problem are here, and my attempt here. It seems that
>>> works well, but I can only test it with a small load (5 - 15 threads, 503 is
>>> the target) because it runs extremely slow. I tried to use atoms, hints, and
>>> change the implementation, but always is slower. What am I doing wrong? And,
>>> by the way, why can't I compile the class?
>>>
>>> Thanks a lot.
>>>
>>>
>>> >
>>>
>>
>>
>>
>> --
>> Venlig hilsen / Kind regards,
>> Christian Vest Hansen.
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread Laurent PETIT

Hi,

didn't take time to analyse why, but your solution sends a

java.util.concurrent.RejectedExecutionException

when I try it with the 50,000,000 number of times the token is
exchanged (which is the number to be used for the benchmark)

2009/5/29 Christian Vest Hansen :
>
> For kicks, I made an implementation* using agents:
>
> http://gist.github.com/119946
>
> I think that you may not want to use the STM so much and instead
> figure out a different approach to sending the token around the ring.
>
> *it may be a bit liberal in its interpretation of the rules... didn't
> read them that carefully.
>
> On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal  
> wrote:
>>
>> Hi everyone,
>> I am a newbie in clojure world, so I have some newbie's questions :) To
>> learn about clojure, I am trying to do the thread ring problem of clgb in
>> clojure. The rules of problem are here, and my attempt here. It seems that
>> works well, but I can only test it with a small load (5 - 15 threads, 503 is
>> the target) because it runs extremely slow. I tried to use atoms, hints, and
>> change the implementation, but always is slower. What am I doing wrong? And,
>> by the way, why can't I compile the class?
>>
>> Thanks a lot.
>>
>>
>> >
>>
>
>
>
> --
> Venlig hilsen / Kind regards,
> Christian Vest Hansen.
>
> >
>

--~--~-~--~~~---~--~~
You 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: Learning Clojure Wiki

2009-05-29 Thread Rock

By the way, here's the link:

http://en.wikibooks.org/w/index.php?title=Learning_Clojure&stable=0#Reader_Macros

On May 29, 4:14 pm, Rock  wrote:
> Hi,
>
> I've just finished updating the "Reader Macros" section of the Wiki
> (especially the syntax-quote part), and I would like to know if it's
> reasonably correct. It'd be great to have Rich's blessing.
>
> Thanks.
>
> Rock
--~--~-~--~~~---~--~~
You 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: Learning Clojure Wiki

2009-05-29 Thread Rock

By the way, here's the link:

http://en.wikibooks.org/wiki/Learning_Clojure#Reader_Macros

On May 29, 4:14 pm, Rock  wrote:
> Hi,
>
> I've just finished updating the "Reader Macros" section of the Wiki
> (especially the syntax-quote part), and I would like to know if it's
> reasonably correct. It'd be great to have Rich's blessing.
>
> Thanks.
>
> Rock
--~--~-~--~~~---~--~~
You 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
-~--~~~~--~~--~--~---



Learning Clojure Wiki

2009-05-29 Thread Rock

Hi,

I've just finished updating the "Reader Macros" section of the Wiki
(especially the syntax-quote part), and I would like to know if it's
reasonably correct. It'd be great to have Rich's blessing.

Thanks.

Rock

--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread graham

Have you seen the example on the agents page of the main clojure site?

http://clojure.org/agents
--~--~-~--~~~---~--~~
You 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: The thread ring problem

2009-05-29 Thread Christian Vest Hansen

For kicks, I made an implementation* using agents:

http://gist.github.com/119946

I think that you may not want to use the STM so much and instead
figure out a different approach to sending the token around the ring.

*it may be a bit liberal in its interpretation of the rules... didn't
read them that carefully.

On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal  wrote:
>
> Hi everyone,
> I am a newbie in clojure world, so I have some newbie's questions :) To
> learn about clojure, I am trying to do the thread ring problem of clgb in
> clojure. The rules of problem are here, and my attempt here. It seems that
> works well, but I can only test it with a small load (5 - 15 threads, 503 is
> the target) because it runs extremely slow. I tried to use atoms, hints, and
> change the implementation, but always is slower. What am I doing wrong? And,
> by the way, why can't I compile the class?
>
> Thanks a lot.
>
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

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



Re: how would I do this functionally? (internally mutable state)

2009-05-29 Thread Korny Sietsma

I keep reading this thread when I should be going to bed :)  Sadly,
this stuff is in what I call my "0.2% time" so I'm not working very
hard on it right now.

The ruby code, which basically works (but is rather ugly in parts)
relies on reading the whole file tree into memory, and then traversing
the tree, saving each node (file or dir) in a repostory, which
internally detects duplicates as they are added.

The repository stores all known nodes, indexed by size, and then
grouped into clumps of identical nodes.  When you add a new node, it
compares it to all clumps of the same size as the node, looking for an
identical clump; if it finds one, the new node is added to the clump,
otherwise it forms a new clump.
(sorry if this is a bit of a vague description, I haven't worked on
this code for a while so all the details are a bit vague)

Once the repository is built, it's pretty easy to throw away all
non-duplicate nodes, and report on the duplicates.

This works, but has some issues:
- it's got some kind-of ugly handling for some special cases, like
making sure a directory doesn't match it's own children if it only has
one child
- it's a bit slow, and uses a lot of memory
- it *only* handles exact matches.

I've been playing with shingling and sketching algorithms that are
used by search engines to identify nearly-identical documents, and I
think they could be applied to this problem; in fact I suspect they
could speed it up considerably.  (If you want to know more about this
the best reference online seems to be the book "Introduction to
Information Retrieval" which is at
http://www-csli.stanford.edu/~hinrich/information-retrieval-book.html
- the chapter most relevant is at
http://nlp.stanford.edu/IR-book/html/htmledition/near-duplicates-and-shingling-1.html
)

But, like I said, this is my 0.2% time project, so it might be some
time before I really do more than think about this. :)

- Korny

On Fri, May 29, 2009 at 4:51 PM, Daniel Lyons  wrote:
>
> For whatever reason I just can't seem to put this problem down.
>
> I have rewritten the code substantially. A major bottleneck was using
> Java's MD5 classes. The "Fast MD5" library really is, and that helped
> a lot. I did get the -> notation to work and I have a reasonable HOF
> now for doing the winnowing, which might even be applicable to another
> program someday, maybe.
>
> Anyway I uploaded it here:   > and again I'd love any feedback anyone cares to give.
>
> Just to add insult to injury, I went ahead and programmed it again in
> Ruby. The good news is that I can't seem to get Ruby to find all the
> files the Clojure one finds, but the bad news is that the Ruby version
> is like four times faster. I'd love to understand that. So I uploaded
> that too: . Of
> course it must be benefiting to some extent from the fact that the
> Ruby version has a lot less abstraction, but I don't see how the
> approach is fundamentally any different or why there would be such a
> large performance disparity. I must be missing something big.
>
> On May 28, 2009, at 6:50 AM, Korny Sietsma wrote:
>> By the way, in response to whoever suggested pre-sorting files; I
>> sort-of do this (in the old ruby version) but actually, mostly the
>> program is looking for duplicate *directories* of files - the goal is
>> to point it at my archive disk, and have it find the biggest identical
>> subdirectories.  Duplicate file checking is needed for this, but it's
>> only a tiny part.
>>
>> And I'm playing with sketching algorithms at work right now, which
>> look very handy for the next phase, which is to find the biggest
>> *similar* subdirectories.  That's the real goal - point a program at a
>> terabyte archive disk, and have it spit out :
>> "/archive/old_disks/laptop_2007a is 312gb and 99% similar to
>> /archive/misc/stuff_from_2007"
>> ... or sorting by file count:
>> "/archive/source/old_projects/c_stuff/1996 is 20,324 files and 97%
>> similar to /archive/old/disks/laptop2006/unsorted/old_drives/
>> old_archive/c_cpp_stuff/90s"
>
>
> I can think of three ways to approach this, none of which are
> particularly easy.
>
> The first is to take the duplicate file finding function and look for
> common suffixes of paths. It could almost be like running a fuzzy
> duplicate finder against your duplicates. I suspect the performance
> here will blow for no particular reason I can put my finger on.
>
> The second approach would be to use something like rsync's rolling
> checksum. I bet you could use a rather stupid heuristic to find
> candidate directories for similarity and then apply this algorithm
> amongst the candidates. It would be handy if you could have a version
> of diff that would look at two directories recursively and give up if
> they were sufficiently different.
>
> Another option would be to ignore the filesystem altogether and look
> for runs of similar blocks on the device direc

Re: Instructions for Emacs+SLIME

2009-05-29 Thread Robert Stehwien
Phil,

I love the starter kit and I'm trying an experiment of dropping my old
crufty .emacs in favor of the the starter kit.  A few notes of things that
might be useful to add to the tutorial (coming from someone starting from
scratch):

* I needed to do a "M-x load-file /clojure-mode.el" before being able
to call "clojure-install"

* I needed to add the following to my ~/.emacs.d/.el so that "M-x
slime" was available on starting emacs
(Load-file
"/Users//.emacs.d/elpa/clojure-mode-1.1/clojure-mode.el")
;; suggestion from "clojure-install"
(setq clojure-src-root "/Users//src/clojure")
(eval-after-load 'clojure-mode '(clojure-slime-config))

Not sure if this is the best way (my emacs is a bit rusty) so any
suggestions would be appreciated.

Thanks for making this available.

--Robert

On Thu, May 28, 2009 at 1:54 PM, Phil Hagelberg  wrote:

>
>
> I just posted some instructions for getting up and running with
> SLIME. I've seen a lot of folks get confused with some of the more
> convoluted tutorials out there, so I thought it'd be helpful to document
> the simplest way to get started that I know:
>
>  http://technomancy.us/126
>
> I welcome feedback on this, particularly about using Common Lisp
> together with Clojure as this supposedly makes things a bit trickier.
>
> Hope this is useful to folks getting started.
>
> -Phil
>
> >
>

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



The thread ring problem

2009-05-29 Thread Alvaro Vilanova Vidal
Hi everyone,
I am a newbie in clojure world, so I have some newbie's questions :) To
learn about clojure, I am trying to do the thread ring problem of clgb in
clojure. The rules of problem are
here,
and my attempt here . It seems that works
well, but I can only test it with a small load (5 - 15 threads, 503 is the
target) because it runs extremely slow. I tried to use atoms, hints, and
change the implementation, but always is slower. What am I doing wrong? And,
by the way, why can't I compile  the class?

Thanks a lot.

--~--~-~--~~~---~--~~
You 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 Writing Helper?

2009-05-29 Thread Laurent PETIT

Hi,

As you mentioned in another thread, your version of defblockfn cannot
create more than one macro due to the problem with defn.
I also didn't see whether it was interesting to have the explicit
defn, I thought that an anonymous function could do the trick.
And as I, too, wanted to understand more thouroughly how nested
syntax-quotes ... work, I tried and (and finally arrived to!) a
working solution.

Here it is (with first the demonstration of the problem in the
original defblockfn)
(note that I also gensymed all the intermediate macro params, though
it may not be needed in this particular case, since the user code
itself is encapsulated in an anonymous fn and will not be in the
lexical scope where the non gensymed params are placed in your
version)
:

;; initial defblockfn ...
(defmacro defblockfn [function params & body]
 (let [butlast_params (butlast params)]
   `(do (defn func# ~params ~...@body)
(defmacro ~function [...@butlast_params & tail#]
  `(~'func# ~...@butlast_params (fn [] ~...@tail#))

;; ... does not work well if more than one macro is generated
(defblockfn with-1 [text-before text-after func] (println "before:"
text-before) (func) (println "after:" text-after))
(defblockfn with-2 [text-before text-after func] (println "avant:"
text-before) (func) (println "apres:" text-after))
(with-1 "before" "after" (println "middle"))
(with-2 "before" "after" (println "middle"))

;; working defblockfn ...
(defmacro defblockfn [function params-names & body]
  (let [macro-params-names (map (fn [_] (gensym)) (butlast params-names))]
`(defmacro ~function [...@macro-params-names & macro-tail#]
  `((fn [~@'~params-names] ~@'~body) ~@(list ~...@macro-params-names)
(fn [] ~...@macro-tail#)

;; ... does work well if more than one macro is generated
(defblockfn with-1 [text-before text-after func] (println "before:"
text-before) (func) (println "after:" text-after))
(defblockfn with-2 [text-before text-after func] (println "avant:"
text-before) (func) (println "apres:" text-after))

(with-1 "before" "after" (println "middle"))
(with-2 "before" "after" (println "middle"))


HTH,

-- 
Laurent

2009/5/28 CuppoJava :
>
> Okay. So I grasped some understanding from going through Meikel's
> macro with a micron comb.
>
> Here's my version: it's a little more general (it can accept any
> number of arguments), and little cleaner.
> 
> (defmacro defblockfn [function params & body]
>  (let [butlast_params (butlast params)]
>    `(do (defn func# ~params ~...@body)
>         (defmacro ~function [...@butlast_params & tail#]
>           `(~'func# ~...@butlast_params (fn [] ~...@tail#))
> -
>
> This allows us to define "modifier" macros, like such:
>
> (defblockfn with_surrounding_text [text func]
>  (println text)
>  (func)
>  (println text))
>
> And you can use it like such:
>
> (with_surrounding_text "surround"
>  (println "within surrounding text: line1")
>  (println "within surrounding text: line2"))
>
> I'm personally using it to wrap openGL commands:
> (defblockfn with_shape [shape func]
>  (glBegin shape)
>  (func)
>  (glEnd))
>
> so that I can type:
>
> (with_shape GL11/GL_QUADS
>  (glVertex ...)
>  (glVertex ...))
>
> The point of this macro is not to accomplish any specific function.
> It's to allow you to define your own "wrapping" functions.
>
> Thanks to Meikel and Sean for their input and help.
>  -Patrick
> >
>

--~--~-~--~~~---~--~~
You 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: Slurping structs from file fails with string attributes containing whitespaces

2009-05-29 Thread Christophe Grand



On 29 mai, 05:55, Perttu  wrote:
> I use a store-function like this:
>
> (defn store-customer-db [customer-db filename]
>   (spit filename (with-out-str (print customer-db

> From the output file of spit I can see that the print doesn't give
> double quotes to the strings which seems to be a problem for slurp.
> What would be the correct solution for this?

Use pr instead of print (see http://clojure.org/api#pr "By default, pr
and prn print in a way that objects can be read by the reader").
You can even remove with-out-str if you use pr-str

hth

Christophe
--~--~-~--~~~---~--~~
You 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: Slurping structs from file fails with whitespace string attributes

2009-05-29 Thread J. McConnell
On Thu, May 28, 2009 at 4:23 PM, Perttu  wrote:

>
> I use a store-function like this:
>
> (defn store-customer-db [customer-db filename]
>  (spit filename (with-out-str (print customer-db


I believe this is your problem. The print/println functions print in a
format suitable for human consumption. That's why you don't see quotes
around the strings. These are the functions you would normally use for, for
example, echoing instructions to a console user.

I believe what you are looking for are the pr/prn functions (pr in
particular). These are designed to print objects for reader consumption.

HTH,

- J.

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



Slurping structs from file fails with whitespace string attributes

2009-05-29 Thread Perttu

Hi.

I'm a newbie so bare with me. I have just started playing with Clojure
and the first thing I thought I'd try is storing and retrieving a seq
of structs, like in Suart Halloway's example here:

http://github.com/stuarthalloway/practical-cl-clojure/blob/1c2f138bda5e73ebbbafbc2cea7e5cd14ec335c4/pcl/chap_03/chap_03.clj

My spit/slurp of a hash of structs works fine with, if I use struct
instances without spaces in the attribute strings like the following:

(struct customer "Apple" "InfiniteLoop")

But if I use this:

(struct customer "Apple" "Infinite Loop 1")

I get an error:

Exception in thread "main" clojure.lang.LispReader$ReaderException:
java.lang.ArrayIndexOutOfBoundsException: 7 (test-storing.clj:19)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2719)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:298)
at clojure.lang.Compiler.eval(Compiler.java:4537)
at clojure.lang.Compiler.load(Compiler.java:4857)
at clojure.lang.Compiler.loadFile(Compiler.java:4824)
at clojure.main$load_script__5833.invoke(main.clj:206)
at clojure.main$init_opt__5836.invoke(main.clj:211)
at clojure.main$initialize__5846.invoke(main.clj:239)
at clojure.main$null_opt__5868.invoke(main.clj:264)
at clojure.main$legacy_script__5883.invoke(main.clj:295)
at clojure.lang.Var.invoke(Var.java:346)
at clojure.main.legacy_script(main.java:34)
at clojure.lang.Script.main(Script.java:20)
Caused by: clojure.lang.LispReader$ReaderException:
java.lang.ArrayIndexOutOfBoundsException: 7
at clojure.lang.LispReader.read(LispReader.java:180)
at clojure.core$read__4168.invoke(core.clj:2083)
at clojure.core$read__4168.invoke(core.clj:2081)
at clojure.core$read__4168.invoke(core.clj:2079)
at clojure.core$read__4168.invoke(core.clj:2077)
at chap_03$load_db__54.invoke(chap_03.clj:71)
at clojure.lang.AFn.applyToHelper(AFn.java:173)
at clojure.lang.AFn.applyTo(AFn.java:164)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2714)
... 12 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 7
at clojure.lang.PersistentArrayMap$Seq.first(PersistentArrayMap.java:
216)
at clojure.lang.APersistentMap.hashCode(APersistentMap.java:101)
at clojure.lang.Util.hash(Util.java:55)
at clojure.lang.PersistentHashMap.entryAt(PersistentHashMap.java:134)
at clojure.lang.PersistentHashMap.containsKey(PersistentHashMap.java:
130)
at clojure.lang.APersistentSet.contains(APersistentSet.java:33)
at clojure.lang.PersistentHashSet.cons(PersistentHashSet.java:59)
at clojure.lang.PersistentHashSet.create(PersistentHashSet.java:34)
at clojure.lang.LispReader$SetReader.invoke(LispReader.java:974)
at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:540)
at clojure.lang.LispReader.read(LispReader.java:145)
... 20 more

I use a store-function like this:

(defn store-customer-db [customer-db filename]
  (spit filename (with-out-str (print customer-db

And a read-function like this:

(defn load-db [filename]
  (with-in-str (slurp filename)(read)))

>From the output file of spit I can see that the print doesn't give
double quotes to the strings which seems to be a problem for slurp.
What would be the correct solution for this?

My Clojure version is 1.0, and the contrib is a few weeks old
snapshot.

Thanks,
Perttu



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Macro Writing Helper?

2009-05-29 Thread Rock

Macros and, more specifically, syntax-quotes are not conceptually
hard. Nested syntax-quotes though are certainly more complicated to
follow, but not any harder from a conceptual point of view. I've
written about what the expansion algorithm does in the wiki. You can
find some info here:

http://en.wikibooks.org/wiki/Learning_Clojure#Reader_Macros

Just follow the rules and you'll figure out what's going on behind the
curtains.

As for expansion per se, I use a simple trick. Just "quote" it and
you'll see the result. For instance:

Want to see what happens to ``(~a) then just
'``(~a)

If you want to break that down, keep in mind that the expansion starts
from the innermost syntax-quote. Like the wiki says:

If the syntax-quote syntax is nested, the innermost syntax-quoted form
is expanded first. This means that if several ~ occur in a row, the
leftmost one belongs to the innermost syntax-quote.

So in the previous example do this:
'`(~a)

then apply another '` to whatever you get as the result. This way you
can break it down to successive steps.

Hope that helps.

Rock

P.S. I've just realized that I'm going to have to update the syntax-
quote expansion algorithm in the wiki because with the changes
concerning lazy sequences it seems things have changed slightly, but
the essence of what I have told you is the same.

Perhaps Rich can write it out for us explicitly right away. It would
be greatly appreciated.

On May 28, 9:10 pm, CuppoJava  wrote:
> Thank you Meikel for going to the trouble of writing out the full
> macro. It's going to take me a while to decipher it, and hopefully
> grasp some understanding at the end of it.
>
> I find defblockfn very useful for functions that take a single
> function as one of the parameters.
>
> Macros are much harder and more error-prone to write than functions,
> so almost all of my macros do nothing but wrap a body in a function.
>
> "One technique, which was
> helpful was to just call the defblockfn macro and then
> expand the call to freshly defined macro.
>
> (defblockfn foo [a b c] ...)
> (macroexpand-1 '(foo :a :b :c)) "
>
> Could you explain a bit more what you mean by that? I don't quite
> understand what you're saying, but it sounds potentially very useful.
>
> Thanks again
>   -Patrick

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Slurping structs from file fails with string attributes containing whitespaces

2009-05-29 Thread Perttu

Hi.

I'm a n00b so bare with me. I have just started playing with Clojure
and the first thing I thought I'd try is storing and retrieving a list
of structs, like in Suart Halloway's example here:

http://github.com/stuarthalloway/practical-cl-clojure/blob/1c2f138bda5e73ebbbafbc2cea7e5cd14ec335c4/pcl/chap_03/chap_03.clj

My spit/slurp of a hash of structs works fine with, if I use struct
instances without spaces in the attribute strings like the following:

(struct customer "Apple" "InfiniteLoop")

But if I use this:

(struct customer "Apple" "Infinite Loop 1")

I get an error:

Exception in thread "main" clojure.lang.LispReader$ReaderException:
java.lang.ArrayIndexOutOfBoundsException: 7 (test-storing.clj:19)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2719)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:298)
at clojure.lang.Compiler.eval(Compiler.java:4537)
at clojure.lang.Compiler.load(Compiler.java:4857)
at clojure.lang.Compiler.loadFile(Compiler.java:4824)
at clojure.main$load_script__5833.invoke(main.clj:206)
at clojure.main$init_opt__5836.invoke(main.clj:211)
at clojure.main$initialize__5846.invoke(main.clj:239)
at clojure.main$null_opt__5868.invoke(main.clj:264)
at clojure.main$legacy_script__5883.invoke(main.clj:295)
at clojure.lang.Var.invoke(Var.java:346)
at clojure.main.legacy_script(main.java:34)
at clojure.lang.Script.main(Script.java:20)
Caused by: clojure.lang.LispReader$ReaderException:
java.lang.ArrayIndexOutOfBoundsException: 7
at clojure.lang.LispReader.read(LispReader.java:180)
at clojure.core$read__4168.invoke(core.clj:2083)
at clojure.core$read__4168.invoke(core.clj:2081)
at clojure.core$read__4168.invoke(core.clj:2079)
at clojure.core$read__4168.invoke(core.clj:2077)
at chap_03$load_db__54.invoke(chap_03.clj:71)
at clojure.lang.AFn.applyToHelper(AFn.java:173)
at clojure.lang.AFn.applyTo(AFn.java:164)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2714)
... 12 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 7
at clojure.lang.PersistentArrayMap$Seq.first(PersistentArrayMap.java:
216)
at clojure.lang.APersistentMap.hashCode(APersistentMap.java:101)
at clojure.lang.Util.hash(Util.java:55)
at clojure.lang.PersistentHashMap.entryAt(PersistentHashMap.java:134)
at clojure.lang.PersistentHashMap.containsKey(PersistentHashMap.java:
130)
at clojure.lang.APersistentSet.contains(APersistentSet.java:33)
at clojure.lang.PersistentHashSet.cons(PersistentHashSet.java:59)
at clojure.lang.PersistentHashSet.create(PersistentHashSet.java:34)
at clojure.lang.LispReader$SetReader.invoke(LispReader.java:974)
at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:540)
at clojure.lang.LispReader.read(LispReader.java:145)
... 20 more

Depending on the amount of the fields defined in the struct, I might
also just get a part of the string as an attribute name instead of the
error. For example :Loop 1

I use a store-function like this:

(defn store-customer-db [customer-db filename]
  (spit filename (with-out-str (print customer-db

And a read-function like this:

(defn load-db [filename]
  (with-in-str (slurp filename)(read)))

>From the output file of spit I can see that the print doesn't give
double quotes to the strings which seems to be a problem for slurp.
What would be the correct solution for this?

The Clojure version is 1.0, and contrib-lib is a few weeks old
snapshot.

Thanks,
Perttu

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: (gensym) not equivalent to #?

2009-05-29 Thread jdz

> Here are two functions the do roughly the same thing --
> return a list with a single gensym'ed symbol in it:
>
> (defn f-auto []
>   `(foo#))

Think about it this way: everything that is not unquoted in the body
of syntax-quote stays the same.  In other words, syntax-quote is like
regular quote, but with some things being dynamic; and the dynamic
things are only the ones that are unquoted.

Maybe this helps somebody understand this issue.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: How to hide functions from being imported?

2009-05-29 Thread Michael Wood

On Fri, May 29, 2009 at 8:44 AM, kinghajj  wrote:
>
> In Haskell, it's simple to explicitly state what names should be
> exported by a module. Is there a way to do this in Clojure?

I think this is what you're looking for:

user=> (doc defn-)
-
clojure.core/defn-
([name & decls])
Macro
  same as defn, yielding non-public def
nil

-- 
Michael Wood 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---