Qiu Xiafei writes:
> (defn num->digits
> [num]
> (loop [n num res []]
> (if (zero? n)
> res
> (recur (long (/ n 10)) (cons (mod n 10) res)
How about (quot n 10) instead of (long (/ n 10))? No sense in the
extra step.
David
--
You received this message because you ar
On Fri, Jan 04, 2013 at 08:58:40AM +0100, Tassilo Horn wrote:
At least in my experience, it usually matters a lot which form actually
evaluated to nil. But it's easy to write a macro `if-let-all' or so,
which would expand into
(let [x 1 y nil z 3]
(if (and x y z)
(+ x y z)
0))
i
On Thu, Jan 03, 2013 at 11:14:30PM -0800, Evan Mezeske wrote:
Wouldn't it be more accurately named "if-and-let" if it supported that? E.g.
(if (and x y z) ...).
I can see regular if-let being useful with more than one form, just
using the last value for the conditional.
(if-let [a expr, b
On Thu, Jan 21, 2010 at 10:23:10PM -0800, Richard Newman wrote:
I'm somewhat swayed by Leiningen because it makes doing some things
easy (uberjar! starting a REPL! neat!), at the cost of making other
things (such as managing dependencies myself) more frustrating.
However, if it wasn't for all
On Sat, Jan 16, 2010 at 03:30:49PM -0800, Sergey wrote:
But how?:)
Use a '$' character to delimit the internal class.
... (:import com.google.template.soy.SoyFileSet$Builder) ...
... (new SoyFileSet$Builder) ...
That's the real class name. It's fairly easy to figure this out by
looking
On Fri, Jan 01, 2010 at 12:31:16PM -0500, Mike Meyer wrote:
>On Fri, 1 Jan 2010 13:45:43 -0300
>Angel Java Lopez wrote:
>
>> I would like to add Ada exception management. I don't know if there were
>> previous work on the field. Any info? I worked with Algol, but I don't
>> remember if something l
On Tue, Dec 29, 2009 at 01:58:45PM -0500, Rich Hickey wrote:
>(type (Small))
>:user/Small
>
>You can use this keyword type tag for multimethod dispatch.
I did eventually figure this out.
>I am a bit confused as to why you would want to reify a deftype. You
>can reify protocols, however.
I need
On Mon, Dec 28, 2009 at 02:50:59PM -0800, Mark Tomko wrote:
>This, however, does not work:
>
>(ns org.tomko.konkordans.analysis
> (:import
>(org.tomko.konkordans NestedStatics)))
>
>(def foo NestedStatics$LevelOne$LevelTwo/NO)
The class is called NestedStatics$LevelOne$LevelTwo, so you would
On Mon, Dec 28, 2009 at 02:32:48PM -0800, Mark Tomko wrote:
>user=> (str.org.tomko.konkordans.NestedStatics/LevelOne)
Does
str.org.tomko.konkordans.NestedStatics$LevelOne/ONE
Work?
You can always look in the class output directory that the Java
compiler generates, and see the resulting cla
On Mon, Dec 28, 2009 at 12:44:31PM +0100, Konrad Hinsen wrote:
>> This fact is realized even in haskell community:
>> http://lambda-the-ultimate.org/node/2749#comment-41078
>
>That article is about monad transformers, not monads themselves. BTW,
>monad transformers are simpler in Clojure than they
The following generates an NPE during compilation:
(deftype Small [])
(defn wrap []
(reify Small))
Obviously, my real use has more interfaces I implement, but this shows
the problem.
My problem is that I need to override 'print-method', which is using
defmulti off of 'type' of it's ar
On Sun, Dec 20, 2009 at 02:30:58PM -0500, Luc Préfontaine wrote:
>People bought HP calculators not for the Postfix notation but for all
>the others things it offered at the time...
Some of us _still_ only buy HP calculators because of the postfix
notation. Oh, the other things are nice, too.
Da
On Thu, Dec 10, 2009 at 09:13:33AM -0800, samppi wrote:
>notation before, and it is fine. For my tastes, however, I think that
>it repeats the symbol (in this case, 'x) too much. Sometimes it may be
>the best way, but usually I would instead use ->, ->>, and/or letfn.
The problem I have using ->
On Thu, Dec 10, 2009 at 09:26:07AM -0500, Graham Fawcett wrote:
>(let [x 1
> _ (f x)
> y (+ x 2)
> _ (g y)]
> ...)
What do people in general think of this style? I remember using this
trick a lot with O'Caml, and I've certainly used it a few times in
Clojure, but something feels
On Tue, Dec 08, 2009 at 03:22:47PM -0800, ataggart wrote:
>I would be very surprised if getting the first element from a sorted-
>set wasn't ~O(1).
As has been mentioned, it probably isn't if the set is a tree.
But, also, usually, in addition to getting the first element, we also
are going to wa
On Sat, Dec 05, 2009 at 01:38:36AM +0300, Ivan Sagalaev wrote:
>Cliff Wells wrote:
>> I am
>> unable to see why someone shouldn't be able to receive a signed PDF via
>> email and achieve a similar level of confidence that the signor was
>> legitimate.
>
>BTW Canonical does exactly that[1]. I've jus
On Fri, Dec 04, 2009 at 03:15:28PM +0200, Sergey Didenko wrote:
>However it looks interesting, "(dosync (alter myref inc))" takes much longer
If your var is independent, how about using an atom?
(swap! myatom inc)
seems to be about 5-10 times faster than a dosync/ref on my Linux machine.
Da
On Wed, Dec 02, 2009 at 08:18:33PM -0800, Dave M wrote:
>On Dec 2, 9:09 pm, David Brown wrote:
>...
>> If you're running JDK 6, you can run the virtualvm, or jconsole to get
>> a better handle on the memory usage, and even dig into what it might
>> used for.
>
On Wed, Dec 02, 2009 at 02:01:36PM -0800, Johann Hibschman wrote:
>There is a qualitative difference between the runs, though. I can run
>test-split-3 five times in a row, all with similar times, without
>having the java process size get bigger than 0.6 GB. When I run any of
>the others, the size
On Tue, Dec 01, 2009 at 08:16:41PM -0800, rzeze...@gmail.com wrote:
>Once you have the heap dump you can use the Eclipse Memory Analyzer
>Tool. It can take your heap dump and create various reports. One of
>them being a "dominator tree" which will show you what object has the
>largest retained h
On Sun, Nov 29, 2009 at 11:09:00PM -0800, David Brown wrote:
>All of the persistent classes in Clojure, including continuations
>claim to implement Serializable. Not sure how well it actually works,
>but if implemented, it should be possible to send a closure even to a
>diffe
On Sun, Nov 29, 2009 at 11:09:38PM -0500, Jim Powers wrote:
>Clearly what would be desired is portable continuations that can be loaded
>on any machine and/or duplicated/replicated for failure cases.
All of the persistent classes in Clojure, including continuations
claim to implement Serializable
This commit:
commit 5577a47a390782d7ab911c2e3c4c8be1b0341aa8
Author: Rich Hickey
Date: Sat Feb 7 14:46:56 2009 +
added sync to writeClassFile
Adds a 'sync()' call to the class file write. On systems where the
underlying fsync() call causes a flush all the way
On Fri, Nov 27, 2009 at 01:52:05PM +0200, Miron Brezuleanu wrote:
>not sure if it works here, but what about adapting advice from Stuart
>Halloway's Programming Clojure (pages 159-160, 'Losing your head') and
>use a function returning a sequence instead of a 'bound by let' name
>(the actual advice
On Thu, Nov 26, 2009 at 05:05:17PM -0800, David Brown wrote:
>On Thu, Nov 26, 2009 at 04:00:34PM -0800, David Brown wrote:
>
>>For now, I'll do without the with-open, since in this particular case,
>>errors are going to be fairly fatal anyway.
>
>BTW, I still haven
On Thu, Nov 26, 2009 at 04:00:34PM -0800, David Brown wrote:
>For now, I'll do without the with-open, since in this particular case,
>errors are going to be fairly fatal anyway.
BTW, I still haven't been able to figure out how to write this
function without hanging onto the colle
On Thu, Nov 26, 2009 at 02:50:09PM -0800, David Brown wrote:
>I'm writing some fairly complex code involving lazy sequences. I
>appear to be getting a space leak from what looks like something that
>is still holding a reference to the head of the sequence.
Ok, I found the leak
I'm writing some fairly complex code involving lazy sequences. I
appear to be getting a space leak from what looks like something that
is still holding a reference to the head of the sequence.
Does anyone have any advice on how to go about finding this? Are
there any JVM tools that might perchan
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
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
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 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 Tue, Nov 24, 2009 at 04:39:38PM -0500, Peter Wolf wrote:
>Here is a N00B question, but I can not find the answer by Googling, or
>reading Stuart's book. So, I assume that others will want to find this
>FAQ in the future.
I think it's also change a bit since the book.
>I am calling legacy cod
On Tue, Nov 24, 2009 at 01:04:57AM -0800, Meikel Brandmeyer wrote:
>Hi,
>
>On Nov 24, 9:44 am, bOR_ wrote:
>
>> Can we get an option 'leiningen' at "how do you get clojure"?
>
>I think this is basically Maven/Ivy, no?
Leiningen includes, within it's own Jar, a particular version of the
clojure sn
On Mon, Nov 23, 2009 at 09:55:46PM +, the.stuart.sie...@gmail.com wrote:
Since the form only lets me answer one answer for each, but reality is
much more complicated.
>How do you get Clojure? *
>
>Download release
>Github
>Maven or Ivy
I primarily use the latest development snapshot that I p
On Mon, Nov 23, 2009 at 03:00:16PM -0800, Raoul Duke wrote:
>i'd be interested to hear who has successfully used clojure in
>production. i know of some, as some folks have been vocal; any other
>interesting-but-so-far-silent uses people'd be willing to fess up
>about?
I've thrown together a small
On Sun, Nov 22, 2009 at 08:40:42PM +0100, Christophe Grand wrote:
>(defn foo [#^FileChannel chan, bufs]
>(.write chan #^"[Ljava.nio.ByteBuffer;" (to-array bufs)))
Excellent, it was the quotes I was missing. Nice to know I can hint
any type.
Thanks,
David
--
You received this message becau
On Sun, Nov 22, 2009 at 01:00:51PM -0500, John Harrop wrote:
>On Sun, Nov 22, 2009 at 12:55 PM, David Brown wrote:
>
>> java.nio.channels.FileChannel contains some .write methods:
>>
>> [27] write : int (ByteBuffer)
>> [28] write : int (ByteBuffer,long)
>> [29
java.nio.channels.FileChannel contains some .write methods:
[27] write : int (ByteBuffer)
[28] write : int (ByteBuffer,long)
[29] write : long (ByteBuffer[])
[30] write : long (ByteBuffer[],int,int)
I have an array of ByteBufers, but I can't figure out how to call #29
without it being a reflectin
On Sun, Nov 22, 2009 at 11:45:46AM -0500, John Harrop wrote:
>Nothing so serious as a hang, though, and at least I can do basic things in
>my IDE without reaching for the frelling manual every two minutes to look up
>some key-combination :)
I suspect both models are going to be important. I feel
On Sun, Nov 22, 2009 at 07:14:33AM -0800, bOR_ wrote:
>What is the normal way to let Leiningen know about local jars? I am
>using brics automaton in one of my projects, and that jar is only
>downloadable after confirming the bsd licence (http://www.brics.dk/
>automaton/), so I have it locally on m
On Sun, Nov 22, 2009 at 01:05:43AM -0800, bOR_ wrote:
>elif [ ${1: -4} = ".clj" ]; then
># Small hack to use lein to start clojure scripts
>java -cp "$CLASSPATH" clojure.main "$1"
How about
elif [ ${1: -4} = ".clj" ]; then
# Small hack to use lein to start clojure scripts
On Sat, Nov 21, 2009 at 11:14:52PM -0500, John Harrop wrote:
>1 second instead of 1/6 of a second. Yeah, like users will notice that
>difference in startup times. :)
I'm not actually complaining, but I do notice every single time I fire
up a REPL. The more code that you have, the longer it takes
On Sat, Nov 21, 2009 at 08:42:26PM -0500, John Harrop wrote:
>Are you talking about binding things like String.class to vars referenced by
>symbols like String?
Not just String.class, every single class referenced by a given
namespace will be loaded, and most of them instantiated before a
single
On Fri, Nov 20, 2009 at 03:54:45PM -0800, Mike Hinchey wrote:
>It's the . special form that makes the difference. In (. System
>(getProperty)), the dot interprets System as a class and looks for a static
>method (at read/compile time). With (identity System), System resolves to a
>value, a Class
On Fri, Nov 20, 2009 at 06:37:18PM +, Jim Downing wrote:
>I might have misunderstood, but isn't the problem the same as in Java;
>you can't know from a static analysis which classes are going to be
>loaded?
Except that Clojure will load all of them so it can bind them to the
vars in each name
On Thu, Nov 19, 2009 at 05:51:22AM -0500, John Harrop wrote:
>On Thu, Nov 19, 2009 at 4:31 AM, Lauri Pesonen wrote:
>
>> (clojure.walk/macroexpand-all '(cond (even? 2) :foo (odd? 2) :bar :else
>> :baz))
>> (if (even? 2) :foo (if (odd? 2) :bar (if :else :baz nil)))
>
>Eeeuw. Perhaps the cond macro
s work in Java/Clojure.
Nice to see that it doesn't make the calls until asked for.
>On Nov 18, 4:23 am, David Brown wrote:
>> On Tue, Nov 17, 2009 at 03:24:46PM -0800, Richard Newman wrote:
>> >Baby, bathwater. Making a persistent map out of a Java map is
>> >ex
On Tue, Nov 17, 2009 at 03:24:46PM -0800, Richard Newman wrote:
>Baby, bathwater. Making a persistent map out of a Java map is
>expensive. Not everything that implements Map is concrete; e.g.,
>spending several seconds making a local persistent Clojure map out of
>a distributed hash table proxy, j
On Tue, Nov 17, 2009 at 10:12:19AM -0800, David Brown wrote:
>On Tue, Nov 17, 2009 at 08:03:59AM -0800, pkw wrote:
>
>>I'm having this same problem. Did you find a way around it?
>>I want to try changing the User-Agent, but I can't figure out
>>how to do that.
&
On Tue, Nov 17, 2009 at 08:03:59AM -0800, pkw wrote:
>I'm having this same problem. Did you find a way around it?
>I want to try changing the User-Agent, but I can't figure out
>how to do that.
I suspect that the Sax parser by default is configured to not allow
fetching of the DTD over the net.
On Sun, Nov 15, 2009 at 04:20:19PM -0500, John Harrop wrote:
>That's weird. It's not documented anywhere on the site. And it seems to hang
>the REPL:
>
>user=> nil #!foo
>
>and nothing. Enter doesn't print "nil" and a fresh user=> prompt as it
>should and nothing else apparently works either. The
On Sun, Nov 15, 2009 at 09:43:38PM +0100, B Smith-Mannschott wrote:
>On Sun, Oct 11, 2009 at 22:12, Matt Wilson wrote:
>> The only hassle with a map is that iterating over it (in my case, with
>> a `for`) turns it into a list of [key value], which makes it a pain to
>> turn back into a map once y
>> On Jan 21, 4:39 pm, Frank wrote:
>>
>> > I am interested in trying to use Clojure to develop web-based
>> > applications. Can someone point me to any Clojure libraries that have
>> > been written that I can use. Thanks.
I spent a couple of days this week using Compojure both in anger, and
fo
On Thu, Nov 12, 2009 at 07:50:31AM -0800, Sean Devlin wrote:
>(defn daemon
> "Creates a new daemon thread and sets runnable to f"
> [f]
> (let [t (Thread. f)]
>(do
> (.setDaemon t true)
> (.start t)
> t)))
>
>And I tried calling
>
>user=>(daemon #(println "foo"))
>
>I get the
Speaking of vimclojure, has anyone else encountered situations where
the vimclojure indent decides that the indentation of top-level
constructs should be two spaces over? I haven't been able to figure
out a pattern, and sometimes I can even fix it by just scrolling up
and back.
David
--
You rec
On Thu, Nov 12, 2009 at 10:21:32AM +1100, John Ky wrote:
>Does anyone know why if the first character in my *.clj file is '#', then
>when I open it in VIM, ClojureVIM fails to recognise it as a Clojure file?
Vim runs the type detectors that examine the file before the ones
based on filename. The
On Tue, Nov 10, 2009 at 09:08:31PM -0500, John Harrop wrote:
>In case anyone was wondering, apparently it wants
>
>(ns foo.bar.baz
> (:use [clojure.contrib.core :only (seqable?)]))
>
>(and thus violates the usual clojure rule of using vectors rather than lists
>for groupings that are not invocati
On Tue, Nov 10, 2009 at 07:41:41AM -0800, pmf wrote:
>> This thing could easily create a lazy sequence, in fact, the code
>> would look a lot like the code for seque, with just a separation of
>> the writer from the reader. I'll have to think about it to make sure
>> that it can be used safely.
>
On Mon, Nov 09, 2009 at 10:07:41PM -0800, David Brown wrote:
>On Mon, Nov 09, 2009 at 09:42:28PM -0800, Mark Engelberg wrote:
>>But let's say the agent is responsible some enormous database, and
>>it's impractical for the in-memory state to hold all the information
On Mon, Nov 09, 2009 at 09:42:28PM -0800, Mark Engelberg wrote:
>But let's say the agent is responsible some enormous database, and
>it's impractical for the in-memory state to hold all the information
>that readers might find useful. In this case, I think you're right
>that the basic agent func
On Mon, Nov 09, 2009 at 05:19:41PM -0800, Don wrote:
>
>I am having a problem with vectors. It seems there should be a
>function for this however I am not sure.
>
>I have a vector a [ [2 3] [4 5] [6 7] ]
>
>And I want to be able to get [2 3 4 5 6 7]
There's a flatten in clojure.contrib.seq-utils
On Mon, Nov 09, 2009 at 08:28:43PM -0800, David Brown wrote:
>In both cases, the reads run completely synchronously, waiting for
>their answer, and really the whole thing isn't really any better than
>just using locks.
I guess a deeper concern is that there seems to only be a sing
I'm trying to get a better grasp of how Agents are intended to be
used, so let me give an example scenario.
Let's say I have some thing that keeps track of the state of some I/O
entity, let's say some kind of file-based storage. There is state
associated with the entity. It's important that onl
On Mon, Nov 09, 2009 at 05:54:36PM -0800, David Brown wrote:
>Depending on use behavior, you can also make a decent lazy queue just
>out a two lists, where you reverse and append whenever the source side
>fills up.
Ok, this is what PersistentQueue is, except without the reverse and
a
On Mon, Nov 09, 2009 at 05:53:28PM -0800, Mark Engelberg wrote:
>
>On Mon, Nov 9, 2009 at 5:41 PM, John Harrop wrote:
>> In the meantime, the main thing still missing from Clojure is a convenient
>> queue.
>
>What's wrong with clojure.lang.PersistentQueue?
The only clojure constructor I could fi
On Mon, Nov 09, 2009 at 08:41:25PM -0500, John Harrop wrote:
>In the meantime, the main thing still missing from Clojure is a convenient
>queue. Lists and vectors both add and remove efficiently only at one end,
>and at the same end for add and remove in both cases. Doubly-linked lists
>can't be
On Mon, Nov 09, 2009 at 11:42:32PM +0100, Michael Jaaka wrote:
>How to convert HashMap to Clojure map, sorted-map,
>tree-map
(into {} hm)
or
(into (sorted-map) hm)
where hm is the hash map.
You can also just use the hash map like you would a Clojure map, but
it might change on you, since
On Mon, Nov 09, 2009 at 09:07:31AM -0800, pmf wrote:
>
>On Nov 9, 5:39 pm, David Brown wrote:
>>
>> (let-map [x [31 41 59 26]
>> y (iterate inc 1)]
>> (+ x y))
>>
>> Probably not that interesting in the simple case.
>
>How is t
On Mon, Nov 09, 2009 at 04:49:16PM +, Emeka wrote:
>What is the gain of using lazy-seq here? Why can't we go without laziness?
- The lazy version doesn't consume stack per length of the sequence.
- The lazy version works with unbounded sequences.
For short sequences it probably doesn'
Given the recent talk about iter and how most of the expressions can
be done easily with sequences and map. I however, have found that map
often makes these difficult to read because the names are up front in
the function and the arguments follow this.
So, I threw together the following macro th
On Sat, Nov 07, 2009 at 11:48:32AM -0500, Chouser wrote:
>This should work:
>
>(defn update1 [#^MessageDigest md, #^bytes item]
> (.update md item))
This does seem to work, thanks.
Any reason that 'doubles' is also defined as an array cast function,
but 'bytes' is not?
David
--~--~--
I can't figure out how to avoid reflection, in the 'update' method of
MessageDigest. It is overloaded on a single argument with either
'byte', 'byte[]', or 'java.nio.ByteBuffer'.
(import '(java.security MessageDigest))
(set! *warn-on-reflection* true)
The compiler didn't seem to like a ta
73 matches
Mail list logo