Carlos,
I think this is pretty much what you had in mind:
(defn count-zeros [l]
(cond (empty? l) 0
(zero? (first l)) (inc (count-zeros (rest l)))
:else (count-zeros (rest l
(count-zeros '(9 8 6 0 1 2 0 5)) = 2
(count-zeros '(9 8 6)) = 0
(count-zeros '()) = 0
Of course the
2010/8/10 David Sletten da...@bosatsu.net
On Aug 10, 2010, at 2:22 AM, Laurent PETIT wrote:
You could accomplish pretty much the same thing by defining two versions
with different arities:
(defn count-zeros
([l] (count-zeros l 0))
([l result]
(cond (empty? l) result
I'm the author of clj-native.
Currently it only works with Clojure 1.2. In retrospect I should have
made a separate branch when dropping 1.1 support.
If you need 1.1 support, just tell me and I could make a branch for it
since the changes required should be small.
/Markus
On Aug 9, 5:31 pm,
Hi,
On Aug 10, 8:22 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Though here, the version with different arities exposes as API for the
user the 2-arity version, but it may not make sense for the user of your
function to know about this 2-arity version. I personally prefer the first
2010/8/10 Meikel Brandmeyer m...@kotka.de
Hi,
On Aug 10, 8:22 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Though here, the version with different arities exposes as API for the
user the 2-arity version, but it may not make sense for the user of your
function to know about this
Hi,
On Aug 10, 9:36 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Interesting ! Though it seems like a repetition in this case ...
Indeed. However, eg. with multimethods this a nice-to-know to supply
some meaningful argument info.
Sincerely
Meikel
--
You received this message because you
What I'm looking for is a natural, conceptually clean approach.
Erlang programmers do version 2 all the time and it can be call
Erlang-style. You should be confident with version 2.
Version 2 is cleaner if you write the inner loop as a separate
function.
--
You received this message because
2010/8/10 Meikel Brandmeyer m...@kotka.de
Hi,
On Aug 10, 9:36 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Interesting ! Though it seems like a repetition in this case ...
Indeed. However, eg. with multimethods this a nice-to-know to supply
some meaningful argument info.
Indeed !
2010/8/10 Laurent PETIT laurent.pe...@gmail.com
2010/8/10 Meikel Brandmeyer m...@kotka.de
Hi,
On Aug 10, 9:36 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Interesting ! Though it seems like a repetition in this case ...
Indeed. However, eg. with multimethods this a nice-to-know to
The main usage (at least for me) is avoiding reflection in the context
of direct call to a Java method.
if you write:
(defn foo [x]
(.clone x))
Thank you for the insightful explanation.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post
On Tue, Aug 10, 2010 at 2:40 AM, Mark Engelberg
mark.engelb...@gmail.com wrote:
arbitrary-sized lists is a primary goal. The posted code (minus the
call to recur), is an elegant recursive formulation that is idiomatic
in Scheme because Scheme is (typically) implemented in a way that
makes
On Tue, Aug 10, 2010 at 12:43 AM, Jules julesjac...@gmail.com wrote:
It is impossible (undecidable) to tell precisely which functions a
function will call. Therefore you will need to consider not exactly
set of functions that a function will call, but some superset of that.
Why not take as
On 9 August 2010 22:16, Alan a...@malloys.org wrote:
Weird. I wonder if I was using an outdated version of Clojure or (more
likely) assumed from (doc drop-while) that it wouldn't handle false
the way I wanted. When doc says not nil should I assume it means
neither nil nor false, or should the
On Tue, Aug 10, 2010 at 1:15 AM, Nicolas Oury nicolas.o...@gmail.com wrote:
So, in this particular case, Scheme does not warranty no exhaustion
of resources.
Yes, but your recursion depth is limited to the length of the list you
are processing. So if you have enough resources to comfortably
Hello Mark,
2010/8/10 Mark Engelberg mark.engelb...@gmail.com
On Tue, Aug 10, 2010 at 1:15 AM, Nicolas Oury nicolas.o...@gmail.com
wrote:
So, in this particular case, Scheme does not warranty no exhaustion
of resources.
Yes, but your recursion depth is limited to the length of the list
On Tue, Aug 10, 2010 at 9:55 AM, Mark Engelberg
mark.engelb...@gmail.com wrote:
In Clojure, I find stack limitations are a real issue unless
I transform the algorithms into a tail-recursive accumulator style.
For lists, it's usually not hard. For trees, it can be a bit of a
pain.
Try
On Tue, Aug 10, 2010 at 10:08 AM, Laurent PETIT laurent.pe...@gmail.com wrote:
Naive question from someone who has not really used Scheme in practice :
beyond the memory footprint problem (which may or may not be a problem
depending on the memory size of an element in the initial list, and also
2010/8/10 Nicolas Oury nicolas.o...@gmail.com
On Tue, Aug 10, 2010 at 10:08 AM, Laurent PETIT laurent.pe...@gmail.com
wrote:
Naive question from someone who has not really used Scheme in practice :
beyond the memory footprint problem (which may or may not be a problem
depending on the
2010/8/10 Laurent PETIT laurent.pe...@gmail.com
2010/8/10 Nicolas Oury nicolas.o...@gmail.com
On Tue, Aug 10, 2010 at 10:08 AM, Laurent PETIT laurent.pe...@gmail.com
wrote:
Naive question from someone who has not really used Scheme in practice :
beyond the memory footprint problem
On Tue, Aug 10, 2010 at 2:21 AM, Nicolas Oury nicolas.o...@gmail.com wrote:
It would probably be up to twice as slow, I would say.
For a list that is continuous in memory and continuations that are
allocated perfectly in memory,
you would need to go through twice the same amount of memory.
(I
Hi,
On Aug 10, 11:34 am, Mark Engelberg mark.engelb...@gmail.com wrote:
The table shows that the performance of the accumulator-style version
of factorial is always worse than that of the original factorial
function.
I'm a little bit surprised, that people still prefer programs, which
are
The table show 20!.
I am far from being sure of my point, but in a first approximation:
Loading a part of memory that is not cached (which will be the case
for big lists) is around 300 cycles.
An addition in a register is a few cycles, a jump is a few cycles too,
at most, (the prediction will be
Dipping my toes for the first time in Clojure. Having some beginner
troubles.
THIS code works (on the repl, if that matters... also, Clojure 1.2):
(defn show [words]
(let [word (first words)]
(do
(println word)
(if (nil?
Thanks Chouser for your reply .. I was wondering if it is possible to acess
c++ code via clj-native .. I only seem to find c-native calls .. do you have
a comment on this..
Sunil.
On Mon, Aug 9, 2010 at 9:01 PM, Chouser chou...@gmail.com wrote:
On Mon, Aug 9, 2010 at 10:55 AM, Sunil Nandihalli
The following succeeds:
(try
(prn 1)
(finally
(prn 2)
(doto (System/out) (.print -) (.println -
prints:
1
2
--
The following fails (note the odd duplication of 2 in the output):
(try
(prn 1)
(finally
(prn 2)
(.. (System/out) (print -) (println -
prints:
1
2
-2
On occasion the REPL in Eclipse will stop taking input, or will fail
to recognize a function I have just defined. Is there a simple way to
get the REPL to restart, or break out of its current state?
One other question as well, to get the REPL running when I first bring
up Eclipse I have a file
Thanks Mac for your clarification .. I am using clojure 1.2 .. so should be
fine. And I was wondering if I can acess c++ stuff via clj-native .. What
are your suggestions?
Sunil
On Tue, Aug 10, 2010 at 12:45 PM, mac markus.gustavs...@gmail.com wrote:
I'm the author of clj-native.
Currently it
Hi,
if you recur with rest, you should use (empty?), if you recur with next,
you can use (nil?)
next is more eager than rest, but in a loop scenario, I generally use next
since we'll test for nil in order to know whether to continue to iterate or
not.
2010/8/10 chepprey jmess...@cranksters.org
2010/8/10 garf gary.overg...@gmail.com
On occasion the REPL in Eclipse will stop taking input, or will fail
to recognize a function I have just defined. Is there a simple way to
get the REPL to restart, or break out of its current state?
Hi, I don't know why your REPL is not responding
Hi,
On Aug 10, 8:36 am, Brian Stiles brian.sti...@gmail.com wrote:
The following succeeds:
(try
(prn 1)
(finally
(prn 2)
(doto (System/out) (.print -) (.println -
prints:
1
2
--
The following fails (note the odd duplication of 2 in the output):
(try
(prn 1)
The bug has nothing to do with try-finally.
Take a look at the macro expansion:
user= (macroexpand '(.. (System/out) (print -) (println -)))
(. (. (System/out) (print -)) (println -))
You are trying to call 'println on what ever 'print returns. But
'print is a void method.
On Tue, Aug 10, 2010
Hi Brian,
System/out
#PrintStream java.io.printstr...@7d59ea8e
(System/out)
#PrintStream java.io.printstr...@7d59ea8e
both return the out PrintStream object, so
(.. System/out (print -))
-nil
(.. (System/out) (print -))
-nil
(.. System/out (print -))
-nil
all invoke the print method on the java
Hi,
On Aug 10, 3:13 pm, Laurent PETIT laurent.pe...@gmail.com wrote:
next is more eager than rest, but in a loop scenario, I generally use next
since we'll test for nil in order to know whether to continue to iterate or
not.
I generally use next when I know that I need to realise anyway
On Aug 9, 2010, at 11:52 PM, chepprey wrote:
(defn show [words]
(let [word (first words)]
(do
(println word)
(if (nil? word)
(println DONE)
(recur (rest words))
Weird indeed:
user= (def a (atom 1))
#'user/a
user= (try (prn :test) (finally (swap! a inc) (.foo nil)))
:test
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user= @a
3
I would have expected 2 as a result, in any case ?
2010/8/10 Meikel Brandmeyer m...@kotka.de
Hi,
On Aug 10, 8:36 am,
2010/8/10 Rasmus Svensson r...@lysator.liu.se
I assume the problem is that there are no .class files in the jar. I
tried to rebuild the compojure jar using lein jar but still didn't
get .class files, even though:
Clojure looks for both .class files and .clj files, so you don't need
to
I assume the problem is that there are no .class files in the jar. I
tried to rebuild the compojure jar using lein jar but still didn't
get .class files, even though:
Clojure looks for both .class files and .clj files, so you don't need
to compile anything manually.
I'm seeing the following
Hi,
On Aug 10, 3:48 pm, David Sletten da...@bosatsu.net wrote:
Notice how Clojure returns two different values here. Other Lisps (such as
Common Lisp) define FIRST/REST of the empty list to both be NIL (i.e., the
empty list itself). So it is common in other Lisps to test for the end of a
hi!
I am doing a real-file demo with ring, compojure, hiccup, and database
access as well.
There is some chinese chararters in the tables. I want to display them
by hiccup, but browser display those chinese character as ???. But the
prn to console is ok. I am confused since I was a newbie in
Why? My nickname in #clojure is limux1972.
--
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
You need to register with NickServ, e.g.
/msg NickServ identify yourpassword
It's a protection so that nobody else uses limux1972 when you're not online.
(you also need to register limux1972, but I don't remember how)
2010/8/10 limux liumengji...@gmail.com
Why? My nickname in #clojure is
thanks for the answer. I suspect that the REPL dieing is justified,
as I tend to use the file as workspace with somethings uncompleted,
and with my newness to Clojure in general, I am often doing things in
ways that are not correct
On Aug 10, 8:21 am, Laurent PETIT laurent.pe...@gmail.com wrote:
Maybe this point about Racket is too off-topic for the list, but:
On Aug 10, 2010, at 4:55 AM, Mark Engelberg wrote:
Generally speaking, I find I do not have to worry about blowing the
stack in Scheme, and as a result, non-tail-call structural recursion
(such as the algorithm that kicked off
On Tue, Aug 10, 2010 at 11:23 AM, Will M. Farr wmf...@gmail.com wrot
Sorry for the digression; I hope people find it interesting.
I found it interesting.
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
2010/8/10 garf gary.overg...@gmail.com
thanks for the answer. I suspect that the REPL dieing is justified,
as I tend to use the file as workspace with somethings uncompleted,
and with my newness to Clojure in general, I am often doing things in
ways that are not correct
This may explain
Try using [:meta {:http-equiv Content-Type :content text/html;
charset=utf-8}] inside your [:head]
(can this be done with Jetty?)
2010/8/10 limux liumengji...@gmail.com:
hi!
I am doing a real-file demo with ring, compojure, hiccup, and database
access as well.
There is some chinese
Access to C/C++ is only available via JNI, which requires a bit of technical
understanding about the Java-C bridge. Are you just trying to make use of a C++
library you already have, for which there is no pure Java equivalent?
-Fred
--
Science answers questions; philosophy questions answers.
I need to write raw bytes to the file. I do it with:
(.write (FileOutputStream /path) bytes)
...where bytes must be of type byte[]. Please note it cannot be
Byte[].
I tried to convert my sequence with both (bytes) and/or (into-array)
functions and got frustrated, one example:
user=
Laurent,
Looking through the output of javap -v, it looks to me like this is
roughly what's been emitted (please forgive the mix of clojure and
java):
try {
(prn :test)
(swap! a inc)
(.foo nil)
} finally {
(swap! a inc)
(.foo nil)
}
Which explains why @a is 3 -- I'm not sure this is
2010/8/10 limux liumengji...@gmail.com:
There is some chinese chararters in the tables. I want to display them
by hiccup, but browser display those chinese character as ???.
I spoke to him on #clojure and from what I could tell from some
experiments I asked him to run:
(map int 刘孟江) - (21016
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/
Compiler.java
index f5684f1..af55660 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -1775,7 +1775,7 @@ public static class TryExpr implements Expr{
By into-array default, into-array returns an array of the capital-B
Bytes (that's what the cryptic [Ljava.lang.Byte; in the error message
means). To get an array of primitive bytes (the class being printed as
[B), you can pass the type as additional parameter
(into-array Byte/TYPE mybytes)
On
On Aug 10, 7:19 pm, Janico Greifenberg j...@acm.org wrote:
By into-array default, into-array returns an array of the capital-B
Bytes (that's what the cryptic [Ljava.lang.Byte; in the error message
means). To get an array of primitive bytes (the class being printed as
[B), you can pass the
Hi there, I'm very new to both Clojure and Emacs, but I've come across
the following unexpected situation when wanting to activate clojure-
mode in my slime REPL:
Running Emacs 23 on OS X, installed clojure-mode, slime, slime-repl
and swank-clojure via ELPA (the same situation arises when getting
To all - THANKS (especially David Sletten) for the excellent
responses! Very helpful.
--
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 -
Hi,
there is also byte-array:
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/byte-array
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that
Now we are at eclipse / clojure, I ahave had some issues.
I love eclipse, have used it a lot with java, but i could not get it
working satisfactorily with cloure and ccw. Hopefully unjustified.
I am using windows (XP). My issues were that as soon as I had had some
compilation error (in ccw) i
On Tue, Aug 10, 2010 at 1:09 PM, joegg joega...@gmail.com wrote:
diff --git a/src/jvm/clojure/lang/Compiler.java b/src/jvm/clojure/lang/
Compiler.java
index f5684f1..af55660 100644
--- a/src/jvm/clojure/lang/Compiler.java
+++ b/src/jvm/clojure/lang/Compiler.java
@@ -1775,7 +1775,7 @@ public
Hi,
sad you gave up on ccw :-(.
Let's address your point, though ...
2010/8/10 gammelgedden gammelged...@gmail.com
Now we are at eclipse / clojure, I ahave had some issues.
I love eclipse, have used it a lot with java, but i could not get it
working satisfactorily with cloure and ccw.
On 10 Aug 2010, at 19:19, Mike Meyer wrote:
On Tue, 10 Aug 2010 09:57:02 -0700 (PDT)
Alexis Rondeau alexis.rond...@gmail.com wrote:
What I would like to do is to enable clojure-mode when I get my REPL
(connected either via swank-clojure-project or lein swank/M-x slime-
connect) but whenever
Thanks! I will definitely give it another try :-)
--
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.
010/8/10 gammelgedden gammelged...@gmail.com
Thanks! I will definitely give it another try :-)
feedback welcome (especially for things you don't like - and how you would
like them to be - )
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post
How do I construct
SetMyType s = new HashSet();
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
On Tue, Aug 10, 2010 at 2:51 PM, Chouser chou...@gmail.com wrote:
That patch seems to essentially reverse this one:
http://github.com/clojure/clojure/commit/5e9f2b293b307aa7953cd390360d24549e542b92
...which suggests to me there must be a better solution, though I
don't see yet what it would
2010/8/10 Tim Daly d...@axiom-developer.org
How do I construct
SetMyType s = new HashSet();
in clojure?
Can you be more precise about the context of what you're trying to achieve ?
'cause the naive answer to your question is
(def s #{})
or
(let [s #{}] ...)
but I think you have a
I looked into the source of hiccup and tried entering the string 刘孟江
at various places, but I couldn't reproduce the error or find any code
that did any form of encoding.
When playing around with the repl, I was reminded that JLine (used by
lein repl) does not support multibyte encodings
I have java code that reads:
SetMyType s = new HashSet();
I don't know how to write the parameter MyType in clojure
where MyType is a Java class.
Laurent PETIT wrote:
2010/8/10 Tim Daly d...@axiom-developer.org
mailto:d...@axiom-developer.org
How do I construct
SetMyType s = new
Hi, Tim
Can you describe you task?
Sets (and other collections) in clojure don't use generics, as I know. You
can add element to set and check if set contains element. Why do you need
MyType? To allow add only MyType elements in set?
On Tue, Aug 10, 2010 at 11:40 PM, Tim Daly
If you must use Java's HashSet, you can use it untyped:
user= (deftype MyType [])
user.MyType
user= (def my-set (HashSet.))
#'user/my-set
user= (.add my-set (MyType.))
true
user= (.add my-set (java.util.Date.))
true
If you need to enforce the use of a type, use a checked set:
user= (def checked
All of the code I'm trying to convert uses generics everywhere.
I don't know how to construct a generic in clojure.
Is there a syntax for it?
For instance, I have a graph of nodes of type Chart.
They are stored in the graph where the nodes are kept as:
SetChart nodes =
Can I construct a type
This code uses the JGraphT graphing package which
wants to create a graph where the types of the
vertices and edges are generics, as in:
JGraphTMyVertexType,MyEdgeType graph =
and I'm at a loss for how to instantiate a graph in clojure.
Armando Blancas wrote:
If you must use Java's
I have the following function as part of a card-game system I'm
developing:
(defn make-suit
[suit owner ranks]
{suit (map (partial struct-map card
:suit suit
:owner owner
:rank)
ranks)})
(make-suit
Depends on what you mean by that. If you mean, create a hashset for
use in clojure that will only accept MyType objects, I'll defer to
someone here who knows more clojure than I do, though it looks like
metadata preconditions are the way to go.
If you mean, create a hashset you can pass to Java
Similar experience here. For what it's worth, I found that emacs/swank
made my wildest dreams come true - if you're willing to put in the
effort to learn emacs, you'll love emacs for clojure as much as you
love eclipse for java.
On Aug 10, 11:38 am, gammelgedden gammelged...@gmail.com wrote:
Now
2010/8/10 Tim Daly d...@axiom-developer.org
This code uses the JGraphT graphing package which
wants to create a graph where the types of the
vertices and edges are generics, as in:
JGraphTMyVertexType,MyEdgeType graph =
and I'm at a loss for how to instantiate a graph in clojure.
Hi,
Am 10.08.2010 um 23:22 schrieb Tim Daly:
This code uses the JGraphT graphing package which
wants to create a graph where the types of the
vertices and edges are generics, as in:
JGraphTMyVertexType,MyEdgeType graph =
and I'm at a loss for how to instantiate a graph in clojure.
If the JGraphT constructor takes say 2 args arg1 and arg2, you'll just
write
(let [graph (JGraphT. arg1 arg2)] ) and every side will be happy:
clojure, and java.
And when you need to add vertex or edge you create it and add.
If you need to get edge (e.g. getEdge(...) method) you just
2010/8/10 Alan a...@malloys.org:
I have the following function as part of a card-game system I'm
developing:
(defn make-suit
[suit owner ranks]
{suit (map (partial struct-map card
:suit suit
:owner owner
:rank)
Hi,
Am 10.08.2010 um 20:56 schrieb Alan:
which is exactly what I want. But I have failed countless times to
define a make-hand function - I'd like to be able to call (make-
hand :west {:spade [9 5], :club [10]}) and get back
{:spade
({:suit :spade, :owner :west, :rank 9}
{:suit :spade,
BTW, when you're done, it would be great if you could post a report
about your experience using JGraphT from Clojure. I've been thinking
a lot lately about what an ideal graph library would look like in pure
Clojure, and it would be interesting to hear how easy/hard it already
is to use an
first change your nick to whatever you want to register
/nick nickname
then you can register using
/msg NickServ register password em...@address
freenode requires you to confirm your registration i think (via a code
sent via email)
On Aug 10, 7:44 am, Laurent PETIT laurent.pe...@gmail.com
I've pushed the changes to my fork of contrib[1] and would like to get
feedback before pushing to contrib master.
Changes to logging.clj[2]:
New features:
- Log and LogFactory protocols allow adding new implementations
- log macros for using println-style args
- log macros for using format-style
On Aug 7, 6:42 pm, Ben Mabey b...@benmabey.com wrote:
Hi all,
I've run into an issue with a lazy-seq either being prematurely realized
or having the head unwittingly retained. Reading chapter 5 in The Joy
of Clojure I realize that I am breaking one of the rules (page 150 in my
MEAP
83 matches
Mail list logo