I have more information on this now, and it is definitely a bug in
Clojure -- defmacro within a let doesn't work correctly. Consider the
following file:
--- BEGIN foo1a.coj ---
(ns com.ksvanhorn.foo1a)
(let [dummy 0]
(defmacro add [& args] `(unchecked-add ~...@args))
(defmacro mul [& args]
> Or maybe just:
> (defn mo [op & args] (reduce op args))
I believe that won't make clojure make a faster code, but I might be
wrong.
I think the macroexpansion is the right thing if you want speed, as it
seems clojure could optimize well this:
(+ a b)
while it can't optimize this well
(+ a b
On Fri, Apr 24, 2009 at 6:33 AM, Dimiter "malkia" Stanev
wrote:
>
> Here's even more concise version:
>
> (defmacro mo [op & args]
> (reduce (fn [& ab#] (cons op ab#)) args))
Or maybe just:
(defn mo [op & args] (reduce op args))
I don't think that's the point, though. Why not allow bit-and an
On Apr 24, 2:57 am, Kevin Van Horn wrote:
> 1. bit-and, bit-or, and bit-xor only take two arguments. These are
> all associative operations, and as such should take an arbitrary
> number of arguments for the same reason that + and * take arbitrary
> number of arguments:
I totally agree. I
When unchecked-add is given an invalid argument, sometimes it throws
an exception, and sometimes it does something very weird -- it returns
the code for the call!
Referring to the files foo1.clj and foo2.clj below, if I type at the
REPL
(use 'com.ksvanhorn.foo2)
I get "java.lang.IllegalA
billh04, have a look at the compojure project
(http://github.com/weavejester/compojure/tree/master).
In that James uses an "immigrate" function which may be useful to you.
Also the structure used is a good example of a reasonably large, quite
complex project.
Hth, Adrian.
On Fri, Apr 24, 2009 at
Hi,
Please note that a convention (but it's really just one convention)
could also be to name file for partB : place_partB.clj (or even
place_part_b.clj since in clojure camel case notation is not the
preferred way to write things, hyphens and lower cases are -> but
hyphens must be replaces by u
Here's even more concise version:
(defmacro mo [op & args]
(reduce (fn [& ab#] (cons op ab#)) args))
On Apr 23, 9:23 pm, "Dimiter \"malkia\" Stanev"
wrote:
> You can make your own macro to do that:
>
> (defmacro mo [op & args]
> (reduce (fn [a# b#] (cons op [a# b#])) args))
>
> (mo + 1 2 3
You can make your own macro to do that:
(defmacro mo [op & args]
(reduce (fn [a# b#] (cons op [a# b#])) args))
(mo + 1 2 3 4)
(print "expanded=" (macroexpand '(mo + 1 2 3 4)) "\n")
;expanded= (+ (+ (+ 1 2) 3) 4)
On Apr 23, 5:57 pm, Kevin Van Horn wrote:
> I'm writing an application that ne
I don't think I explained my need clearly.
I try to rephrase it. Suppose I have a source file named place.clj in
a directory named whale/achi/model like the following:
place.clj
(ns whale.achi.model.place)
partA
partB
==
What I want to do is to keep the same namesp
billh04 wrote:
> Right now I have the two files "whale.achi.model.place.clj" and
> "whale.achi.model.placeEvaluation.clj" that make up one name space
> "whale.achi.model.place".
> The first file is the "root" of the namespace.
I think you're confused with how Clojure looks for packages in the
fi
Thanks all - the list is here:
http://clojure.org/community
More additions welcome!
Rich
On Apr 15, 1:48 pm, Amit Rathore wrote:
> Hi Rich,
>
> Bay Area Clojure User
> Grouphttp://www.meetup.com/The-Bay-Area-Clojure-User-Group/
>
> Thanks!
>
> Regards,
> Amit Rathore.
>
> On Apr 9, 12:00 pm
I'm writing an application that needs fast, high-quality random number
generation, so I've been implementing a Mersenne Twister random number
generator. I'm finding that bit-twiddling in Clojure can be a "bit"
awkward. Here are some specifics:
1. bit-and, bit-or, and bit-xor only take two
On Apr 23, 11:24 am, Laurent PETIT wrote:
> 2009/4/23 Rich Hickey :
>
>
>
> > On Apr 22, 12:41 pm, Laurent PETIT wrote:
> >> 2009/4/22 Rich Hickey :
>
> >> > [...]
> >> > {:major 1, :minor 0, :incremental 0, :qualifier :rc1 :interim true}
>
> >> > for interim versions and
>
> >> > {:major 1, :
I came across the term "root lib" when I googled on how to have one
lib with source in multiple files. But, it appears that this was just
discussion. I couldn't find the information I wanted on the main
clojure page.
Right now I have the two files "whale.achi.model.place.clj" and
"whale.achi.mode
"meld" results look good (unless I made a mistake somewhere).
I merged two collections, each with 2 million unique elements. did union of
sorted sets, then did meld with my heap implementation:
performing union of two sorted sets
"Elapsed time: 18881.81 msecs"
--
On Apr 23, 2:43 pm, Stuart Sierra wrote:
> Possibly of interest: I saw a presentation about IBM's experimental
> X10 language. (Why they named it after the most annoying ad campaign
> in the history of the web, I'll never know.)
>
> X10 is an extension to Java for concurrency and cluster compu
Possibly of interest: I saw a presentation about IBM's experimental
X10 language. (Why they named it after the most annoying ad campaign
in the history of the web, I'll never know.)
X10 is an extension to Java for concurrency and cluster computing.
The basic idea is to make it possible to write
I'm interested, although I'm not sure if I'll be around that weekend.
I've done quite well in past TopCoder-style contests (where I've had
to use Java); it would be fun to do a competition in Clojure.
-Jason
--~--~-~--~~~---~--~~
You received this message because y
On Apr 23, 2009, at 18:59, Mark Engelberg wrote:
> Konrad has written a library that turns equality into a multimethod.
> This provides the hooks for altering equality for maps, but there are
> a lot of questions in my mind about how well this will coexist with
> other Clojure code and just how s
Nice enhancement!
On Thu, Apr 23, 2009 at 6:43 PM, Christophe Grand wrote:
>
> I updated the tutorial to reflect a new behavior: enlive now precomputes
> html output for untouched or partly untouched elements.
>
> ((template (java.io.StringReader. "untouched element class=foo>won't last") []
>
In Clojure, the closest thing to an object (short of implementing a
class in Java or using gen-class) is the map. But the more I play
around with using maps to implement the kinds of things that objects
are used for in other languages, the more I'm feeling that maps don't
quite cut it.
One probl
I updated the tutorial to reflect a new behavior: enlive now precomputes
html output for untouched or partly untouched elements.
((template (java.io.StringReader. "untouched elementwon't last") []
[[:div last-child]] (content "new content")))
used to return:
("<" "html" ">" "<" "body" ">" "<
to qualify the "simple" part, I was saying that I wanted to restrict myself
to just calling what's in clojure and clojure-contrib, mostly. "simple"
from my user perspective, since another part of the study could easily
include building a data structure on top of what's already in clojure.
On Thu,
2009/4/23 Christophe Grand :
>
> Laurent PETIT a écrit :
>> 2009/4/23 Christophe Grand :
>>
>>> Laurent PETIT a écrit :
>>>
I guess you're right. But a little warning in the javadoc could help
newcomers not shoot themselves in the foot.
And the problem is, calling directly (second)
Point taken, this actually got me thinking about the probability of a hash
match between strings of English words. I tried a playful experiment- I used
a dictionary of 800,000 English words (containing 2 to 32 characters culled
from the Internet) I got 2802 occurrences of strings producing the same
I'm continuing to think about this priority queue stuff, now looking at
"meld", and wondering what would be the best way to approximate it with
what's in clojure right now ... core data structures and simple algorithms.
for example, I could populate two vectors O(n), sort them O(n(log(n))), and
im
Laurent PETIT a écrit :
> 2009/4/23 Christophe Grand :
>
>> Laurent PETIT a écrit :
>>
>>> I guess you're right. But a little warning in the javadoc could help
>>> newcomers not shoot themselves in the foot.
>>> And the problem is, calling directly (second) without calling (first)
>>> woul
2009/4/23 Rich Hickey :
>
>
>
> On Apr 22, 12:41 pm, Laurent PETIT wrote:
>> 2009/4/22 Rich Hickey :
>>
>> > [...]
>> > {:major 1, :minor 0, :incremental 0, :qualifier :rc1 :interim true}
>>
>> > for interim versions and
>>
>> > {:major 1, :minor 0, :incremental 0}
>>
>> > for releases. :interim
On Apr 22, 12:41 pm, Laurent PETIT wrote:
> 2009/4/22 Rich Hickey :
>
> > [...]
> > {:major 1, :minor 0, :incremental 0, :qualifier :rc1 :interim true}
>
> > for interim versions and
>
> > {:major 1, :minor 0, :incremental 0}
>
> > for releases. :interim tracks the SNAPSHOT segment of the versi
On Thu, Apr 23, 2009 at 11:04 AM, Rich Hickey wrote:
> On Apr 23, 8:59 am, Andrew Wagner wrote:
> > > Sounds like a fun thing to try. Could someone give a brief
> > > description of what would be required in terms of time commitment to
> > > participate on a team? (Sadly, spare time is hard to
On Apr 23, 8:59 am, Andrew Wagner wrote:
> > Sounds like a fun thing to try. Could someone give a brief
> > description of what would be required in terms of time commitment to
> > participate on a team? (Sadly, spare time is hard to come by...)
>
> It's just one weekend. As much or as little
2009/4/23 Christophe Grand :
>
> Laurent PETIT a écrit :
>> I guess you're right. But a little warning in the javadoc could help
>> newcomers not shoot themselves in the foot.
>> And the problem is, calling directly (second) without calling (first)
>> would work most of the time. I wanted to make
Laurent PETIT a écrit :
> I guess you're right. But a little warning in the javadoc could help
> newcomers not shoot themselves in the foot.
> And the problem is, calling directly (second) without calling (first)
> would work most of the time. I wanted to make it fail every time =>
> same behaviou
2009/4/23 Christophe Grand :
>
> Laurent PETIT a écrit :
>> 2009/4/23 Christophe Grand :
>>
>>> *Warning this message contains mutable state and may hurt functional
>>> sensibilities.*
>>>
>>> Ugly hack:
>>>
>>> (defn my-split-with [pred coll]
>>> (let [s (atom coll)
>>> p #(when-let [r (p
Laurent PETIT a écrit :
> 2009/4/23 Christophe Grand :
>
>> *Warning this message contains mutable state and may hurt functional
>> sensibilities.*
>>
>> Ugly hack:
>>
>> (defn my-split-with [pred coll]
>> (let [s (atom coll)
>>p #(when-let [r (pred %)] (swap! s rest) r)]
>>[(take-
2009/4/23 Christophe Grand :
>
> *Warning this message contains mutable state and may hurt functional
> sensibilities.*
>
> Ugly hack:
>
> (defn my-split-with [pred coll]
> (let [s (atom coll)
> p #(when-let [r (pred %)] (swap! s rest) r)]
> [(take-while p coll) (drop-while pred (lazy-s
My bitbucket contrib mirror is public again at
http://bitbucket.org/shoover/clojure-contrib-mirror. Thanks to bitbucket for
munging unrecognized email addresses per my request.
Shawn
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
>
> Sounds like a fun thing to try. Could someone give a brief
> description of what would be required in terms of time commitment to
> participate on a team? (Sadly, spare time is hard to come by...)
>
It's just one weekend. As much or as little time as you can commit to for
that weekend.
--~-
On Thu, Apr 23, 2009 at 2:11 PM, Emeka wrote:
> Laurent,
>
> Sampi question was;
>
> > Let's say I have a sequence of integers:
> > (def a (3 9 1 5 102 -322 ...))
> >
> > Is there a function for inserting an object—let's say :foo—after
> > elements that fulfill a certain predicate?
> > Furthermo
Laurent,
Sampi question was;
Let's say I have a sequence of integers:
(def a (3 9 1 5 102 -322 ...))
Is there a function for inserting an object—let's say :foo—after
elements that fulfill a certain predicate?
Furthermore, I mean inserting :foo after any block of elements that
fulfill it:
(mys
Ah, and also it's not lazy, e.g. :
(take 10 (reduce #(concat %1 (if (> %2 6) [ :foo %2] [%2])) []
(iterate inc 0
Since you invited comments, please note that the quick way of writing
a literal list '(3 4 5 6 8) is not general, because it does not
evaluate the elements of the list :
Try (let
1:2 user=> (reduce #(concat %1 (if (> %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4 2))
(3 4 5 :foo 8 4 2)
Not good, the expected result would have been
(3 4 5 :foo 8 4 2 :foo)
Regards,
--
Laurent
2009/4/23 Emeka :
>
> (reduce #(concat %1 (if (> %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4 2))
>
> Note th
(reduce #(concat %1 (if (> %2 6) [ :foo %2] [%2])) [] '(3 4 5 8 4 2))
Note that I am not a programmer and do not know much about writing code,
however the above snippet in my view can achieve the result you desired. I
invite comments on the above.
Regards,
Emeka
On Thu, Apr 23, 2009 at 10:52 AM,
*Warning this message contains mutable state and may hurt functional
sensibilities.*
Ugly hack:
(defn my-split-with [pred coll]
(let [s (atom coll)
p #(when-let [r (pred %)] (swap! s rest) r)]
[(take-while p coll) (drop-while pred (lazy-seq @s))]))
Now it works ;-)
Laurent PETIT
Hello,
I've started dabbling into Swing & Clojure, and for fun decided to
translate one of the Sun examples (requires Java SE 1.6 though)
It's located here:
http://java.sun.com/docs/books/tutorial/uiswing/examples/learn/index.html#CelsiusConverter
and the java code here:
http://java.sun.
Christophe Grand a écrit :
> Hi Adrian!
>
> Thanks for this tutorial, I put it on the wiki
> http://wiki.github.com/cgrand/enlive/getting-started (I fixed two typos:
> a missing paren and an extraneous colon and I simplified to-li).
And I removed the part talking about right since I already mer
This is a general problem with function (split-with) (and derivatives
such as partition-by ...),
This should certainly deserve a mention in their respective
docstrings, I think. Because the docstring speak about lazyness, but
not the kind of lazyness that can avoid Out of Memory in corner cases.
Thank you for the suggestion, but doesn't help.
Note again that I use it with no problems with plain java:
---file:SwigTest.java---
import swig_test.swig_test;
public class SwigTest {
public static void main(String[] args) {
System.load(System.getProperty("user.dir") + "/libswig_test
Hi Adrian!
Thanks for this tutorial, I put it on the wiki
http://wiki.github.com/cgrand/enlive/getting-started (I fixed two typos:
a missing paren and an extraneous colon and I simplified to-li).
Speaking of to-li, (to-li ["one" "two"]) can be written (map (wrap :li)
["one" "two"]).
While tr
Laurent PETIT a écrit :
> Hi Meikel,
>
> It seems to me that your version is the only safe one so far, that
> would succesfully indefinitely return values with this test:
>
> (dorun (mystery-function true? :foo (repeat true)))
>
> Mine, a new version of mine I'll never bother to publish, and
> Chr
On Thu, Apr 23, 2009 at 9:44 AM, Laurent PETIT wrote:
>
> Hi Meikel,
>
> It seems to me that your version is the only safe one so far, that
> would succesfully indefinitely return values with this test:
>
> (dorun (mystery-function true? :foo (repeat true)))
>
> Mine, a new version of mine I'll n
On Thu, Apr 23, 2009 at 1:11 AM, Christophe Grand wrote:
>
> Hi all!
>
> (defn mystery-function [pred coll]
> (lazy-seq
> (when (seq coll)
> (let [[run etc] (split-with pred coll)]
> (if (seq run)
> (concat run (cons :foo (mystery-function pred etc)))
> (cons (fi
Hi,
Here is my final word (I promise :-):
(defn mystery-function [f s o]
(let [s (seq s)
preds (map f s)]
(mapcat #(if (and %2 (not %3)) [%1 o] [%1]) s preds
(concat (rest preds) [false]
I has only one drawback AFAIK (and depending on your use case, it
You version does not work for certain kind of data, (as did mine), see
my answer to Meikel for more detail,
--
Laurent
2009/4/23 Christophe Grand :
>
> Hi all!
>
> (defn mystery-function [pred coll]
> (lazy-seq
> (when (seq coll)
> (let [[run etc] (split-with pred coll)]
> (if (
Hi Meikel,
It seems to me that your version is the only safe one so far, that
would succesfully indefinitely return values with this test:
(dorun (mystery-function true? :foo (repeat true)))
Mine, a new version of mine I'll never bother to publish, and
Christophe's all retain head.
To explain o
56 matches
Mail list logo