Re: Printing to *out* in another thread

2009-10-18 Thread Volkan YAZICI

On Sat, 17 Oct 2009, mbrodersen  writes:
> If you want to print to stdout from multiple threads without getting
> the printing garbeled you can do something like the following (it also
> logs all printed values):
>
> (def wa-debug-agent)
>
> (defn wa-debug-make []
>   (def wa-debug-agent (agent [])))
>
> (defn wa-debug-print
>   "This makes it possible to print from multiple threads without
> overlapping each other"
>   [& args]
>   (send wa-debug-agent
>   (fn [list v]
>   (apply println v)
>   (conj list v)) args))

Here is another variant using atoms instead.

  (defn serial-println [_ _ _ args]
(apply println args)
(flush))
  ; #'user/serial-println
  
  (def serial-stream (atom nil))
  ; #'user/serial-stream
  
  (add-watch serial-stream :default serial-println)
  ; #
  
  (defn serial-enqueue [& args]
(swap! serial-stream (fn [_] args)))
  ; #'user/serial-enqueue
  
  (def sprintln serial-enqueue)
  ; #'user/sprintln
  
  (dotimes [i 10]
(.run
 (Thread.
  #(let [d (rand-int 2000)]
 (Thread/sleep d)
 (sprintln "Id:" i "Duration:" d)
  ; Id: 0 Duration: 1228
  ; Id: 1 Duration: 1067
  ; Id: 2 Duration: 893
  ; Id: 2 Duration: 893
  ; Id: 3 Duration: 1482
  ; Id: 4 Duration: 1514
  ; Id: 5 Duration: 79
  ; Id: 6 Duration: 1966
  ; Id: 7 Duration: 730
  ; Id: 8 Duration: 1489
  ; Id: 9 Duration: 1919


Regards.

--~--~-~--~~~---~--~~
You 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: Printing to *out* in another thread

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 2:04 AM, Gorsal  wrote:
>
> I just tried this on the eclipse clojure repl, it works. So i guess it
> is an enclojure thing! (.println System/out "HI") also doesn't work on
> the netbeans repl, but does on the enclojure. I'll ask on the
> enclojure mailing group. Thanks for the help!


The Enclojure REPL has three tabs, REPL, OUT, and ERR. Anything sent to
*out* that doesn't show up in the REPL interaction should be looked for on
the OUT tab.

--~--~-~--~~~---~--~~
You 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: Bug: -main function corrupts applet

2009-10-18 Thread Andreas Wenger

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



Re: JVM Language Summit talk on state, identity, time

2009-10-18 Thread Garth Sheldon-Coulson
Nice, thanks.

On Sat, Oct 17, 2009 at 2:24 AM, Timothy Pratley
wrote:

>
> The slides match this:
> http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey
> [good recording - one of the best I've come across, gives a very
> persuasive reasoning of why Clojure 'has it right']
>
>
> On Oct 17, 7:58 am, Garth Sheldon-Coulson  wrote:
> > In his blog post Rich mentioned his JVM Language Summit talkhttp://
> wiki.jvmlangsummit.com/Clojure_Keynote
> > on state, identity, value, time, etc.
> >
> > There are notes and slides on the site, but no audio or video.
> >
> > Does anyone know if audio or video was recorded, or (if Rich is reading
> > this) if there are more comprehensive notes to be gotten?
> >
> > 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
-~--~~~~--~~--~--~---



Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Dmitry Kakurin

I need to run 3 separate filters on the same collection.
Can I do this in a single pass thru collection (as opposed to 3
separate passes)?
Basically I don't want to bind the head of 'idata' collection because
it holds the whole thing in memory. Also collection itself is coming
from a file.

Here is what I have right now:
  (let [idata ... something ...
sales
  (filter
#($ (% "Product Type Identifier") = "1" &&
 % "Vendor Identifier" = "01010012"
)
idata
  )
upgrades
  (filter
#($ % "Product Type Identifier" = "7" &&
% "Vendor Identifier" = "01010012"
)
idata
  )
demo
  (filter
#($ % "Product Type Identifier" = "1" &&
% "Vendor Identifier" = "01010318"
)
idata
  )
]
(println "Sales   : " (sum-units sales))
(println "Upgrades: " (sum-units upgrades))
(println "Demo: " (sum-units demo))

I can of cause write my own custom filter fn that would return 3
collections, but I'm wondering if there is a generic way to do it.

- Dmitry

--~--~-~--~~~---~--~~
You 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: Bug: -main function corrupts applet

2009-10-18 Thread Rich Hickey



On Oct 18, 5:47 am, Andreas Wenger 
wrote:
> *push*
> Can please anybody verify this bug? Should take only 3 minutes or so.

A NullPointerException in
sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel isn't enough to
go on. This could be anyone's bug, just because you can change
something in your Clojure code to trigger it doesn't mean the problem
is on the Clojure side.

Does one need main functions in applets?

I found this via googling:

http://www.java-forums.org/java-applets/19544-nullpointerexception-findappletjdklevel-unknown-source.html

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: Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Meikel Brandmeyer
Hi,

Am 18.10.2009 um 09:48 schrieb Dmitry Kakurin:

> Here is what I have right now:
>  (let [idata ... something ...
>sales
>  (filter
>#($ (% "Product Type Identifier") = "1" &&
> % "Vendor Identifier" = "01010012"
>)
>idata
>  )
>upgrades
>  (filter
>#($ % "Product Type Identifier" = "7" &&
>% "Vendor Identifier" = "01010012"
>)
>idata
>  )
>demo
>  (filter
>#($ % "Product Type Identifier" = "1" &&
>% "Vendor Identifier" = "01010318"
>)
>idata
>  )
>]
>(println "Sales   : " (sum-units sales))
>(println "Upgrades: " (sum-units upgrades))
>(println "Demo: " (sum-units demo))

Maybe you can do:

(reduce (fn [[sales upgrades demo :as v] data]
   (cond
 (is-sales? data)   [(conj sales data) upgrades demo]
 (is-upgrade? data) [sales (conj upgrades data) demo]
 (is-demo? data)[sales upgrades (conj demo data)]
 :else v))
 [[] [] []] (get-idata))

This will hold the resulting collections completely in memory, but not  
the idata part. This is maybe not what you want, because it's too big.  
Or it is what you want, because you want to close the file at some  
point in time. I think defining anything lazy will hold onto idata.  
(or at least part of the end results)

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


difference between into & concat

2009-10-18 Thread DemAS

Hi all,

I'm just wondering if there is any difference between 'into' and
'concat' ?

(def x (range 1 100 5))
(def y (range 1 100 10))
(concat x y)
(into x y)

I have found only one difference - the 'concat'-functon sorts resulted
list.
--~--~-~--~~~---~--~~
You 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: difference between into & concat

2009-10-18 Thread Alex Osborne

DemAS wrote:
> I'm just wondering if there is any difference between 'into' and
> 'concat' ?

There are actually more differences than similarities in my opinion. 
For starters, 'concat' can take more than 2 arguments:

   (concat [1 2] [3 4] [5 6])
   => (1 2 3 4 5 6)

'into' returns whatever collection type is passed in, so for a vector:

   (into [1 2] [3 4])
   => [1 2 3 4]

or a map:

   (into {:a 1} [[:b 2] [:c 3]])
   => {;a 1, :b 2, :c 3}

while 'concat' (being lazy) will always return a lazy seq:

   (concat [1 2] [3 4])
   => (1 2 3 4)

   (concat {:a 1} [[:b 2] [:c 3]])
   => ([:a 1] [:b 2] [:c 3])

> I have found only one difference - the 'concat'-functon sorts resulted
> list.

Neither of them do any sorting, even in your example with ranges the 
output is not sorted.

The difference in the ordering is because concat keeps the seqs (in your 
example ranges) ordered:

(concat (range 1 5) (range 11 15))
=> (1 2 3 4 11 12 13 14)

While 'into' just repeatedly applies the 'conj' function, which for a 
seq will add each element to the front of the seq, instead of the end, 
so the second range appears in reverse in front the first:

(into (range 1 5) (range 11 15))
=> (14 13 12 11 1 2 3 4)

When used on a vector however, 'conj' adds to the end, so we get:

(into (vec (range 1 5)) (range 11 15))
=> [1 2 3 4 11 12 13 14]

--~--~-~--~~~---~--~~
You 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: Dedicated thread for agent or creating thread pool for agent?

2009-10-18 Thread pmf

On Oct 18, 6:27 am, mbrodersen  wrote:
> I don't know SWT well enough to answer that. I am new to the JVM
> platform (after 20+ years of writing native C++ code).
>
> However, the question is not SWT specific. There will be other cases
> (for example OpenGL) where something like InvokeLater doesn't exist.

SWT's equivalent to Swing's SwingUtilities.invokeLater is
Display.asyncExec; the equivalent of SwingUtilities.invokeAndWait is
Display.syncExec (all four take a Runnable as an argument).
--~--~-~--~~~---~--~~
You 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: Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Alex Osborne

Meikel Brandmeyer wrote:
> Maybe you can do:
> 
> (reduce (fn [[sales upgrades demo :as v] data]
>(cond
>  (is-sales? data)   [(conj sales data) upgrades demo]
>  (is-upgrade? data) [sales (conj upgrades data) demo]
>  (is-demo? data)[sales upgrades (conj demo data)]
>  :else v))
>  [[] [] []] (get-idata))

Another variation:

(use 'clojure.contrib.seq-utils)

(defn record-type [data]
   (cond
 (is-sale? data) :sales
 (is-upgrade? data) :upgrades
 (is-demo? data) :demos))

(group-by record-type (filter record-type (get-idata)))

If the three output lists themselves are too large, I'd just explicitly 
sum your units with reduce:

(reduce
  (fn [counts data]
(let [type (record-type data)]
  (assoc counts type (+ (units data)
(get counts type 0)
  {} (get-idata))

=> {:sales 1233, :upgrades 17, :demos 42, nil 30}

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



ANN: Clojure live-repl

2009-10-18 Thread David Powell

Hi,

I just posted a project at .

It uses the Java Attach API to let you connect a Clojure REPL to any running 
Java or Clojure process, without them requiring any special startup.

It probably requires a Sun 1.6 JDK.  And currently the startup script is a 
batch file, so if anyone can knock a Bourne shell script together that would 
be cool.

-- 
Dave 


--~--~-~--~~~---~--~~
You 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: Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Alex Osborne

Alex Osborne wrote:

> If the three output lists themselves are too large, I'd just explicitly 
> sum your units with reduce:
> 
> (reduce
>   (fn [counts data]
> (let [type (record-type data)]
>   (assoc counts type (+ (units data)
> (get counts type 0)
>   {} (get-idata))
> 
> => {:sales 1233, :upgrades 17, :demos 42, nil 30}

Actually come to think of it, this sort of thing is common enough that 
you could pull out a 'reduce-by' function like this:

(defn reduce-by [grouper f val coll]
   (reduce
(fn [m x]
  (let [group (grouper x)]
(assoc m group (f (get m group val) x
(sorted-map) coll))

Then group-by could be easily defined in terms of it:

(defn group-by [f coll]
   (reduce-by f conj [] coll))

And it makes your unit summing example:

(reduce-by record-type
(fn [count data] (+ count (units data)))
0 (get-idata))

--~--~-~--~~~---~--~~
You 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: -> vs comp

2009-10-18 Thread Stuart Halloway

I find the suite of ->, ->>, anonymous functions, partial, and comp  
sufficient for my needs, with each having its place.

My only grumble is that "partial" is a lot of characters. I would love  
a one-character alternative, if it could be reasonably intuitive.

Stu

> On Oct 16, 10:22 pm, Sean Devlin  wrote:
>> In order to generate closures, every function should take parameters
>> first, and data at the end, so that they work well with partial.
>
> It's really hard to come up with a consistent practice that works well
> for all scenarios.  Even clojure.core is inconsistent in this regard
> -- the sequence fns take the seq at the end, the collection functions
> (like assoc) take the collection first.
>
> Whichever way you design your functions, half the time the arguments
> will be in the wrong place for what someone wants to do.  If you want
> a purely compositional style, the only way to do it is to only allow
> single-argument functions, a la Haskell.
>
> -SS
> >


--~--~-~--~~~---~--~~
You 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: -> vs comp

2009-10-18 Thread B Smith-Mannschott

On Sun, Oct 18, 2009 at 20:04, Stuart Halloway
 wrote:
>
> I find the suite of ->, ->>, anonymous functions, partial, and comp
> sufficient for my needs, with each having its place.
>
> My only grumble is that "partial" is a lot of characters. I would love
> a one-character alternative, if it could be reasonably intuitive.
>

F# uses >> for functional composition and |> for partial evaluation.
Both as infix operators, of course. Perhaps they'd work for clojure's
prefix syntax?

(def >> comp)
(def |> partial)

what do you think?

> Stu
>
>> On Oct 16, 10:22 pm, Sean Devlin  wrote:
>>> In order to generate closures, every function should take parameters
>>> first, and data at the end, so that they work well with partial.
>>
>> It's really hard to come up with a consistent practice that works well
>> for all scenarios.  Even clojure.core is inconsistent in this regard
>> -- the sequence fns take the seq at the end, the collection functions
>> (like assoc) take the collection first.
>>
>> Whichever way you design your functions, half the time the arguments
>> will be in the wrong place for what someone wants to do.  If you want
>> a purely compositional style, the only way to do it is to only allow
>> single-argument functions, a la Haskell.
>>
>> -SS
>> >
>
>
> >
>

--~--~-~--~~~---~--~~
You 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: Clojure live-repl

2009-10-18 Thread Alex Osborne

David Powell wrote:
> It uses the Java Attach API to let you connect a Clojure REPL to any running 
> Java or Clojure process, without them requiring any special startup.

Exceedingly cool!

> It probably requires a Sun 1.6 JDK.  And currently the startup script is a 
> batch file, so if anyone can knock a Bourne shell script together that would 
> be cool.

This worked for me:

http://gist.github.com/212785

--~--~-~--~~~---~--~~
You 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: Discuss: Add a :let "special expression" to cond

2009-10-18 Thread Howard Lewis Ship

Seem to be hitting a problem.

(defmacro cond
  "Takes a set of test/expr pairs. It evaluates each test one at a
  time.  If a test returns logical true, cond evaluates and returns
  the value of the corresponding expr and doesn't evaluate any of the
  other tests or exprs. As a special case, a test of :let injects
  an implicit let (the expression should be a vector of binding forms).
  The new bindings may be referenced in later tests and expressions.
  (cond) returns nil."
  [& clauses]
  (when clauses
; Jumping through many hoops, as cond is fundamental to many
; other basic forms such as let.
(if-not (next clauses)
  (throw (IllegalArgumentException. "cond requires an even number
of forms")))

`(~@(if (= (first clauses) :let)
  (list 'clojure.core/let (second clauses))
  (list 'if (first clauses) (second clauses)))
  (clojure.core/cond ~@(next (next clauses))

This works for normal uses of cond (I had to move it after (defn =) though).

However, when I try to use :let, I get a StackOverflowException:

at clojure.lang.PersistentList$1.doInvoke(PersistentList.java:32)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply__4293.invoke(core.clj:395)
at clojure.walk$walk__7846.invoke(walk.clj:54)
at clojure.walk$prewalk__7852.invoke(walk.clj:74)
at clojure.lang.AFn.applyToHelper(AFn.java:175)
at clojure.lang.AFn.applyTo(AFn.java:164)
at clojure.core$apply__4293.invoke(core.clj:397)
at clojure.core$partial__4968$fn__4970.doInvoke(core.clj:1639)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$map__5005$fn__5007.invoke(core.clj:1724)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
at 
clojure.lang.LazilyPersistentVector.create(LazilyPersistentVector.java:31)
at clojure.core$vec__4219.invoke(core.clj:256)
at clojure.walk$walk__7846.invoke(walk.clj:56)
at clojure.walk$prewalk__7852.invoke(walk.clj:74)
at clojure.lang.AFn.applyToHelper(AFn.java:175)
at clojure.lang.AFn.applyTo(AFn.java:164)
at clojure.core$apply__4293.invoke(core.clj:397)
at clojure.core$partial__4968$fn__4970.doInvoke(core.clj:1639)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$map__5005$fn__5007.invoke(core.clj:1726)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.Cons.next(Cons.java:37)
at clojure.lang.PersistentList$1.doInvoke(PersistentList.java:32)

I suspect this is to do with the fact that the let macro destructures
the bindings, and the function for that uses cond. I can't quite wrap
my head around the cause-and-effect however. I just don't see why it
expands infinitely, because the uses of cond inside
destructure-bindings will not be using the :let option, so any uses of
cond will be the simple working case (expanding into deeply nested
ifs).

I'm considering an alternative approach, where the cond macro is
redefined at the end of the core.clj, but that seems pretty crude and
may also not work.

On Sat, Oct 17, 2009 at 6:07 PM, Howard Lewis Ship  wrote:
> Here's my implementation. Seems to be working fine. I like it.
>
> http://github.com/hlship/cascade/blob/master/src/main/clojure/cascade/utils.clj
> http://github.com/hlship/cascade/blob/master/src/test/clojure/cascade/test_utils.clj
>
> On Sat, Oct 17, 2009 at 5:06 PM, Howard Lewis Ship  wrote:
>> Coming right up!
>>
>> On Sat, Oct 17, 2009 at 9:14 AM, Sean Devlin  
>> wrote:
>>>
>>> So you have a working version of this macro, as well as some use cases
>>> in actual code?  This would help the discussion a lot.
>>>
>>> Thanks!
>>>
>>> On Oct 17, 10:43 am, Howard Lewis Ship  wrote:
 I keep coming into situations where I'd like a let in the middle of my
 cond.  I often do a couple of tests, then would like to lock down some
 symbols that I'll use frequently in the remaining cases.

 There's a precedent for this, in that the for macro allows a :let as
 an alternative to a list interpolation term.

 I'm working on my own implementation of cond to support this and would
 like to see it in core.

 Thoughts?

 --
 Howard M. Lewis Ship

 Creator of Apache Tapestry

 The source for Tapestry training, mentoring and support. Contact me to
 learn how I can get you up and productive in Tapestry fast!

 (971) 678-5210http://howardlewisship.com
>>> >>>
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apac

Re: -> vs comp

2009-10-18 Thread Sean Devlin

I've been using & and p, respectively.

On Oct 18, 2:21 pm, B Smith-Mannschott  wrote:
> On Sun, Oct 18, 2009 at 20:04, Stuart Halloway
>
>  wrote:
>
> > I find the suite of ->, ->>, anonymous functions, partial, and comp
> > sufficient for my needs, with each having its place.
>
> > My only grumble is that "partial" is a lot of characters. I would love
> > a one-character alternative, if it could be reasonably intuitive.
>
> F# uses >> for functional composition and |> for partial evaluation.
> Both as infix operators, of course. Perhaps they'd work for clojure's
> prefix syntax?
>
> (def >> comp)
> (def |> partial)
>
> what do you think?
>
>
>
> > Stu
>
> >> On Oct 16, 10:22 pm, Sean Devlin  wrote:
> >>> In order to generate closures, every function should take parameters
> >>> first, and data at the end, so that they work well with partial.
>
> >> It's really hard to come up with a consistent practice that works well
> >> for all scenarios.  Even clojure.core is inconsistent in this regard
> >> -- the sequence fns take the seq at the end, the collection functions
> >> (like assoc) take the collection first.
>
> >> Whichever way you design your functions, half the time the arguments
> >> will be in the wrong place for what someone wants to do.  If you want
> >> a purely compositional style, the only way to do it is to only allow
> >> single-argument functions, a la Haskell.
>
> >> -SS
--~--~-~--~~~---~--~~
You 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: -> vs comp

2009-10-18 Thread Robert Fischer

The F# language does partial application through calling the function: if you 
don't supply enough 
arguments, they're partially applied.  The |> syntax is for "backwards" 
(object-y)  partial application:

let f x y = ...
let g = f 1
let h = 1 |> f

The |> operator is built-in in F#, but in OCaml (my background), |> can be 
defined easily enough:
let (|>) x f = f x

~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog

Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/gormbook


B Smith-Mannschott wrote:
> On Sun, Oct 18, 2009 at 20:04, Stuart Halloway
>  wrote:
>> I find the suite of ->, ->>, anonymous functions, partial, and comp
>> sufficient for my needs, with each having its place.
>>
>> My only grumble is that "partial" is a lot of characters. I would love
>> a one-character alternative, if it could be reasonably intuitive.
>>
> 
> F# uses >> for functional composition and |> for partial evaluation.
> Both as infix operators, of course. Perhaps they'd work for clojure's
> prefix syntax?
> 
> (def >> comp)
> (def |> partial)
> 
> what do you think?
> 
>> Stu
>>
>>> On Oct 16, 10:22 pm, Sean Devlin  wrote:
 In order to generate closures, every function should take parameters
 first, and data at the end, so that they work well with partial.
>>> It's really hard to come up with a consistent practice that works well
>>> for all scenarios.  Even clojure.core is inconsistent in this regard
>>> -- the sequence fns take the seq at the end, the collection functions
>>> (like assoc) take the collection first.
>>>
>>> Whichever way you design your functions, half the time the arguments
>>> will be in the wrong place for what someone wants to do.  If you want
>>> a purely compositional style, the only way to do it is to only allow
>>> single-argument functions, a la Haskell.
>>>
>>> -SS
>>
> 
> > 
> 

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



Contrib (1.0 compatible) succeeds (but fails :-)

2009-10-18 Thread Joubert Nel

Hi,

When I try to build the 1.0 compatible branch of clojure.contrib using
Clojure 1.0 I get the following two FileNotFoundExceptions:

1) [java] java.io.FileNotFoundException: Could not locate clojure/
stacktrace__init.class or clojure/stacktrace.clj on classpath:
(jmx.clj:10)
2) [java] java.io.FileNotFoundException: Could not locate clojure/
walk__init.class or clojure/walk.clj on classpath:  (dataflow.clj:17)

A clojure-contrib.jar gets produced but obviously something's wrong.

Thoughts?


--~--~-~--~~~---~--~~
You 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: Printing to *out* in another thread

2009-10-18 Thread Gorsal

Dang, you're ri ght, I didn't even notice. This is a nice feature,
separating everything. 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
-~--~~~~--~~--~--~---



Re: ANN: Clojure live-repl

2009-10-18 Thread Michael Wood

2009/10/18 David Powell :
> I just posted a project at .
>
> It uses the Java Attach API to let you connect a Clojure REPL to any running
> Java or Clojure process, without them requiring any special startup.

That's very cool :)

> It probably requires a Sun 1.6 JDK.  And currently the startup script is a

I tried with:

java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu11)
OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)

and I can attach, but if the process I attach to exits, I get a
never-ending stream of \xef \xbf \xbf characters:

  75 73 65 72 3d 3e 20 ef  bf bf ef bf bf ef bf bf  |user=> .|
0010  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef  ||
0020  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf  ||
[...]

Also, I can't exit with Ctrl-D as is possible with a normal REPL.
Ctrl-C works, though.

Both very minor issues, but I thought I'd mention them in case they're
easy to fix.

I would love to see an example or two of how one could use this.  :)

-- 
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: ANN: Clojure live-repl

2009-10-18 Thread Gorsal

That's very slick. I'm going to use 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
-~--~~~~--~~--~--~---



What do you use for asdf-like functionality?

2009-10-18 Thread Gorsal

Coming from lisp, i am used to an asdf like functionality. Recently I
have been reorganizing my code and placing all my general utilities
under one package, utils. Under it i have a file for each time of
utility, string, macro, etc. Then i have a package.clj file.
Basically, I want the user to be able to import one ns,
'utils.package', and gain access to all of my utilities. Each utility
has a (in-ns 'utils.package) statement so that if it is loaded the
code will go in that ns.

What i need is to load the package.clj file and for that to then load
all the other files in order based on dependency. I could, of course,
simply go (load "string"), etc, or create a macro to do it, but I was
interested in how others do this. Would it be worth adding some asdf-
like functionality to the language?
--~--~-~--~~~---~--~~
You 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: Contrib (1.0 compatible) succeeds (but fails :-)

2009-10-18 Thread Michael Wood

2009/10/18 Joubert Nel :
>
> Hi,
>
> When I try to build the 1.0 compatible branch of clojure.contrib using
> Clojure 1.0 I get the following two FileNotFoundExceptions:
>
> 1) [java] java.io.FileNotFoundException: Could not locate clojure/
> stacktrace__init.class or clojure/stacktrace.clj on classpath:
> (jmx.clj:10)
> 2) [java] java.io.FileNotFoundException: Could not locate clojure/
> walk__init.class or clojure/walk.clj on classpath:  (dataflow.clj:17)
>
> A clojure-contrib.jar gets produced but obviously something's wrong.
>
> Thoughts?

I've just tried it now and it works fine for me, as long as I make
sure to run "ant clean" first.  I had clojure-contrib master checked
out built, then I switched to the clojure-1.0-compatible branch and
tried to build it with:

$ ant -Dclojure.jar=/path/to/clojure-1.0.0.jar

I then remembered I hadn't cleaned out the bits compiled from master
and did so.  After that it worked fine.

Mine failed with a NoSuchMethodError rather than a
FileNotFoundException, but maybe it's a similar problem?  i.e. try
"ant clean" and see if that fixes it.

-- 
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: La Clojure plugin for IntelliJ IDEA moved to Git

2009-10-18 Thread Ilya Sergey
Hi all.

The repository
git://git.jetbrains.org/idea/clojure-plugin.git
must work now. Sorry for the inconvenience.

Cheers!
Ilya

2009/10/18 Kurman Karabukaev 

>
> Hi Ilya, it is asking for password for
> git.labs.intellij.net:idea/clojure-plugin URL.
>
> Kurman
>
> On Sat, Oct 17, 2009 at 12:19 PM, Ilya Sergey  wrote:
> > Ok, try this:
> >
> > g...@git.labs.intellij.net:idea/clojure-plugin
> >
> > Cheers!
> > Ilya
> >
> > 2009/10/17 B Smith-Mannschott 
> >>
> >> On Sat, Oct 17, 2009 at 18:21, Ilya Sergey  wrote:
> >> > Hi all.
> >> >
> >> > After the long silence we resume work on `La Clojure' plugin for
> >> > IntelliJ
> >> > IDEA. It is still open-source and available now for IntelliJ IDEA 9
> >> > Community Edition. The repository may be cloned now from
> >> > git://git.jetbrains.org/idea/clojure-plugin.git
> >> > To build the plugin from scratch you need the latest of Clojure and
> >> > clojure-contrib jars, so before running ant don't forget to edit
> >> > clojure.properties file in the root of the `clojure-plugin' project as
> >> > appropriate.
> >>
> >> No joy. Has your git server gotten slashdotted?
> >>
> >> [bsm...@meheadable:~/w]
> >> $ git clone --bare git://git.jetbrains.org/idea/clojure-plugin.git
> >> idea-clojure-plugin.git
> >> Initialized empty Git repository in
> >> /Users/bsmith/w/idea-clojure-plugin.git/
> >> fatal: The remote end hung up unexpectedly
> >>
> >> // Ben
> >>
> >>
> >
> >
> > >
> >
>
> >
>

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



Using 'future' ?

2009-10-18 Thread Gorsal

I'm attempting to use the function future to start something in
another thread. However, in the netbeans enclojure plugin, when i type
it into the repl, it becomes non-responsive. Is this just a bug in the
enclojure plugin or would this be normal?

(future
(let [input-stream (:input-stream *lisp*)]
 (loop [the-char (.read input-stream)]
   (if (not (= the-char -1)) (jprint (char the-char)))
   (recur (.read input-stream)

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



deftest metadata

2009-10-18 Thread Phil Hagelberg


It's a fairly common idiom in other languages to have your test suite
broken up into unit tests and higher-level integration tests.

I've implemented this for one of my projects using metadata on each test
var. Unfortunately the current implementation of deftest does not
provide a way to set metadata this way, so I had to create a deftest*
macro that takes a metadata map argument.

Would it be a good idea to change deftest so that it accepts an optional
metadata map just like defn? I can implement it if it's wanted.

thanks,
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: What do you use for asdf-like functionality?

2009-10-18 Thread Richard Newman

> What i need is to load the package.clj file and for that to then load
> all the other files in order based on dependency.

See clojure.contrib.immigrate. It doesn't do dependency tracking, but  
it doesn't need to: each sub-package should require or use those it  
needs.

--~--~-~--~~~---~--~~
You 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 do you use for asdf-like functionality?

2009-10-18 Thread Gorsal

Now that I think about it im guessing ant is used. Though if i don't
want to compile the clojure files, i guess i might be able to use
lancelet to simply define a series of loading? Perhaps...
--~--~-~--~~~---~--~~
You 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
-~--~~~~--~~--~--~---



A-Star Search Implementation

2009-10-18 Thread Josh

Hi,

To teach myself Clojure and A-Star search, I mocked up a quick demo
program. I don't know if anyone else would be interested in seeing it,
but it demos a few things, including calling Clojure from Java,
building / running from a Maven environment, and of course A-Star.

I'd appreciate any critiques on my Clojure technique, and if the A-
Star implementation is useful to you, feel free to use it for any
purpose.

http://www.offthehill.org/articles/2009/10/16/a-star-search-in-clojure/

I suppose an interesting addition would be to define the dataset /
graph in Java and have Clojure run the search on it. I'm not sure how
best to map Clojure structures to Java objects, so I'd have to think
about that for a bit.

--~--~-~--~~~---~--~~
You 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: La Clojure plugin for IntelliJ IDEA moved to Git

2009-10-18 Thread Mark Derricutt
Where should we raise tickets/issues for the plugin?  One thing I'm really
still missing with it is auto completion of aliased namespaces:

(ns foo
  (:require foo.bar.test :as test))

(defn hello []
  (test/do-something))

Having the completion of a) the test alias, and b) the contents of test
inside hello would be a godsend.


On Mon, Oct 19, 2009 at 10:56 AM, Ilya Sergey  wrote:

> Hi all.
>
> The repository
> git://git.jetbrains.org/idea/clojure-plugin.git
> must work now. Sorry for the inconvenience.
>
> Cheers!
> Ilya
>
> 2009/10/18 Kurman Karabukaev 
>
>
>> Hi Ilya, it is asking for password for
>> git.labs.intellij.net:idea/clojure-plugin URL.
>>
>> Kurman
>>
>> On Sat, Oct 17, 2009 at 12:19 PM, Ilya Sergey  wrote:
>> > Ok, try this:
>> >
>> > g...@git.labs.intellij.net:idea/clojure-plugin
>> >
>> > Cheers!
>> > Ilya
>> >
>> > 2009/10/17 B Smith-Mannschott 
>> >>
>> >> On Sat, Oct 17, 2009 at 18:21, Ilya Sergey  wrote:
>> >> > Hi all.
>> >> >
>> >> > After the long silence we resume work on `La Clojure' plugin for
>> >> > IntelliJ
>> >> > IDEA. It is still open-source and available now for IntelliJ IDEA 9
>> >> > Community Edition. The repository may be cloned now from
>> >> > git://git.jetbrains.org/idea/clojure-plugin.git
>> >> > To build the plugin from scratch you need the latest of Clojure and
>> >> > clojure-contrib jars, so before running ant don't forget to edit
>> >> > clojure.properties file in the root of the `clojure-plugin' project
>> as
>> >> > appropriate.
>> >>
>> >> No joy. Has your git server gotten slashdotted?
>> >>
>> >> [bsm...@meheadable:~/w]
>> >> $ git clone --bare git://git.jetbrains.org/idea/clojure-plugin.git
>> >> idea-clojure-plugin.git
>> >> Initialized empty Git repository in
>> >> /Users/bsmith/w/idea-clojure-plugin.git/
>> >> fatal: The remote end hung up unexpectedly
>> >>
>> >> // Ben
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>>
>>
>
> >
>

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



Clojure Cheat Sheet

2009-10-18 Thread Gorsal

All right, so this is probably way off topic, but what software was
used to create the clojure cheat sheet?
http://clojure.org/cheatsheet
I really like the format and would like to make one for my own
utilities so that I can actually remember what general utility
functions i have written!
--~--~-~--~~~---~--~~
You 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: La Clojure plugin for IntelliJ IDEA moved to Git

2009-10-18 Thread Wilson MacGyver

One thing I'd really like to see for the plugin is to support a way to
"expand" macros.
Sometimes it's hard to understand the macros. It would be great if
from the IDE, you can
"expand" the macro to the normal form.

I don't think I've ever see this in any lisp IDE before.

On Sun, Oct 18, 2009 at 6:56 PM, Mark Derricutt  wrote:
> Where should we raise tickets/issues for the plugin?  One thing I'm really
> still missing with it is auto completion of aliased namespaces:
> (ns foo
>   (:require foo.bar.test :as test))
> (defn hello []
>   (test/do-something))
> Having the completion of a) the test alias, and b) the contents of test
> inside hello would be a godsend.
>
> On Mon, Oct 19, 2009 at 10:56 AM, Ilya Sergey  wrote:
>>
>> Hi all.
>>
>> The repository
>> git://git.jetbrains.org/idea/clojure-plugin.git
>> must work now. Sorry for the inconvenience.
>>
>> Cheers!
>> Ilya
>>
>> 2009/10/18 Kurman Karabukaev 
>>>
>>> Hi Ilya, it is asking for password for
>>> git.labs.intellij.net:idea/clojure-plugin URL.
>>>
>>> Kurman
>>>
>>> On Sat, Oct 17, 2009 at 12:19 PM, Ilya Sergey  wrote:
>>> > Ok, try this:
>>> >
>>> > g...@git.labs.intellij.net:idea/clojure-plugin
>>> >
>>> > Cheers!
>>> > Ilya
>>> >
>>> > 2009/10/17 B Smith-Mannschott 
>>> >>
>>> >> On Sat, Oct 17, 2009 at 18:21, Ilya Sergey  wrote:
>>> >> > Hi all.
>>> >> >
>>> >> > After the long silence we resume work on `La Clojure' plugin for
>>> >> > IntelliJ
>>> >> > IDEA. It is still open-source and available now for IntelliJ IDEA 9
>>> >> > Community Edition. The repository may be cloned now from
>>> >> > git://git.jetbrains.org/idea/clojure-plugin.git
>>> >> > To build the plugin from scratch you need the latest of Clojure and
>>> >> > clojure-contrib jars, so before running ant don't forget to edit
>>> >> > clojure.properties file in the root of the `clojure-plugin' project
>>> >> > as
>>> >> > appropriate.
>>> >>
>>> >> No joy. Has your git server gotten slashdotted?
>>> >>
>>> >> [bsm...@meheadable:~/w]
>>> >> $ git clone --bare git://git.jetbrains.org/idea/clojure-plugin.git
>>> >> idea-clojure-plugin.git
>>> >> Initialized empty Git repository in
>>> >> /Users/bsmith/w/idea-clojure-plugin.git/
>>> >> fatal: The remote end hung up unexpectedly
>>> >>
>>> >> // Ben
>>> >>
>>> >>
>>> >
>>> >
>>> > >
>>> >
>>>
>>>
>>
>>
>>
>
>
> >
>



-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 5:59 PM, Gorsal  wrote:

>
> I'm attempting to use the function future to start something in
> another thread. However, in the netbeans enclojure plugin, when i type
> it into the repl, it becomes non-responsive. Is this just a bug in the
> enclojure plugin or would this be normal?
>
> (future
>(let [input-stream (:input-stream *lisp*)]
> (loop [the-char (.read input-stream)]
>   (if (not (= the-char -1)) (jprint (char the-char)))
>   (recur (.read input-stream)
>

We'd need to know more about the vars specific to your project named here,
notably *lisp* and jprint. The latter is called as a function or macro and
the former holds an input stream. If it redirects standard input, in
particular, that will redirect it away from the REPL.

Most likely, though, it's an unfortunate effect of how futures print
themselves:

user=> (future (* 3 4))
#

As you can see, futures get their values to print themselves. So executing
any (future ...) expression at the REPL causes the REPL to block until the
future spits out a result. If that input stream is not generating an EOF for
a while, the REPL isn't responding again for a while.

It's hard to use a future unless you keep a reference to it, so I suggest
evaluating (def foo (future ...)) at the REPL:

user=> (future (do (Thread/sleep 1000) (println "boo!") (* 3 4)))
boo!
#

There should be a second's delay before the boo! and the rest of the output
appears.

(Enclojure users will find the "boo!" in the *out* pane rather than the Repl
pane after executing this.)

user=> (def calc-twelve (future (Thread/sleep 1000) (do (println "boo!") (*
3 4
#'user/calc-twelve
user=>
boo!

This time, the #'user/calc-twelve and the next user=> prompt should appear
instantly, and after a second's delay, the boo! should appear. (Again,
enclojure users will find the boo! in a different pane. They can make the
delay bigger, say changing 1000 to 1, see the next prompt appear, switch
to the *out* pane, and watch the boo! appear after a few more seconds.)

--~--~-~--~~~---~--~~
You 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: Clojure live-repl

2009-10-18 Thread David Powell


> and I can attach, but if the process I attach to exits, I get a
> never-ending stream of \xef \xbf \xbf characters:
>
>   75 73 65 72 3d 3e 20 ef  bf bf ef bf bf ef bf bf  |user=> 
> .|
> 0010  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef 
> ||
> 0020  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf 
> ||
> [...]
>
> Also, I can't exit with Ctrl-D as is possible with a normal REPL.
> Ctrl-C works, though.
>
> Both very minor issues, but I thought I'd mention them in case they're
> easy to fix.

I've made a fix to handle end-of-stream checking.  Wonder if that fixes the 
other problem too?

--
Dave
 


--~--~-~--~~~---~--~~
You 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: La Clojure plugin for IntelliJ IDEA moved to Git

2009-10-18 Thread eyeris

Once I build the plugin with the latest clojure, can I use it to write
code targeting 1.0?



On Oct 17, 11:21 am, Ilya Sergey  wrote:
> Hi all.
>
> After the long silence we resume work on `La Clojure' plugin for IntelliJ
> IDEA. It is still open-source and available now for IntelliJ IDEA 9
> Community Edition. The repository may be cloned now from
> git://git.jetbrains.org/idea/clojure-plugin.git
> To build the plugin from scratch you need the latest of Clojure and
> clojure-contrib jars, so before running ant don't forget to edit
> clojure.properties file in the root of the `clojure-plugin' project as
> appropriate.
>
> Cheers!
> Ilya
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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: Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Timothy Pratley



On Oct 19, 4:54 am, Alex Osborne  wrote:
> (reduce-by record-type
>             (fn [count data] (+ count (units data)))
>             0 (get-idata))

Wow - that is a really nice abstraction!

Kind of leads to SQLalike queries:

(defn select-count
  [grouper coll]
  (reduce-by grouper (fn [x _] (inc x)) 0 coll))

(defn select-sum
  [summer grouper coll]
  (reduce-by grouper (fn [x row] (+ x (summer row))) 0 coll))

(let [owners #{{:name "dorris" :sale 5}
   {:name "joe" :sale 2}
   {:name "dorris" :sale 2}
   {:name "joe" :sale 2}
   {:name "carol" :sale 2}
   {:name "louise" :sale 2}}]
  (select-sum :sale :name owners))
#_({"carol" 2, "dorris" 7, "joe" 2, "louise" 2})


--~--~-~--~~~---~--~~
You 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: deftest metadata

2009-10-18 Thread Timothy Pratley



On Oct 19, 9:32 am, Phil Hagelberg  wrote:
> It's a fairly common idiom in other languages to have your test suite
> broken up into unit tests and higher-level integration tests.
>
> I've implemented this for one of my projects using metadata on each test
> var. Unfortunately the current implementation of deftest does not
> provide a way to set metadata this way, so I had to create a deftest*
> macro that takes a metadata map argument.
>
> Would it be a good idea to change deftest so that it accepts an optional
> metadata map just like defn? I can implement it if it's wanted.
>
> thanks,
> Phil


I would like this very much so +1 from me fwiw :)

--~--~-~--~~~---~--~~
You 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: deftest metadata

2009-10-18 Thread George Jahad

Seems like a good idea to be able to set metadata on test vars.  I
work on the project Phil mentions above, and it does come in handy
for categorizing tests.


--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Timothy Pratley



> Most likely, though, it's an unfortunate effect of how futures print
> themselves:
>
> user=> (future (* 3 4))
> #

I agree - this is the cause, if you really wanted to do this at the
REPL maybe you can get around it like this:
user=> (do (future (* 3 4)) nil)
nil


--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Gorsal

Thanks, this works.
--~--~-~--~~~---~--~~
You 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: Best way to run multiple filters on the same [lazy] collection?

2009-10-18 Thread Alex Osborne

Dmitry Kakurin wrote:
> I actually like your "tag them then group them" approach.
> But what if the same record can have multiple tags?
> E.g. :sales and :upgrades?
> 

Hmmm. the first way that occurred to me is just make your tagging 
function return a set:

(defn record-types [x]
  (disj
   #{(when (is-sale? x) :sales)
 (when (is-upgrade? x) :upgrades)
 (when (is-demo? x) :demos)}
   nil))

So you'd then get groups like:

{#{:sales :upgrades} [...]
  #{:sales}   [...]
  #{:upgrades}[...]}

But unfortunately it seems that because the group-by in 
clojure.contrib.seq-utils uses a sorted-map it can't have keys that are 
sets (as there's no ordering defined for sets).  You could either use 
vectors instead of sets, or better yet lets just define reduce-by and 
group-by to use a hash-map instead:

(defn reduce-by [grouper f val coll]
(reduce (fn [m x]
  (let [group (grouper x)]
(assoc m group (f (get m group val) x
{} coll))

(defn group-by [grouper coll]
   (reduce-by grouper conj [] coll))

This has the advantage that you can do things like intersections 
("number of sales sales that were also upgrades").  If you don't care 
about intersections and just want the three :sales, :upgrades, and 
:demos lists, then I guess we start with 'for' to generate [tag record] 
pairs:

(for [record (get-idata)
   type (record-types record)]
   [type record])

So if "data1" is both sales and upgrades then you'd get:

   ([:sales data1] [:upgrades data1] [:sales data2] [:demos data3] ...)

We can then reduce-by grouped on the first value in the pair (the tag) 
and then transform the resulting maps to select just the second item in 
the pair (the record):

(reduce-by
  first #(conj %1 (second %2)) []
  (for [record (get-idata)
type (record-types record)]
[type record]))

=> {:sales [data1 data2 ... ],
 :upgrades [data1 data3 ...],
 :demos [data4 ...]}

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Gorsal

Hey, is there any way to separate the out view from the repl view so i
don't have to switch back and forth?
--~--~-~--~~~---~--~~
You 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
-~--~~~~--~~--~--~---



Using synchronized keyword

2009-10-18 Thread Gorsal

I was wondering how to used the java keyword synchronized in clojure?
--~--~-~--~~~---~--~~
You 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 synchronized keyword

2009-10-18 Thread Alex Osborne

Gorsal wrote:
> I was wondering how to used the java keyword synchronized in clojure?

http://clojure.org/api#locking

Java: synchronized(foo) { ... }
Clojure: (locking foo ...)

--~--~-~--~~~---~--~~
You 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: deftest metadata

2009-10-18 Thread Stuart Halloway

+1, we'd use this immediately.

> On Oct 19, 9:32 am, Phil Hagelberg  wrote:
>> It's a fairly common idiom in other languages to have your test suite
>> broken up into unit tests and higher-level integration tests.
>>
>> I've implemented this for one of my projects using metadata on each  
>> test
>> var. Unfortunately the current implementation of deftest does not
>> provide a way to set metadata this way, so I had to create a deftest*
>> macro that takes a metadata map argument.
>>
>> Would it be a good idea to change deftest so that it accepts an  
>> optional
>> metadata map just like defn? I can implement it if it's wanted.
>>
>> thanks,
>> Phil
>
>
> I would like this very much so +1 from me fwiw :)
>
> >


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

2009-10-18 Thread ngocdaothanh

The bottom of that page says: Original source (pdf, tex). So it is
probably TeX.


On Oct 19, 8:06 am, Gorsal  wrote:
> All right, so this is probably way off topic, but what software was
> used to create the clojure cheat sheet?http://clojure.org/cheatsheet
> I really like the format and would like to make one for my own
> utilities so that I can actually remember what general utility
> functions i have written!
--~--~-~--~~~---~--~~
You 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 Cheat Sheet

2009-10-18 Thread Gorsal

lo, never looked at the bottom. I shall do that next time! 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
-~--~~~~--~~--~--~---



Re: Using 'future' ?

2009-10-18 Thread Gorsal

So now that the future is working, I'm attempting to print from an
actual java thread. Like this

(defmacro with-thread [nm & body]
  `(let [thread# (Thread. #(fn [] (do ~...@body)))]
 ~@(if nm `((.setName thread# ~nm)))
 (.start thread#)
 thread#))

(with-thread nil (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))

Except no output! Eeek!!! What am i doing wrong?
--~--~-~--~~~---~--~~
You 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: Dedicated thread for agent or creating thread pool for agent?

2009-10-18 Thread mbrodersen

> SWT's equivalent to Swing's SwingUtilities.invokeLater is
> Display.asyncExec; the equivalent of SwingUtilities.invokeAndWait is
> Display.syncExec (all four take a Runnable as an argument).

Thanks pmf! That at least solves the immediate problem.

--~--~-~--~~~---~--~~
You 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: Printing to *out* in another thread

2009-10-18 Thread mbrodersen

Using atoms is not a good idea. Unless you don't mind if the same
message is sometimes printed more than once. Atoms are implemented
using spin locks with automatic retry.

Cheers
Morten

--~--~-~--~~~---~--~~
You 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: Printing to *out* in another thread

2009-10-18 Thread mbrodersen

> Using atoms is not a good idea. Unless you don't mind if the same
> message is sometimes printed more than once. Atoms are implemented
> using spin locks with automatic retry.

Hmmm...unless add-watch => observer is called only once.

So I might be wrong :-)

Interesting. Anybody knows more about this?

Thanks
Morten

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread John Harrop
On Sun, Oct 18, 2009 at 10:22 PM, Gorsal  wrote:
>
> Hey, is there any way to separate the out view from the repl view so i
> don't have to switch back and forth?
>

In Enclojure? Unfortunately, apparently not. It's possible to undock the
REPL and make it a free-floating window, but all three of the tabs Repl,
*err*, and *out* come with it. There doesn't seem to be a way to separate
these from one another.

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Timothy Pratley


On Oct 19, 3:39 pm, Gorsal  wrote:
> Except no output! Eeek!!! What am i doing wrong?

Looks like #(fn ... is meant to be #(do ~...@body)
#(fn declares a function which creates a function, so your thread is
returning a function instead of executing it.

user=> (macroexpand-1 '(with-thread nil (println
"HasdfasdfasdfasdfasdfasdfasdfasdfI")))
(clojure.core/let [thread__2__auto__ (java.lang.Thread. (fn* []
(clojure.core/fn [] (do (println
"HasdfasdfasdfasdfasdfasdfasdfasdfI")] (.start thread__2__auto__)
thread__2__auto__)


--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Adrian Cuthbertson

The following seems to do it;

(defmacro with-thread [nm & body]
 `(let [thread# (Thread. (fn [] (do ~...@body)))]
(if ~nm (.setName thread# ~nm))
(.start thread#)
thread#))

(with-thread "foo" (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
#
user=> HasdfasdfasdfasdfasdfasdfasdfasdfI

Also, macroexpand-1 really helps when writing macros. You can see
exactly how it's being expanded and it's then somewhat easier to
debug;

(macroexpand-1 '(with-thread nil (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
(clojure.core/let [thread__112__auto__ (java.lang.Thread.
(clojure.core/fn [] (do (println
"HasdfasdfasdfasdfasdfasdfasdfasdfI"] (if nil (.setName
thread__112__auto__ nil)) (.start thread__112__auto__)
thread__112__auto__)

Regards, Adrian.

On Mon, Oct 19, 2009 at 6:39 AM, Gorsal  wrote:
>
> So now that the future is working, I'm attempting to print from an
> actual java thread. Like this
>
> (defmacro with-thread [nm & body]
>  `(let [thread# (Thread. #(fn [] (do ~...@body)))]
>     ~@(if nm `((.setName thread# ~nm)))
>     (.start thread#)
>     thread#))
>
> (with-thread nil (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
>
> Except no output! Eeek!!! What am i doing wrong?
> >
>

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



college courses

2009-10-18 Thread cej38

Does anyone know of any college courses that are using Clojure?  For
example, instead of LISP in an AI course?
--~--~-~--~~~---~--~~
You 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: Printing to *out* in another thread

2009-10-18 Thread Alex Osborne

mbrodersen wrote:
>> Using atoms is not a good idea. Unless you don't mind if the same
>> message is sometimes printed more than once. Atoms are implemented
>> using spin locks with automatic retry.
> 
> Hmmm...unless add-watch => observer is called only once.

Looking in clojure/lang/Atom.java:

public Object swap(IFn f) throws Exception{
for(; ;)
{
Object v = deref();
Object newv = f.invoke(v);
validate(newv);
if(state.compareAndSet(v, newv))
{
notifyWatches(v, newv);
return newv;
}
}
}

So I guess that'd be a yes, it's only called once.

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread Adrian Cuthbertson

Just an addendum to my last post - without the .start you can test it better;

(defmacro with-thread [nm & body]
 `(let [thread# (Thread. (fn [] (do ~...@body)))]
(if ~nm (.setName thread# ~nm))
;(.start thread#)
thread#))

(def th (with-thread "foo" (println "HasdfasdfasdfasdfasdfasdfasdfasdfI")))

(.start th)
nil
HasdfasdfasdfasdfasdfasdfasdfasdfI

(.getName th)
"foo"

- Adrian.

On Mon, Oct 19, 2009 at 7:18 AM, Adrian Cuthbertson
 wrote:
> The following seems to do it;
>
> (defmacro with-thread [nm & body]
>  `(let [thread# (Thread. (fn [] (do ~...@body)))]
>    (if ~nm (.setName thread# ~nm))
>    (.start thread#)
>    thread#))
>
> (with-thread "foo" (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
> #
> user=> HasdfasdfasdfasdfasdfasdfasdfasdfI
>
> Also, macroexpand-1 really helps when writing macros. You can see
> exactly how it's being expanded and it's then somewhat easier to
> debug;
>
> (macroexpand-1 '(with-thread nil (println 
> "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
> (clojure.core/let [thread__112__auto__ (java.lang.Thread.
> (clojure.core/fn [] (do (println
> "HasdfasdfasdfasdfasdfasdfasdfasdfI"] (if nil (.setName
> thread__112__auto__ nil)) (.start thread__112__auto__)
> thread__112__auto__)
>
> Regards, Adrian.
>
> On Mon, Oct 19, 2009 at 6:39 AM, Gorsal  wrote:
>>
>> So now that the future is working, I'm attempting to print from an
>> actual java thread. Like this
>>
>> (defmacro with-thread [nm & body]
>>  `(let [thread# (Thread. #(fn [] (do ~...@body)))]
>>     ~@(if nm `((.setName thread# ~nm)))
>>     (.start thread#)
>>     thread#))
>>
>> (with-thread nil (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
>>
>> Except no output! Eeek!!! What am i doing wrong?
>> >>
>>
>

--~--~-~--~~~---~--~~
You 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: deftest metadata

2009-10-18 Thread Phil Hagelberg

Phil Hagelberg  writes:

> Would it be a good idea to change deftest so that it accepts an optional
> metadata map just like defn? I can implement it if it's wanted.

Here's the ticket and patch:

https://www.assembla.com/spaces/clojure/tickets/201-Make-deftest-keep-var-metadata

I ran into a very confusing problem while I was testing my change. The
custom-report function defined at the bottom of the test makes it so
that any tests that are defined that do not have "Should pass" as their
message will fail. I flailed around for quite some time, starting to
wonder if I was losing it when my simple (is true) tests did not pass.

I understand the need to be able to make sure that certain tests cause
errors or failures, but perhaps making the msg argument required only in
those cases (rather than for every single test) would cause less
confusion.

thanks,
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: Using 'future' ?

2009-10-18 Thread Gorsal

Thanks. I think now that i recall i have made that mistake before. I
must differentiate - fn and #()!

--~--~-~--~~~---~--~~
You 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 'future' ?

2009-10-18 Thread John Harrop
On Mon, Oct 19, 2009 at 12:39 AM, Gorsal  wrote:
>
> So now that the future is working, I'm attempting to print from an
> actual java thread. Like this
>
> (defmacro with-thread [nm & body]
>  `(let [thread# (Thread. #(fn [] (do ~...@body)))]
> ~@(if nm `((.setName thread# ~nm)))
> (.start thread#)
> thread#))
>
> (with-thread nil (println "HasdfasdfasdfasdfasdfasdfasdfasdfI"))
>
> Except no output! Eeek!!! What am i doing wrong?


Get rid of the extra #:

(defmacro with-thread [nm & body]
 `(let [thread# (Thread. (fn [] (do ~...@body)))]
~@(if nm `((.setName thread# ~nm)))
(.start thread#)
thread#))

#(fn [] foo) is equivalent to (fn [] (fn [] foo)), i.e. is a zero-argument
function that returns a zero argument function. So your thread's Runnable
had no side effects and the return value (which, if invoked, WOULD have had
side effects) was discarded and never invoked.

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