Re: transients problem

2018-02-24 Thread Christophe Grand
This makes me think that transients could (should?) be made reducible. On Sat, Feb 24, 2018 at 4:19 PM, Timothy Baldridge wrote: > Yes, transients mutate when updated. Seqs over sets are a immutable view > over a collection. So if someone did get this to work, the implementation > could be incor

Re: transducers and eduction

2017-09-05 Thread Christophe Grand
Hi, the naming of your args [x r] is a bit confusing as x is usually the second item and the first is often caled acc (and it's also the argument passed to the completing arity (1-arg)). However acc is a name inherited from reduce and does not really represent its actual purpose. *You have to cons

Re: escape characters to make a string literal

2017-03-30 Thread Christophe Grand
A funny thing is that octal or hexadecimal escapes are not part of EDN (even if most readers recognize them). On Wed, Mar 29, 2017 at 8:49 PM, Brian Craft wrote: > A funny hole in the meta-programming story. I don't think the String or > Character classes have methods that do this. > > Also inte

Re: What is the correct way to increment a value in an atom from multiple workers?

2017-02-11 Thread Christophe Grand
Instead of dereferencing again for lgging, log the return value of the swap! call, thus you will log exactly what the worker just put in the atom. hth, Christophe On Fri, Feb 10, 2017 at 10:18 PM, Laws wrote: > (timbre/log :trace @accuracy-and-precision) -- On Clojure http://clj-me.cgran

Re: Literal map keys are checked for duplication before evaluation?

2017-01-06 Thread Christophe Grand
On Thu, Jan 5, 2017 at 6:45 AM, Tianxiang Xiong wrote: > So clearly a check is also made *after* evaluating the key forms. I'm > just not sure why we need to check *before* evaluating the key forms. > Because Clojure is a lisp. Code is data. {(java.util.UUID/randomUUID) 1 (java.util.UUID/randomU

Re: No transducer variant of partition?

2016-10-12 Thread Christophe Grand
Not a rational for why there's no partition transducer in core but I have a partition transducer in this lib (https://github.com/cgrand/xforms). => (sequence (x/partition 3) (range 8)) ([0 1 2] [3 4 5]) => (sequence (x/partition 3 2) (range 8)) ([0 1 2] [2 3 4] [4 5 6]) => (sequence (x/partition 3

Re: grouping and mapping

2016-08-12 Thread Christophe Grand
I have a collection of transducers that I use in such cases: (require '[net.cgrand.xforms :as x] '[clojure.string :as str]) (into {} (x/by-key (comp (map str/upper-case) (x/into []))) ;=> [[:a "foo"] [:b "bar"] [:a "baz"]]) On Fri, Aug 12, 2016 at 7:14 PM, Moe Aboulkheir wrote: > As far a

Re: recursive specs

2016-06-09 Thread Christophe Grand
Hi Frédéric, On Thu, Jun 9, 2016 at 2:21 PM, Frederic Peschanski < frederic.peschanski.w...@gmail.com> wrote: > ;; == > (:require [clojure.spec :as s])) > (s/def ::zero #{:zero}) > (s/def ::one #{:one}) > (s/def ::succ #{:succ}) > (s/def ::odd nil) > (s/def ::even (s/or :zero ::zero

Re: clojure.spec

2016-05-26 Thread Christophe Grand
urn :k) > [:r :a :k] (gen/return :a) > [:r :a :r :a :k] (gen/return :aa)}))) > > (:k (:a) ((:aa)) :k :k :k :k :k (:a) :k) > > I’ll have to think about the suffixes > > > On May 25, 2016, at 7:56 AM, Christophe Grand > wrote: >

Re: clojure.spec

2016-05-25 Thread Christophe Grand
Speaking of recursive definitions: how to provide an override in a recursive spec? Would it be possible to have path suffixes (in addition to paths not in replacement of) in the override map? Thanks, Christophe On Mon, May 23, 2016 at 6:16 PM, Alex Miller wrote: > Yes, you can create recursive

Re: Profiling in Counterclockwise

2014-10-09 Thread Christophe Grand
To profile whithin Eclipse you need to have the TPTP pugin installed http://www.eclipse.org/tptp/. That said, I *never* managed to have it work (I haven't tried for at least two years), launching from Eclipse as usual and connecting an external profiler (VisualVM or Yourkit works fine -- Yourkit ev

Re: Defs with %

2014-06-18 Thread Christophe Grand
thanks for the report, fixed On Wed, Jun 18, 2014 at 1:30 AM, Mike Thompson wrote: > > Colin, many thanks. Issue created: > https://github.com/cgrand/sjacket/issues/19 > > > On Wednesday, June 18, 2014 4:08:53 AM UTC+10, Colin Jones wrote: > >> Yeah the latter version parses as 2 symbols in sja

Re: [RFC] Roundtripping namespaced xml documents for data.xml

2014-05-28 Thread Christophe Grand
On Tue, May 27, 2014 at 2:05 AM, Herwig Hochleitner wrote: > My use case is parsing and generating webdav and I'd much rather work with > model tier than just looking at tag names and assuming that the prefixes > are set up correctly. Yes, that might exclude clients, that generate > invalid webdav

Re: Porting parsley & paredit.clj to Clojurescript: Crazy, or inevitable?

2014-04-02 Thread Christophe Grand
Hi Kovas, On Wed, Apr 2, 2014 at 3:26 AM, kovas boguta wrote: > Looking through the source for parsley & paredit.clj, I'm halfway > convinced that maybe its not so hard to port these to clojurescript. > > Anyone have input in either direction? > We (Laurent and me) are planning an overhaul of p

Re: random thought on #_

2014-01-22 Thread Christophe Grand
#_ nests nicely: #_#_ comments out the next two expressions. Christophe On Wed, Jan 22, 2014 at 2:03 PM, Dave Sann wrote: > I like #_, it's very useful > > I had a thought I'd like to have #__ - two _ to comment 2 expressions - > specifically for commenting in maps > > Then I thought > > #_n

Re: Clojure, floats, ints and OpenGL

2013-09-17 Thread Christophe Grand
I ported Mikera's benchmark to Clojure using my patch https://gist.github.com/cgrand/6595939 The ratio between time-float and time-double (0.632) is very similar to the ratio between timeFloat and timeDouble Mikera reported (0.618) On Tue, Sep 17, 2013 at 1:25 PM, Christophe Grand wrote: &

Re: Clojure, floats, ints and OpenGL

2013-09-17 Thread Christophe Grand
Here is the mundane patch I described earlier: https://github.com/cgrand/clojure/commit/4c202ad9757ce47ac9e669847c0e5bf68785e2d6 It adds four functions (add-, multiply-, divide- and subtract-float), backs them with their corresponding bytecodes and enhance the conversion emitted when going from lo

Re: Clojure, floats, ints and OpenGL

2013-09-12 Thread Christophe Grand
As others have already said: long & double only is a restriction for function args. Not for interop. Not for local computations. Not for args to definterface methods. The reason for this restriction is the combinatorial explosion. (So you may have to roll your own interface and a couple of helper m

Re: finding retained head

2013-09-11 Thread Christophe Grand
a heap space (NO_SOURCE_FILE:0) >> > user=> (defn t2 [n c] (f (fn [] (doseq [x c] (identity x) >> > #'user/t2 >> > user=> (defn t1 [n c] (f (^:once fn* [] (dorun (map identity c) >> > #'user/t1 >> > user=> (t1 0 (range 100)) >> >

Re: finding retained head

2013-09-11 Thread Christophe Grand
documentation for this. What does it do? > > On Wednesday, September 11, 2013 2:22:56 AM UTC-7, Christophe Grand wrote: > >> >> On Wed, Sep 11, 2013 at 6:00 AM, Brian Craft wrote: >> >>> (defmacro transaction >>> [& body] >>> `(transac

Re: Functional purity and "globals" in Clojure

2013-09-11 Thread Christophe Grand
I like the dynamic var approach. It even allows to enforce that submodules won't see some keys (using select-keys or dissoc). It tests nicely too. Christophe -- On Clojure http://clj-me.cgrand.net/ Clojure Programming http://clojurebook.com Training, Consulting & Contracting http://lambdanext.eu

Re: finding retained head

2013-09-11 Thread Christophe Grand
On Wed, Sep 11, 2013 at 6:00 AM, Brian Craft wrote: > (defmacro transaction > [& body] > `(transaction* (fn [] ~@body))) > > I'm not sure how to avoid that. The anonymous function created here > doesn't take parameters. > The fix for this is: (defmacro transaction [& body] `(transaction*

Re: a lazy version of shuffle.

2013-08-23 Thread Christophe Grand
=> (defn lazy-shuffle [v] (lazy-seq (if (seq v) (let [idx (rand-int (count v))] (cons (nth v idx) (lazy-shuffle (pop (assoc v idx (peek v) => (take 10 (lazy-shuffle (vec (range 100 (77 63 37 99 81 73 25 85 35 10) On Fri, Aug 23, 2013 at 1

Re: cgrand's parsley... text offsets ?

2013-08-23 Thread Christophe Grand
Hi, You may be interested in the net.cgrand.parsley.functional-trees and net.cgrand.parsley.views namespaces. you need to pass options :make-node fnode and :make-leaf :fleaf to your parser. Now the result of parse-tree is not a tree anymore but an opaque object (a function). . You can then compu

Re: Confused by var eval behaviour

2013-08-09 Thread Christophe Grand
is used though. Am I > right in thinking that clojure.core/eval is not calling the function > that the compiler uses, but instead serializing everything and pushing > it through the same pathway as compiling text files? > > On 8 August 2013 16:43, Christophe Grand wrote: > > Righ

Re: butlast with reducers

2013-08-09 Thread Christophe Grand
) (java.util.ArrayDeque. (int n))) f1 init On Thu, Aug 8, 2013 at 3:34 PM, Christophe Grand wrote: > ArrayDeque based versions: > > > (defn drop-last [n coll] > (reducer coll > (fn [f1] > (let [buffer (java.util.ArrayDeque. (int n))] > > (fn self >

Re: Confused by var eval behaviour

2013-08-08 Thread Christophe Grand
al x) > # > > user=> (eval [x]) > [#] > > user=> (read-string "# >") > RuntimeException Unreadable form clojure.lang.Util.runtimeException > (Util.java:219) > > On 8 August 2013 14:58, Christophe Grand wrote: > > The error is caused by the fact

Re: Confused by var eval behaviour

2013-08-08 Thread Christophe Grand
The error is caused by the fact that eval sees the var as a constant (or part of) and tries to serialize the constant. # is unreadable while #'user/x is that explains teh difference in behaviour. On Thu, Aug 8, 2013 at 3:40 PM, Jamie Brandon wrote: > This has me stumped: > > user=> (with-local-v

Re: butlast with reducers

2013-08-08 Thread Christophe Grand
uce coll (fn [^java.util.Deque q x] (.add q x) (when (> (count q) n) (.pop q)) q) (java.util.ArrayDeque. (int n))) prn) f1 init On Thu, Aug 8, 2013 at 3:16 PM, Christophe Grand wrote: > You need to use a buffer

Re: butlast with reducers

2013-08-08 Thread Christophe Grand
You need to use a buffer to defer calls to the reduced function (defn drop-last [n coll] (reducer coll (fn [f1] (let [buffer (atom clojure.lang.PersistentQueue/EMPTY)] (fn self ([] (f1)) ([ret x] (let [b (swap! buffer conj x)]

Re: Casting to Object[]

2013-07-02 Thread Christophe Grand
=> (def a (object-array 1)) #'user/a => (set! *warn-on-reflection* true) true => (aset a 0 nil) Reflection warning, NO_SOURCE_PATH:1:1 - call to aset can't be resolved. nil => (aset ^objects a 0 nil) nil hth, Christophe On Tue, Jul 2, 2013 at 5:13 PM, Mikera wrote: > I think that is the only

Re: Why is using (not (empty? coll)) not idiomatic?

2013-05-13 Thread Christophe Grand
I second: using seq to test for emptiness is only one half of the idiom, the second half is to bind and to destructure (usually with if-let) the returned value. Christophe On Sat, May 11, 2013 at 12:08 PM, Chris Ford wrote: > IMHO it's a bit subjective, but empty? is defined as (not (seq coll))

Re: prog1

2013-05-13 Thread Christophe Grand
Hi On Sat, Nov 8, 2008 at 5:10 PM, Robert Pfeiffer < pfeiffer.rob...@googlemail.com> wrote: > Is there a benefit in implementing this as a macro instead of a > function? The function version would be very simple: > > (defn returning [returnval & body] >returnval) > The macro does not alloca

Re: Clojure special forms

2013-04-30 Thread Christophe Grand
Hi David, Special forms exist because they have special semantics and evaluation rules. Is there some overlap between them? Absolutely: when you have fn you don't need let. Still we have let. About reduce: originally reduce was pure clojure with no interop, the .reduce you see is just for the chu

Re: Clojure Performance For Expensive Algorithms

2013-02-27 Thread Christophe Grand
On Wed, Feb 27, 2013 at 11:20 AM, Marko Topolnik wrote: > On Wednesday, February 27, 2013 10:59:33 AM UTC+1, Christophe Grand wrote: > >> >> Now that reduce can be short-circuited, redifining every?, some and al on >> top of it would yield some interesting gains: >&g

Re: Clojure Performance For Expensive Algorithms

2013-02-27 Thread Christophe Grand
On Wed, Feb 27, 2013 at 10:21 AM, Marko Topolnik wrote: > > (defn blank? [s] (every? #(Character/isWhitespace %) s)) >> >> Have you ever wondered about its performance? Here you go: >> >> user> (time (dotimes [_ 1] (blank? " >> "))) >> "Elapsed time: 3887.578 msecs" >> > > To give

Re: Redefinition of datatypes

2013-02-22 Thread Christophe Grand
I have,'t looked much into it but my hunch is that it's the same bytecode but loaded by two different classloaders. So a double loading rather than a double compilation. Christophe On Fri, Feb 22, 2013 at 8:26 AM, Ambrose Bonnaire-Sergeant < abonnaireserge...@gmail.com> wrote: > Hi, > > I don't

Re: Clojure Performance For Expensive Algorithms

2013-02-21 Thread Christophe Grand
I updated my answer on SO, with a deftype-based one that gives me an additional 30% boost. On Tue, Feb 19, 2013 at 6:38 PM, Geo wrote: > What about the call to .equals? > > > On Tuesday, February 19, 2013 12:20:28 PM UTC-5, Marko Topolnik wrote: >> >> The difference between String[] and Object[

Re: Performance issue with hashing records

2013-02-06 Thread Christophe Grand
Hi On Mon, Feb 4, 2013 at 2:29 PM, AtKaaZ wrote: > => (class {:x "a" :y 3}) > clojure.lang.Persistent*Array*Map > => (def m {:x "a" :y 3}) > #'runtime.q/m > => (class m) > clojure.lang.Persistent*Hash*Map > huh? that one I can't explain, I'll have to do some research. => (def m (let [] {:x "a"

Re: Performance issue with hashing records

2013-02-06 Thread Christophe Grand
Hi, On Mon, Feb 4, 2013 at 12:13 PM, Paul Stadig wrote: > On Sunday, February 3, 2013 9:56:49 PM UTC-5, puzzler wrote: >> >> In these examples, the map/record is freshly created each time through >> the loop, so caching should not be a factor. >> > > Good point. So maybe it's not the caching :).

Re: Best practice - (:keyword map) versus (map :keyword)

2013-01-29 Thread Christophe Grand
You have 3 choices, all supporting a -n optional default value: 1. (:kw m), 2. (m :kw), 3. (get m :kw) If your keyword is literal, always pick #1. So if your keyword is not literal then you are left with either (m x) or (get m x) -- remember x is not litteral. The later version will work with map

Re: 1.5 alpha 5 - performance issues relating to hashing and equals

2013-01-25 Thread Christophe Grand
Hi Mark, The hasheq chaching patch got applied between beta1 and beta2 so it's not in alpha5. The answer to your problem is to compute hahses incrementally. There's a very old ticket for that http://dev.clojure.org/jira/browse/CLJ-15at the time it was a bullet point on one of Rich's todo list on A

Re: Simple FIFO cache for memoize

2013-01-23 Thread Christophe Grand
and kotka.de/blog/2010/03/memoize_done_right.html has some intersting discussion on memoization On Wed, Jan 23, 2013 at 9:12 AM, Baishampayan Ghose wrote: > Take a look at core.cache - https://github.com/clojure/core.cache ~BG > > On Wed, Jan 23, 2013 at 1:11 PM, Omer Iqbal wrote: > > I've been

Re: abysmal multicore performance, especially on AMD processors

2012-12-12 Thread Christophe Grand
See https://github.com/flatland/classlojure for a, nearly, ready-made solution to running several Clojures in one JVM. On Wed, Dec 12, 2012 at 5:20 PM, Lee Spector wrote: > > On Dec 12, 2012, at 10:45 AM, Christophe Grand wrote: > > Lee, while you are at benchmarking, would you

Re: abysmal multicore performance, especially on AMD processors

2012-12-12 Thread Christophe Grand
Lee, while you are at benchmarking, would you mind running several threads in one JVM with one clojure instance per thread? Thus each thread should get JITted independently. Christophe On Wed, Dec 12, 2012 at 4:11 PM, Lee Spector wrote: > > On Dec 12, 2012, at 10:03 AM, Andy Fingerhut wrote: >

Re: ANN: clj-schema, Schemas For Clojure Maps

2012-12-11 Thread Christophe Grand
On Tue, Dec 11, 2012 at 9:30 AM, Alex Baranosky < alexander.barano...@gmail.com> wrote: > Christophe, one thing I've wondered about the design of clj-schema is > whether the schema is even the right place for determining looseness or > strictness. In some sense that is a property of the validatio

Re: ANN: clj-schema, Schemas For Clojure Maps

2012-12-10 Thread Christophe Grand
Oh and clj-schema is really something I would use and promote. On Mon, Dec 10, 2012 at 10:01 AM, Christophe Grand wrote: > Hi Alex, > > To echo Laurent's concern: if you use schema to validate inputs you get > from another (sub)system then, in my opinion, a loose schema

Re: ANN: clj-schema, Schemas For Clojure Maps

2012-12-10 Thread Christophe Grand
Hi Alex, To echo Laurent's concern: if you use schema to validate inputs you get from another (sub)system then, in my opinion, a loose schema is a better fit. It's the must-understand/must-ignore schism once again. Must-ignore (loose schemas) requires care when revising a schema (since any piece o

Re: group-by vs. reducers?

2012-12-07 Thread Christophe Grand
ups k []) a)))) > > ? > > Las > > 2012/12/7 Christophe Grand > >> Hi, >> >> There are indeed too much allocationfoing on in your r/map. >> You don't need the rmap, >> >> Start from a plain old reduce like your reduce-by-naive, replace re

Re: group-by vs. reducers?

2012-12-07 Thread Christophe Grand
Hi, There are indeed too much allocationfoing on in your r/map. You don't need the rmap, Start from a plain old reduce like your reduce-by-naive, replace reduce by r/fold, remove the seed and add the combine-fn (which now provides the seed): (defn group-by-red [f coll] (r/fold (partial mer

Re: exception in 'map' mutates result to nil -- bug?

2012-12-03 Thread Christophe Grand
This behavior has the same source as CLJ-457. Applying my patch for CL-457, I get: user=> (def mapped (map (fn [_] (throw (Exception.))) [1 2 3])) #'user/mapped user=> mapped Exception user/fn--1 (NO_SOURCE_FILE:1) (user=> mapped RuntimeException Recursive seq realization clojure.lang.LazySeq.s

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-12-02 Thread Christophe Grand
Hi maclo, Your code assume there is two "primes" sequences: the result and the one being constructed. But there's only one and which is infinite. You define your sequence as being (cons 2 something) and computing "something" requires evaluating (every? #(pos? (mod 3 %)) (cons 2 something)) since (

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-30 Thread Christophe Grand
Hallo, On Thu, Nov 29, 2012 at 11:20 PM, Ulrich wrote: > Now should we consider this a clojure bug? > It is, see http://dev.clojure.org/jira/browse/CLJ-457 What clojure version are you using btw to get the exceptions? master from Github with my patch to CLJ-457 applied :-) Now, that's clear

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-29 Thread Christophe Grand
On Wed, Nov 28, 2012 at 5:24 PM, Ulrich wrote: > Then I found the solution with "iterate" and then further reduced starting > values to '(2) and then to '() what worked as well, > as every? returns true for empty sequences, what is right from a logical > point of view too. And with '() as start e

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Christophe Grand
A more succinct test case: user=> (def escher-seq (lazy-seq (lazy-seq (if (seq escher-seq) nil (list 42) #'user/escher-seq user=> escher-seq (42) thus escher-seq is not empty because it is empty :-) On Wed, Nov 28, 2012 at 4:42 PM, Christophe Grand wrote: > Hi Ulrich, >

Re: (iterate inc 2) vs (drop 2 (range)) in corecursion

2012-11-28 Thread Christophe Grand
Hi Ulrich, Wow, you got me scratching my head because your code should not even work. The problem I see with it is that your recursion has no base case. You have to know that 2 is prime to boot the algorithm. Eg (def primes (cons 2 (filter (fn isprime[n] (every? #(po

Re: Primitive function boxes and unboxes result value

2012-11-21 Thread Christophe Grand
Hi Gunnar, The only thing I fixed is related to recur (whose type was null and thus not unifiable with a primitive type). Concerning your fib2, I think the proble comes from the "then" being a long (1) and the else a double. Thus boxing is required to return either a long or double (well a Long a

Re: Primitive function boxes and unboxes result value

2012-11-21 Thread Christophe Grand
I created an issue and attached a patch http://dev.clojure.org/jira/browse/CLJ- Now the 5 last lines of bytecode are: 52: goto9 55: goto61 58: pop 59: dload 5 61: dreturn Christophe On Tue, Nov 20, 2012 at 10:27 PM, Christophe Grand wrote: > I think CLJ-

Re: Primitive function boxes and unboxes result value

2012-11-20 Thread Christophe Grand
I think CLJ-701 is about loop in non-terminal position. On Tue, Nov 20, 2012 at 6:30 PM, Andy Fingerhut wrote: > Any relationship to CLJ-701, other than similar symptoms? > > http://dev.clojure.org/jira/browse/CLJ-701 > > Andy > > On Nov 20, 2012, at 9:15 AM, Christoph

Re: Primitive function boxes and unboxes result value

2012-11-20 Thread Christophe Grand
Hi, It looks like, because of the recur, the compiler fails to notice that if returns a primitive. As far as I understand in Compiler.java, RecurExpr does not implement MaybePrimitiveExpr and thus causes on canEmitPrimitive the surrounding IfExpr to return false. Someone to confirm this analysis?

Re: question concerning macros by a newbie

2012-11-13 Thread Christophe Grand
(symbol (str ":" (str (first components should be (keyword (first components)) In your expansion, :x is not a keyword but a symbol starting by a colon -- the symbol fn performs no validation on its input. When you copied/pasted it for evaluation it was then read as a keyword. Btw I'm a little

Re: What's the difference between `seq` and `lazy-seq`?

2012-11-02 Thread Christophe Grand
Hi, A sequence may be (and commonly is) lazy. Sequences on collections, strings, arrays are not lazy. Nor are those built with cons. Some sequences even have a fast (O(1)) count (eg lists, sequences on strings...) However you sould assume the worst case which is a traversal of the whole sequences

Re: Confused by reference to "capturing" (as opposed to "binding") in C. Grand's talk "(not= DSL macros)"

2012-09-19 Thread Christophe Grand
Exactly! I meant (slide #22) that some functions should extract (capture) the values you are interested in so that your macros only need to deestructure this result: macros should do as little as possible. I hope this clarifies my point. Christophe Le mercredi 19 septembre 2012, Matching Socks a

Re: Doseq, map-style

2012-06-18 Thread Christophe Grand
On Mon, Jun 18, 2012 at 3:37 PM, Kurt Harriger wrote: > > Representations are values in Clojure, they are not mixed with behaviors > like in mainstream OO. It follows that, if your representation need to > change, you can write a converter function (or two if you want to convert > from and to the

Re: Doseq, map-style

2012-06-18 Thread Christophe Grand
On Sun, Jun 17, 2012 at 8:59 PM, Kurt Harriger wrote: > > Data structure is an implementation detail... >> > > It's not. Not in clojure. It is in OO, but clojure is not an OO language, > so it's not an implementation detail in clojure. > > > That is my point, representations SHOULD be considered i

Re: Doseq, map-style

2012-06-12 Thread Christophe Grand
Hi, To contrast our experiences of the language and the different approaches to deal with some problems: On Sun, Jun 10, 2012 at 4:47 AM, Kurt Harriger wrote: > Many will say that side-effecting functions are more difficult to test > then pure functions... However after writing about 4000 lines

Re: Selecting subsets of maps

2012-05-29 Thread Christophe Grand
The expansion idea is interesting: expand your selectors to a seq of paths, redcue with get-in/assoc-in over thme to get the "extract" sense, reduce with update-in+dissoc to get the exclude. Could yield a nice implementation. And now for some nitpicking: * nowadays I'm reluctant to extend a protoc

Re: Selecting subsets of maps

2012-05-29 Thread Christophe Grand
Hi BG, Laurent dragged me in the conversation so here is my take https://gist.github.com/2823916 which strictly follows your proposed "syntax". hth, Christophe On Sat, May 26, 2012 at 6:58 AM, Baishampayan Ghose wrote: > Hi, > > I have a problem wherein I need to select subsets of a given map;

Re: Lexer and parser generator in Clojure

2012-05-20 Thread Christophe Grand
On Sat, May 19, 2012 at 9:44 PM, Jason Jackson wrote: > In retrospect, I would have tried > https://github.com/cgrand/**parsley afaik > it has ~LR1 performance characteristics. > Parsley is closer to LR(0) (but I'd like to make it LR(1) using Pager's lane trac

Re: Drawbridge: a (Ring) HTTP transport for nREPL

2012-03-29 Thread Christophe Grand
It's just a web app, I guess you have to roll out your auth method of choice. On Fri, Mar 30, 2012 at 8:32 AM, Laurent PETIT wrote: > Awesome! > > One question : how to pass security credentials ? > > > > Le 29 mars 2012 à 23:43, Chas Emerick a écrit : > > > Drawbridge is an HTTP/HTTPS nREPL tra

Re: iterate?

2011-07-04 Thread Christophe Grand
=> (= (repeat 100 :foo) (take 100 (iterate identity :foo))) true hth, Christophe On Mon, Jul 4, 2011 at 12:39 PM, Antonio Recio wrote: > Do you know how to solve this? > > (= (repeat 100 :foo) > (take 100 (iterate ___ :foo))) > > -- > You received this message because you are subs

Re: Generated symbols

2011-07-02 Thread Christophe Grand
Creating sentinel values a bit like (Object.) but easier on the eye when debugging. On Sun, Jul 3, 2011 at 6:20 AM, Kazimir Majorinc wrote: > I'm need review of use of symbol and gensym functions in > Clojure. Beside typical alpha-conversion of variables in macros, what > are other typical or int

Re: Any ways to prevent protocol functions from being hardcoded in?

2011-07-02 Thread Christophe Grand
Hi On Jul 1, 8:09 am, Meikel Brandmeyer wrote: > That's not what I understood. I know about the trade-offs between extend and > inline methods. I blogged some time ago about it and voted for extend being > the default until speed matters. However Stuart wrote "protocols are a > low-level implemen

Re: for not returning a lazy sequence

2011-05-21 Thread Christophe Grand
Clojure lazy sequences aren't required to be strictly lazy. Items can be computed in batches (chunks). It depends whether you source seq is chunked or not and whether your seq fns are chunk-aware or not. #'range produces a chunked seq. See (chunked-seq? (seq (range 42))). That's most certainly wh

Re: Subvector

2011-05-16 Thread Christophe Grand
Or: (defn sv [vector value] (let [i (.indexOf ^java.util.List vector value)] (if (neg? i) [] (subvec vector i On Sat, May 14, 2011 at 7:50 PM, Jonathan Fischer Friberg < odysso...@gmail.com> wrote: > I think this should be pretty fast > https://gist.github.com/972423 > > It is at least

Re: Enlive update transformation

2011-05-11 Thread Christophe Grand
Hi, My 2 cents: this solution may be subject to escaping issues. When one needs to pass parameters to Javascript, I often recommend to inject one

Re: How Clojure protocols are implemented internally?

2011-05-10 Thread Christophe Grand
On Tue, May 10, 2011 at 7:13 PM, Krukow wrote: > > > And I've got an impression that protocols are described to be as fast > as > > > interface dispatch (callvirt). > > Almost as fast in case one. There is an indirection because of > dispatch. > There is special support at the call site by the c

Re: Most Elegant Clojure Solution For Wilson's Maze Algorithm

2011-01-27 Thread Christophe Grand
updated with a "rectangular hexgrid" example https://gist.github.com/792959 On Mon, Jan 24, 2011 at 9:07 AM, Christophe Grand wrote: > Hi Conrad, > > Here is my take: https://gist.github.com/792959 > > Since I despise indices I wrote the core algorithm without th

Re: Most Elegant Clojure Solution For Wilson's Maze Algorithm

2011-01-24 Thread Christophe Grand
Hi Conrad, Here is my take: https://gist.github.com/792959 Since I despise indices I wrote the core algorithm without them. That gave me a maze generation code which can create a maze in any kind of graph. This would be fun to run it on the utah teapot for example :-) Christophe On Thu, Jan 20,

Re: Distinguishing a map from a record

2011-01-21 Thread Christophe Grand
Hi! On Fri, Jan 21, 2011 at 1:27 PM, Brian Marick wrote: > In the absence of #'record?, what's the safest way to tell whether a > particular object is a true map or a record? > "true" maps extend clojure.lang.APersistentMap, records don't. hth, Christophe -- Professional: http://cgrand.ne

Re: Lazy sequences with circular definition

2010-11-19 Thread Christophe Grand
Hi, On Fri, Nov 19, 2010 at 11:44 AM, babui wrote: > I've been playing with lazy sequences defined by autoreferential > definition. For instance: > > (def ones (lazy-seq (cons 1 ones))) > > which is equivalent to (def ones (repeat 1)). > > My problem arises when defining the sequence of fibonacc

Re: bimaps in clojure

2010-11-19 Thread Christophe Grand
One call away but rarely persistent or even immutable. On Fri, Nov 19, 2010 at 4:55 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > awesome.. :) i keep forgetting that all of java is just a call away .. hmm > thanks Lachlan..:) > Sunil. > > > On Fri, Nov 19, 2010 at 7:46 AM, jlk wr

Re: bimaps in clojure

2010-11-16 Thread Christophe Grand
O(log32 n) like a direct get. What may confuse you is that only the direct map is hinted. The reverse map doesn't need to: no interop calls on it while it is in reverse position. > On Tue, Nov 16, 2010 at 2:36 PM, Christophe Grand > wrote: > > > You can implement your ow

Re: Function Design: sequence or "&" argument?

2010-11-16 Thread Christophe Grand
Hi, On Tue, Nov 16, 2010 at 5:21 PM, Chris Maier wrote: > That makes sense... thanks, Meikel. > > Maybe my example of + wasn't the best, given its mathematical nature. > > Here's my situation: I'm writing some software to analyze some protein > datasets, part of which entails generating a Venn di

Re: bimaps in clojure

2010-11-16 Thread Christophe Grand
You can implement your own, prettu easily with deftype. However it can be tedious to track every methods, so we need a repl helper function to scaffold the code for us. (defn scaffold [iface] (doseq [[iface methods] (->> iface .getMethods (map #(vector (.getName (.get

Re: Performance of seq on empty collections

2010-11-15 Thread Christophe Grand
On Sun, Nov 14, 2010 at 9:36 PM, Eric Kobrin wrote: > This brought to mind the general case of detecting emptiness. The > current practice of using `seq` to check for non-emptiness wastes > resources. It depends: in many cases you need to call seq anyway in the non-empty branch so seq+if-let is

Re: Polymorphic protocols and containers....

2010-11-05 Thread Christophe Grand
On Fri, Nov 5, 2010 at 8:23 AM, ataggart wrote: > Do you know of a reason why (deftype [foo & more]) isn't read in as > having two fields where the second is a seq? > deftype is low level and exposes limitations of the host and constructors should not be exposed directly (add a new field, change

Re: Polymorphic protocols and containers....

2010-11-04 Thread Christophe Grand
On Fri, Nov 5, 2010 at 1:39 AM, Mike Meyer < mwm-keyword-googlegroups.620...@mired.org> wrote: > It seems like the polymorphism of protocols breaks inside the > methods. This is a problem for having a function that's polymorphic > between an object and a container of the same objects. > > For inst

Re: Reloading java classes

2010-11-04 Thread Christophe Grand
If you launched your repl as a debug process in an IDE code hotswap may work to some extent too. Christophe On Friday, November 5, 2010, Dave Newton wrote: > JRebel is still the best answer. Loading a class at runtime is non- trivial. > I don't know how it deals with handling existing instances

Re: Bug with instance? inside deftypes

2010-11-04 Thread Christophe Grand
To me its an implementation wart which is dictated by the use of the reflection API in the compiler. There is some work done by Stu to create a clojure reflection API with several backends (eg ASM or Java Reflection). However I won't bet on the *current* compiler being fixed. my 2 cents Christoph

Re: partition-starting-every : yet another partition function

2010-09-16 Thread Christophe Grand
On Thu, Sep 16, 2010 at 10:45 PM, Chouser wrote: > On Fri, Sep 10, 2010 at 4:26 PM, Matt Smith wrote: > > problem: convert a collection [1 2 0 1 2 3 0 1 2 3 0 0 1 2] into > > partitions like: > > ((1 2) (0 1 2 3) (0 1 2 3) (0) (0 1 2)) > > In this case, start each partition on a 0. > > Iteratio

Re: simplest graphics?

2010-09-16 Thread Christophe Grand
Hi Lee, On Thu, Sep 16, 2010 at 5:15 AM, Lee Spector wrote: > Also, this would have a smaller impact but I'm curious about it: is there a > way to treat method names as data and then make calls to them, as one can > with clojure functions? Then I could pass things like fillRect, or map rect > to

Re: Feature idea: meta-macros

2010-09-16 Thread Christophe Grand
Hi, On Wed, Sep 15, 2010 at 8:52 PM, Luke VanderHart wrote: > Oh, you're right, of course. > > Still, that doesn't quite meet the case I described, since the > bindings won't effect any spawned threads/agents. > (alter-var-root #'sql log-around) then -- You received this message because you ar

Re: Enhanced Primitive Support

2010-06-18 Thread Christophe Grand
On Fri, Jun 18, 2010 at 2:49 PM, Rich Hickey wrote: > This L suffix idea is a non-starter. Here's why: > > We're in a reader based language. The reader reads objects. When the reader > reads 42, it must return an object. It cannot return an int or a long > primitive. Right now, it returns an Integ

Re: Enhanced Primitive Support

2010-06-18 Thread Christophe Grand
On Fri, Jun 18, 2010 at 8:58 AM, Richard Newman wrote: > It only takes one library to screw up, and the whole stack falls down. > Screwing up can occur because of omission (fact being written with a "1", > not "1N", and not being tested with large inputs), or by design. It can already happen: a l

Re: working with agents and atoms - a beginner question

2010-06-16 Thread Christophe Grand
On Wed, Jun 16, 2010 at 10:20 PM, Meikel Brandmeyer wrote: > The typical solution for your problem would probably be: > > (->> long-running-function-with-recur Thread. .start) > > This starts you function in a dedicated thread and you can save the overhead > of send-off and use recur directly. I'

Re: working with agents and atoms - a beginner question

2010-06-15 Thread Christophe Grand
Hi Ryan, On Tue, Jun 15, 2010 at 6:01 PM, Ryan Waters wrote: > I'm working with the code at the following gist and also pasted below: > > http://gist.github.com/421550 > > I'd like to have execution of a separate thread (agent) continue > running until it sees the atom 'running' change to false.

Re: Requesting Feedback on new Relational Mapping lib for Clojure

2010-06-15 Thread Christophe Grand
Hi Brenton, It's nice to see someone writing a relational mapper. I never got farther than pondering on API design but I share my design thoughts in case it can be useful to you: * relations (tables/views/joins) would be a reference type (when dereferenced they would return a seq or set of maps),

Re: if you have submitted an Assembla ticket...

2010-06-03 Thread Christophe Grand
Stu, #358 is marked as fixed but this bug occurs for other loength of transient vectors (see my 2nd patch for fix and test). Christophe On Thu, Jun 3, 2010 at 4:58 PM, Stuart Halloway wrote: > Hi all, > > I am trying to close out important tickets prior to the 1.2 beta release. If > you have s

Re: reacting to an article on clojure protocols, ruby monkey patching, and safety

2010-06-03 Thread Christophe Grand
On Thu, Jun 3, 2010 at 1:56 PM, Laurent PETIT wrote: > If I understand things well, one problem with ruby monkey patching is that > if a library I use opens a class C and adds a method whose signature is M to > it, and if in my own code I also open the same class C and add a method > whose signatu

  1   2   3   4   5   >