On Thu, Nov 26, 2009 at 8:05 AM, Robert Campbell wrote:
> If you have this:
>
> user> (def f (future (Thread/sleep 2) :done))
> #'user/f
> user> @f ; this immediate deref blocks for 20 sec, finally returning
> :block
> :done
> user> @f ; returns immediately
> :done
>
> What is actually happ
If you have this:
user> (def f (future (Thread/sleep 2) :done))
#'user/f
user> @f ; this immediate deref blocks for 20 sec, finally returning :block
:done
user> @f ; returns immediately
:done
What is actually happening when you call the first @f? You are waiting
for the function to finish e
Forgot to mention: running Clojure 1.0.0- and Clojure-Contrib
1.0-SNAPSHOT according to the pom..
On Thu, Nov 26, 2009 at 7:38 AM, Robert Campbell wrote:
> I'm trying to write a file scanner very similar to the one on page 131
> of Stuart's book:
>
> (ns user
> (:use [clojure.contrib.duck-strea
I'm trying to write a file scanner very similar to the one on page 131
of Stuart's book:
(ns user
(:use [clojure.contrib.duck-streams :only [reader]]))
(defn scan [dir]
(for [file (file-seq dir)]
(with-open [rdr (reader file)]
(count (filter #(re-find #"foobar" %) (line-seq rdr)
On Wed, Nov 25, 2009 at 11:01:32PM +0100, Meikel Brandmeyer wrote:
>(defmacro lazy-seq
> "..."
> [& body]
> `(LazySeq. ~(with-meta `fn* {:once true}) [] ~...@body))
It's also probably good to explain why fn* is quoted with backquote
rather than a regular quote. This took me a while to figure
Thanks. Yeah, after adding a call to shutdown-agents, the process no
longer hangs.
On Nov 25, 1:15 pm, Kevin Downey wrote:
> future also uses the same threadpool as agents, so once you call
> future the threadpool spins up, and just sort of sits around for a
> while before the jvm decides to exit
Hi,
Am 25.11.2009 um 22:43 schrieb David Brown:
(defmacro lazy-seq
"..."
[& body]
(list 'new 'clojure.lang.LazySeq (list* '#^{:once true} fn* []
body)))
That's it. The neat thing is that you or I can also write macros that
do this kind of thing. It's one of the things that m
On Wed, Nov 25, 2009 at 12:40 PM, Gabi wrote:
> Very interesting indeed. I am not sure I understand completely, but by
> intuition I presume that the recursive call actually creates a new
> heap allocated LazySeq (with the function definition inside) .
Not quite; it creates a Java object one me
Hi,
Am 23.11.2009 um 21:46 schrieb Garth Sheldon-Coulson:
bound-fn is very nice, but I've found that capturing *all* dynamic
vars is often overkill.
As I said in said thread: I don't think, that this is a big problem.
The number Vars having actually a non-root binding should be rather
sm
Ok. Now I get it. Cool stuff
On Nov 25, 4:18 pm, Meikel Brandmeyer wrote:
> Hi,
>
> On Nov 25, 9:10 am, Gabi wrote:
>
> > For example why doesn't the following "repeatedly" never crash?
>
> > (defn repeatedly
> > [f] (lazy-seq (cons (f) (repeatedly f
>
> Because the nested call is deferred
On Wed, Nov 25, 2009 at 09:40:44AM -0800, Gabi wrote:
>Very interesting indeed. I am not sure I understand completely, but by
>intuition I presume that the recursive call actually creates a new
>heap allocated LazySeq (with the function definition inside) . So is
>there some help from the compiler
future also uses the same threadpool as agents, so once you call
future the threadpool spins up, and just sort of sits around for a
while before the jvm decides to exit, which is why the program would
sit around for 50 seconds
On Wed, Nov 25, 2009 at 10:30 AM, Hong Jiang wrote:
> Thanks for your
Thanks for your replies David and Sean. Yes, I made a mistake thinking
that future takes a function and its arguments, so the function was
never called in my program.
On Nov 25, 8:21 am, David Brown wrote:
> On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote:
> >Hi all,
>
> >I'm new to Cl
Very interesting indeed. I am not sure I understand completely, but by
intuition I presume that the recursive call actually creates a new
heap allocated LazySeq (with the function definition inside) . So is
there some help from the compiler for this? How does the recursive
call suddenly transfers i
Hi,
I am working on reading a pipe delimited file into a SQL database.
I can read the lines using
(doseq [line (read-lines "myfile.csv")]
and format the lines using
(map #(format "\"%s\"" %) (re-split #"\|" line))
This results in list for each line.
I have created a table that has one co
Hi,
On Nov 25, 6:04 am, Hong Jiang wrote:
> I'm new to Clojure and playing with small programs. Today I wrote a
> snippet to figure out how future works:
>
> (defn testf []
> (let [f (future #(do
> (Thread/sleep 5000)
> %)
> 5)
>
Hi,
On Nov 25, 9:10 am, Gabi wrote:
> For example why doesn't the following "repeatedly" never crash?
>
> (defn repeatedly
> [f] (lazy-seq (cons (f) (repeatedly f
Because the nested call is deferred until the sequence is realised.
Then the original function already returned. So it does no
On Nov 25, 2:09 pm, Martin DeMello wrote:
> On Thu, Nov 26, 2009 at 12:31 AM, Jonathan Smith
>
> wrote:
>
> > I think a better way to do this is to not use a regex at all.
> > Canonically I think this sort of thing is (would be?) implemented by
> > constructing a 'sequence' of strings, (first f
On Nov 25, 11:09 am, Martin DeMello wrote:
> On Thu, Nov 26, 2009 at 12:31 AM, Jonathan Smith
> > To display you would want to use 'into-array' and your 'setListData'
> > function, because you seem to have a homogeneous collection of
> > strings; while to-array makes you an array of objects, into-
On Thu, Nov 26, 2009 at 12:31 AM, Jonathan Smith
wrote:
>
> I think a better way to do this is to not use a regex at all.
> Canonically I think this sort of thing is (would be?) implemented by
> constructing a 'sequence' of strings, (first filtered based on
> potential word length) and recursively
--
> is still slow, but dropping down to
>
> (def wlistdata (to-array (take 26 (words-with "..."
>
> (def update-wlist #(let [w (take 26 (words-with (current-word)))]
>(. words setListData wlistdata)))
>
> leaves everything running smoothly. Is there a more e
ooh, i wondered how words-with was so fast - my first thought was that
it was bound to be the bottleneck, but when i removed the to-array and
things sped up i figured maybe the jvm was more efficient than i
thought :) laziness takes a bit of getting used to!
m.
On Thu, Nov 26, 2009 at 12:26 AM, a
Bear in mind that when going from the "slow" to the "fast", you not
only removed the repeated calls to to-array, but also removed the
overhead of words-with, since the lazy seq returned from the let
doesn't get fully realized.
Try changing your "fast" version to:
(def update-wlist #(let [w (doall
Read Christophe's post about multi-dim arrays. Reflection is getting in the
way here.
On Wed, Nov 25, 2009 at 2:55 AM, Amnon wrote:
> Hi Konrad,
> In the original post, I put in the code, it was removed by the post
> editor.
> The way I wanted it implement, I have the main in java (gui and
> stu
Yup, that's right - I filed ticket 130 to reflect this. If I get there
first, I'll mark the ticket as well and we can compare notes.
I'm super-excited about Leiningen, btw. I've been thinking about how
to turn my autodoc stuff into a Leiningen plugin so that we can get
easy doc for any project.
O
I'm writing a crossword editor that provides a list of suggestions to
fill in the current word. This is displayed in a listbox to the right
of the grid, and every time the cursor is moved, I update it via
(def update-wlist #(let [w (take 26 (words-with (current-word)))]
(. wor
On Wed, Nov 25, 2009 at 12:10:36AM -0800, Gabi wrote:
>How come that infinite recursions under lazy-seq won't crash the
>program, whilst regular infinite recursion would crash the program ?
>What's the trick ?
>
>For example why doesn't the following "repeatedly" never crash?
>
>(defn repeatedly
>
On Nov 23, 4:55 pm, the.stuart.sie...@gmail.com wrote:
> Clojure User Survey
First wave of results (258 responses)
How do you get Clojure?
19% Download release
69% Github
8% Maven or Ivy
4% IDE / Package manager
What distribution of Clojure do you use primarily?
32% 1.0 release
12% I picked on
On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote:
>Hi all,
>
>I'm new to Clojure and playing with small programs. Today I wrote a
>snippet to figure out how future works:
>
>(defn testf []
> (let [f (future #(do
> (Thread/sleep 5000)
> %)
>
On 25.11.2009, at 15:32, jim wrote:
> That's exactly what it is. I used the continuation monad from
> clojure.contrib.monads. After I get the code out, I'll be writing a
> tutorial on how it works which will also explain the continuation
> monad. I found that monad to be the most difficult to get
Graham,
That's exactly what it is. I used the continuation monad from
clojure.contrib.monads. After I get the code out, I'll be writing a
tutorial on how it works which will also explain the continuation
monad. I found that monad to be the most difficult to get my head
around, but it's hugely powe
I'm not quite sure what you're seeing. You might want to use the time
macro to help.
Here's what I was able to do:
user=> (time ((fn [] (let [f (future (#(do (Thread/sleep 5000) %) 5))
g 7] (+ g @f)
"Elapsed time: 4975.917889 msecs"
12
Sean
On Nov 25, 12:04 am, Hong Jiang wrote:
> Hi all,
I am going through Programming Clojure and I recently downloaded the
code from the books official website. For other utils I can do, for
example, (require 'clojure.contrib.str-utils) and it works. But how do
I load code from the book? (require 'examples.introduction) throws the
following exception:
Hi Jim,
On Tue, Nov 24, 2009 at 11:21 PM, jim wrote:
> Evening all,
>
> I've been working on a library for writing web applications for
> compojure. I've got it written and (I think) working. First thing
> tomorrow is to write a sample app and post it along with the library.
>
> But in the meanti
user=> (import '(java.util.logging Logger Level))
nil
user=> (def my-logger (Logger/getLogger "mylogger"))
#'user/my-logger
user=> (. my-logger setLevel Level/WARNING)
nil
user=> (. my-logger warning "this is a warning")
Nov 25, 2009 5:38:25 AM sun.reflect.NativeMethodAccessorImpl invoke0
WARNING:
Here are my results.
The transient version performs slightly better on windows 32bit client
JVM, and considerably better on linux 64bit server JVM (they are both
1.06.0_17)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send e
Hi,
On Nov 25, 9:01 am, cej38 wrote:
> Is there a better way of doing this? For example, something like:
>
> (apply-struct-coll mystruct mycoll)
Close: (apply struct mystruct mycol)
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" grou
Just out of curiosity,
How come that infinite recursions under lazy-seq won't crash the
program, whilst regular infinite recursion would crash the program ?
What's the trick ?
For example why doesn't the following "repeatedly" never crash?
(defn repeatedly
[f] (lazy-seq (cons (f) (repeatedly f)
Hi Konrad,
In the original post, I put in the code, it was removed by the post
editor.
The way I wanted it implement, I have the main in java (gui and
stuff). I create a 3D array in java, it's an int array (i.e. int arr[]
[][] ) and call with that array to clojure.
It can be done in java at least
Hi all,
I'm new to Clojure and playing with small programs. Today I wrote a
snippet to figure out how future works:
(defn testf []
(let [f (future #(do
(Thread/sleep 5000)
%)
5)
g 7]
(+ g @f)))
(println (testf))
I'm expec
Thanks Mike. No big hurry on my part - I'll look at the tutorial code.
On Nov 24, 4:39 pm, Mike Hinchey wrote:
> You're right, the tests have not been converted to 3.2, so they are not
> running at this time. The best thing to look at is the tutorial.clj - most
> of these work properly, but exa
Wow! Many thanks for all the replies :-D
If there are any speech recognition enthusiasts out there, this code
is part of a Clojure example for Sphinx4.
http://cmusphinx.svn.sourceforge.net/viewvc/cmusphinx/trunk/sphinx4/src/scripts/clojure/ClojureTranscriber.clj?view=markup
Suggestions/improvem
Hi,
On Wed, Nov 25, 2009 at 9:01 AM, cej38 wrote:
> Hi,
> I am sorry if this has already discussed, but I didn't see it when I
> did a search.
> I keep running into instances where I would like to define a struct,
> using defstruct, and then have that be applied to the elements of a
> coll.
Hi,
we replaced a command line interface for an internal, mission-critical
application with a custom Clojure-REPL. It is used for administrative
tasks as well as testing.
Cheers,
Stefan
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to thi
Hi,
I am sorry if this has already discussed, but I didn't see it when I
did a search.
I keep running into instances where I would like to define a struct,
using defstruct, and then have that be applied to the elements of a
coll. A simple example might explain it better.
(defstruct mystruct
45 matches
Mail list logo