Re: question about a macro

2012-04-20 Thread nicolas.o...@gmail.com
Part of the problem is that you confuse compile time and runtime. Macro are evaluated at compile-time. So when you write: (my-macro SomeClass. a b) , my-macro can't access the runtime value of a and b. So if you want your second example to work, you need flatten to be called at runtime and not

Re: question about a macro

2012-04-20 Thread nicolas.o...@gmail.com
On Fri, Apr 20, 2012 at 11:14 AM, Marc Limotte wrote: > Thomas, > > Try this: > > (defmacro my-macro2 [func & args] `(~func ~@(flatten (eval (vec args) > > This won't work for: (let [a [2 3]] (my-macro2 SomeClass. a)) -- You received this message because you are subscribed to the Google Gr

Re: Newbie question about rebinding local variables

2012-04-20 Thread nicolas.o...@gmail.com
This is not the idiomatic way but you can stay quite close from your code by: (defn game [ board ] (fn [n i] (cond (= n :x) (game (assoc board i 'x)) ( = n :o) (game (assoc board i 'o)) (= n :print) (println board (defn (new-game (game (in

Re: Reducers

2012-05-09 Thread nicolas.o...@gmail.com
It looks very good. Just a few side-notes: - this representation is quite well known, as it is the Church encoding of list, often used in System F, for example. It corresponds to stating the definition of sequences as the initial algebra of F A = 1 + Any x A. - you can play a dual trick for S

Re: Reducers

2012-05-09 Thread nicolas.o...@gmail.com
On Wed, May 9, 2012 at 1:00 PM, Rich Hickey wrote: > This analogy is not quite right. > >> (fn [n] (vector n (+ n 1)) > > is not a reducing fn. Tt is a cons cell builder, and the Church encoding > builds lists. > It is because I did not write it in the right way. Sorry about that. It can be made

Re: code as data vs. code injection vulnerability

2012-05-09 Thread nicolas.o...@gmail.com
On Wed, May 9, 2012 at 5:01 PM, Rostislav Svoboda wrote: > On 9 May 2012 17:31, Tassilo Horn wrote: >> you should bind *read-eval* to false when reading data from unknown sources. > > This is the point! On one hand I need to evaluate data from a client > on the other hand I'd like to filter out t

Re: Reducers

2012-05-10 Thread nicolas.o...@gmail.com
I can describe the background to understand my last email. >From the programming point of view, I have been told since yesterday that what I explained has already been explained better in "Stream Fusion From Lists to Streams to Nothing at All" from Coutts Leschinskiy and Stewart: metagraph.org/pa

Re: Reducers

2012-05-11 Thread nicolas.o...@gmail.com
On Fri, May 11, 2012 at 12:47 AM, Rich Hickey wrote: > IMO, Nicolas' material is a distraction in understanding reducers, except as > historical background. I perfectly agree. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, s

Iteration or reduction on a transient map

2012-05-16 Thread nicolas.o...@gmail.com
Dear all, Is there a way to apply a function to all members of a transient map? Best regards, Nicolas. -- 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 a

Re: Iteration or reduction on a transient map

2012-05-16 Thread nicolas.o...@gmail.com
So, if I have a transient and want to reduce it and then continue to use it transiently, I need to call persistent!, reduce and transient again. Is there a reason for that? (The documentation says that read operation are allowed. And it is actually possible to write a reduce for a transient vecto

Re: Clojure Bee iPhone app updated

2012-05-17 Thread nicolas.o...@gmail.com
Any android port in the pipeline? -- 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 unsubscribe fr

Re: Let over Lambda

2012-05-18 Thread nicolas.o...@gmail.com
LoL is a good book. Very entertaining, even if part of the content is debatable. (It is a very opiniated book) Reading it after On Lisp could be a good idea, as there are a few references from LoL to On Lisp. http://www.paulgraham.com/onlisp.html The book is definitely a good read, makes you think

Re: Avoid duplicate computation in commute?

2012-05-18 Thread nicolas.o...@gmail.com
I think part of the problem is that commute should not return any result. You are not sure this is actually the value that will be returned, this is costly and misleading. There should be at least a variant of commute that return nil. -- You received this message because you are subscribed to th

Re: defrecord with "inheritance"

2012-05-20 Thread nicolas.o...@gmail.com
> (extend Employee >         AProtocol >         (merge default-implementation {:new-function (fn ...)})) > But you lose a bit of performance with that... -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@go

Re: defrecord with "inheritance"

2012-05-20 Thread nicolas.o...@gmail.com
I had wished such a feature all week. You don't need it often, but when you need it, it is really annoying to circumvent. traits would really be useful. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googl

Re: defrecord with "inheritance"

2012-05-20 Thread nicolas.o...@gmail.com
> So I suggest you take it to heart.  Put deftype, defrecord and defprotocol > away and don't pull them back out for quite some time.  At the beginning, > they are just a distraction from Clojure's core philosophy.  Focus on maps, > vectors, sets, functions, multimethods and macros. But there are

Re: defrecord with "inheritance"

2012-05-21 Thread nicolas.o...@gmail.com
> > Have you actually looked at the data structure implementations in > ClojureScript? The work is done. It's all protocols. > Hi David, I just have. This is a nice work. There is a lot of repetitions though. For example: - IEquiv (-equiv [coll other] (equiv-sequential coll other)) - IHash

Re: defrecord with "inheritance"

2012-05-21 Thread nicolas.o...@gmail.com
> > And now any of those implementations can easily change at anytime without > any external considerations. So what's the problem? Well if you want to amend all of them at the same time, you have to modify all of them. On your advice of using extend-type: maybe I am wrong but I think it has a pe

Re: defrecord with "inheritance"

2012-05-21 Thread nicolas.o...@gmail.com
> Same here--I can count on one hand the number of times I've wanted to > implement polymorphism in three and a half years. Every time > multimethods have worked great for the task. If you had polymorphism > in a tight loop they might not suffice, but the decision to abandon > multimethods should o

Re: defrecord with "inheritance"

2012-05-21 Thread nicolas.o...@gmail.com
>> On the other hand, defrecord/deftype encourage you to write your protocol >> implementation in a way that cannot be reused unless you very specifically >> plan for it (factoring the protocol implementation into a separate map) and >> use a coding style that (might?) be less efficient (i.e., addi

Re: defrecord with "inheritance"

2012-05-22 Thread nicolas.o...@gmail.com
> Everyone just reiterates the mantra “It's slower! It's slower! It's > slower!”, but no one talks about the trade-offs. And I bet only a very > small fraction ever checked what “slower” means in their specific use > case. I think the whole thread is about the trade-off: some people complains that

Re: defrecord with "inheritance"

2012-05-22 Thread nicolas.o...@gmail.com
> The only exception is mutable fields in the type where you don't want uncontrolled access. There you indeed need a protocol to handle the synchronisation of the field access. > > And then you need to include everything accessing the internal state of your data structures in a big deftype with lit

Re: defrecord with "inheritance"

2012-05-22 Thread nicolas.o...@gmail.com
> > Access internal state? >> Like __hash in your code. >> For example, the earlier hash example cannot be put as an extension. > > Why should most extensions manipulate mutable fields? > Most certainly won't. Now none of them can. -- You received this message because you are subscribed to the

Recursive lets

2012-05-29 Thread nicolas.o...@gmail.com
Dear all, Is there a way to write something like: (let [x (foo1 (fn [] (bar y))) y (foo2 x)] ) where the y on line 1 refers to y in line 2? I currently use an atom and an affectation to "tie the loop"... Best, Nicolas. -- You received this message because you are subscribed to

Re: Recursive lets

2012-05-30 Thread nicolas.o...@gmail.com
> I agree with the other commenters that letfn is good when you can use > it, but here you can't use it. Your general approach is really the > best you can do, though it's nicer to use promise/deliver than atom/ > swap!, since these values are never going to change again. I was looking for somethi

Re: CRUD application backed only by immutable facts

2012-06-05 Thread nicolas.o...@gmail.com
It is not totally clear in your post how you want to keep the data? Is it in memory (with a transactional log somewhere)? If it is the case, you can do better than reducing the whole data set when executing a query: you can keep a cache of query results, or indexed data and maintain it, while still

Re: Slow 'quick sort'

2012-06-08 Thread nicolas.o...@gmail.com
Stack-overflows in quicksort can mean that you are hitting the worst case of this algorithm complexity. (Meaning that you are sorting an array already sorted in one direction or the other. In this situation, the size of the recursive call are n - 1 and 0, instead of being roughly n/2 for both calls

Re: If a protocol creates a Java interface under the covers...

2012-06-13 Thread nicolas.o...@gmail.com
that mutation inside piece is > the only non-functional  detail...everything else I am indeed returning new > boards, new pieces (promotion, death etc)... > If I were you, I would look into a way to make Pieces pure too. Because their mutability cascades into the whole state and makes the descript

Re: If a protocol creates a Java interface under the covers...

2012-06-13 Thread nicolas.o...@gmail.com
On Wed, Jun 13, 2012 at 10:46 AM, nicolas.o...@gmail.com wrote: > that mutation inside piece is >> the only non-functional  detail...everything else I am indeed returning new >> boards, new pieces (promotion, death etc)... >> > And from what I understand of your design,

Re: If a protocol creates a Java interface under the covers...

2012-06-13 Thread nicolas.o...@gmail.com
> different positions now or some are nil (dead))... if i make the pieces pure > what comes to mind is resetting or swapping possibly 32 atoms instead.. No, you will have an atom containing a new board with new pieces in their new position. (By the way, you can go a long way writing what you want

Re: If a protocol creates a Java interface under the covers...

2012-06-13 Thread nicolas.o...@gmail.com
> you mean making 32 new pieces after each move regardless of whether they > moved or not? how can I identify the ones that are different from the ones > that remain unchanged so i can conj them in a new list? move will eventually > call 'build-board' which has to look somewhere for the current pie

Re: If a protocol creates a Java interface under the covers...

2012-06-14 Thread nicolas.o...@gmail.com
> (defn move > "The function responsible for moving Pieces. Each piece knows how to move > itself. If trying? is true, there will be no histiry of the new state of the > board. Returns the new board." >  ^clojure.lang.PersistentVector > [game mappings p coords] > {:pre [(satisfies? Piece p)]}  ;saf

Re: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-14 Thread nicolas.o...@gmail.com
>> (defmacro in? >> "Returns true if colle contains elm, false otherwise." >> [colle elm] >> `(if (some #{~elm} ~colle) true false)) Yes. Should not be a macro. (There is no reason for it to be a macro). On top of that, it is not very often useful to convert nil to false as clojure understands n

Re: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-14 Thread nicolas.o...@gmail.com
On Thu, Jun 14, 2012 at 6:19 PM, Jim - FooBar(); wrote: > I don't see why not if you really really need to return true/false... > Because it can be written as a function. Macro are only for things that cannot be easily written as functions. (And then it should be backed by functions that are usa

Re: Is there a reason why 'some' returns "nil" instead o "false"?

2012-06-14 Thread nicolas.o...@gmail.com
> > >> why add the extra overhead of potentially boxing/unboxing x in such a > simple case? Its not like the macro is getting out of control...Its a one > liner... > > Because functions are first class and not macros. Ex: (map to-bool l) -- You received this message because you are subscribed to

Re: reduction to tail recursion

2012-07-23 Thread nicolas.o...@gmail.com
Yes. For example, you can have a look at CPS transformation. If you want tail recursion and not tail calls, you can add trampolining to the mix. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroup

Re: reduction to tail recursion

2012-07-24 Thread nicolas.o...@gmail.com
On Mon, Jul 23, 2012 at 3:14 PM, Mimmo Cosenza wrote: > hi Merek and thanks for the link. But it does not answer my question. > I was looking for a demonstration of the reducibility of (not tail) > recursion to tail recursion. Or there is a demonstration of that, or nobody > could say that a (not

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-27 Thread nicolas.o...@gmail.com
Hi, Great notes. I like a lot. A few (mostly technical) comments: > Concept of Computation > > What does it mean to compute? Turns out this is a complicated question. From > what I can tell, to compute is an actualization (or concrete version) of a > mathematical function. We are swimming in a

Re: Transitioning an App from Java to Clojure (Notes of a Talk)

2012-07-28 Thread nicolas.o...@gmail.com
> There is indeed an infinite number of functions, or relationships between > natural numbers. I don't think that means that that any one of those > relationships is not computable because it is within the range of infinite > functions. The countable parts of a program can still accept an infinite

Re:

2012-07-30 Thread nicolas.o...@gmail.com
Another one. (The exception is for early termination) (def found! (Exception.)) (defn has22 [l] (try (reduce #(and (= 2 %2) (or (not %1) (throw found!))) false l) false (catch Exception e true))) -- You received this message because you are subscribed to

Re:

2012-07-31 Thread nicolas.o...@gmail.com
> The technique, using throw an Exception when succeeded in searching, strikes > me! You can make it less ugly with a bit of library: user> (deftype EarlyExit [result]) user.EarlyExit user> (defn early-exit [x] (EarlyExit. x)) user> (defn reduce-with-early-exit [f acc coll] (if (insta

Re: record constructor

2012-08-05 Thread nicolas.o...@gmail.com
Constructors are not a good idea, because they tie the functionality to the implementation. You want to be able to change your record to something else without changing your client code. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to thi

Re: function calling itself using a generic self reference call?

2012-08-06 Thread nicolas.o...@gmail.com
(defn recurse [f] (fn [& args] (apply f (recurse f) args))) (def fac (recurse (fn [self n] (if (zero? n) 1 (* n (self (dec n))) There is a performance cost. recursive can be specialised on different number of arguments, to reduce this cost.

Re: record constructor

2012-08-06 Thread nicolas.o...@gmail.com
> My answer to this is: everything is an implementation at some level. So do > you think we need factory functions of factory functions, and factory > functions of factory functions of factory functions? I am sure that will be > more flexible than just one level of factory functions. We already ha

Re: record constructor

2012-08-07 Thread nicolas.o...@gmail.com
> (defrecord MyRecord [x y z] > (make-record [arg1 arg2 arg3 ...] ...)) > > (make-record MyRecord arg1 arg2 arg3 ...) This construct is not very good. make-record is not first-class (It cannot be used as an argument to a function). Its first argument is not first-class (it has to be statically t

Re: basic question , clojure io

2012-08-08 Thread nicolas.o...@gmail.com
There is no such thing in Clojure. Separation of IO and non IO is done by: - encouraging pure functions - providing very good pure data structures, and libraries -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clo

Re: Attractive examples of function-generating functions

2012-08-08 Thread nicolas.o...@gmail.com
trampolines is a slightly different example. -- 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 uns

Re: How to measure pieces of Clojure code?

2012-08-11 Thread nicolas.o...@gmail.com
Visualvm is quite nice and simple to use. On 10 Aug 2012 23:21, "Hussein B." wrote: > Hi, > I want to measure how much space an algorithm is taking and then trying to > change some aspects to see how things are going to differ. > I also want to measure how much time it takes to complete an operat

Re: recursion question

2012-08-15 Thread nicolas.o...@gmail.com
First solution: (defn groupSum [l x] (or (zero? x) ; we have won! (and (not (< x 0)) ; we can't win (not (empty? l)) ; lost! (or (groupSum (rest l) (- x (first l))) (recur (rest l) x) The "we

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
> > How do I construct a combining fn out of 'max-key' and is there an idiom or > a pattern for doing so? You might use the fact that -Infinity is a neutral element for max. (Or the smallest long if you work with longs). Alternatively you can represent your value as either a number or nil, nil bei

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
Hi Jim, I tried a bit. The performance of this is not perfect but seems not horrible. It can do a level 5 exploration in 11 sec on my computer, with a branching factor of 30. (Of course, there is very little computation for the next move.) The generation is now lazy, but the depth is used in the e

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
By the way, I just found an obvious bug in that code, but that should be easy to correct. (if (= res Double/NEGATIVE_INFINITY) (evaluate (:board tree)) res This is obviously wrong. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
> > thanks a lot Nicolas...I'll definitely play around with your code tomorrow > morning...if you say you can go up to level 5 in 11 sec this is really good > performance -I can't wait to explore the code...I'll let you know of any > comments of mine soon! > > Of course, don't trust this code. I ha

Re: help needed to use reducers and monoid

2012-08-19 Thread nicolas.o...@gmail.com
A correction for the wrong part: (defn my-max ([x y] (if (nil? x) y (if (nil? y) x (max x y ([] nil)) (defn tree-value ^double [tree evaluate ^long depth] (let [children (:children tree)] (if (or (zero? depth)) (evaluate (:board t

Re: help needed to use reducers and monoid

2012-08-20 Thread nicolas.o...@gmail.com
(defn generate [board next-boards] ;; next-boards return a seq of MoveAndBoard (BoardAndChildren. board (r/map (fn [m] (MoveAndTree. (:move m) (generate (:board m) next

What is the meaning of :while in a for ?

2012-08-21 Thread nicolas.o...@gmail.com
Dear all, What is the meaning of :while in a for? I understand :when, and also that :while jumps more element when the condition is not met, but where does it jump to exactly? Best regards, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. T

Re: What is the meaning of :while in a for ?

2012-08-21 Thread nicolas.o...@gmail.com
I understand now. The documentation could be clearer on that. Your triangular example is very clear. -- 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 mod

Re: real-world usage of reducers?

2012-08-22 Thread nicolas.o...@gmail.com
Hi, 3 questions: 1. Are you sure your moves list at the op level is in a vector? Looking at the code for reducers, it seems that it is the only implementation actually doing concurrency. 2. The default block size for spawning a new thread is 512. Meaning that if you have less than 512 first m

Re: real-world usage of reducers?

2012-08-22 Thread nicolas.o...@gmail.com
Sorry, I forgot to convert to a vector: (defn best-move "Start folding here." [dir b d] (r/fold 1 best best (r/map #(Move-Value. (:move %) (search score-by-count (:tree %) d)) (into [] (:children (game-tree dir b next-level)) -- You received this

Re: Folding a reducer inside of a fold

2012-08-22 Thread nicolas.o...@gmail.com
> In particular, if I attempt to replace the `r/reduce` call on line #23, > with a call to `r/fold`, I get the following crash: > This calss sems strange. remaining? should represent a monoid for it to work. Meaning two functions: 1 -> A and (A -> A -> A) In your code, the case with no arg return

Re: real-world usage of reducers?

2012-08-22 Thread nicolas.o...@gmail.com
On Wed, Aug 22, 2012 at 1:53 PM, Jim - FooBar(); wrote: > Ok, so I followed your suggestions and the block size did the trick with > regards to using all 4 cores of mine...However, even so, I get no > performance improvements!!! It still needs close to 4 min to go to level 4 > and it still needs 5

Re: real-world usage of reducers?

2012-08-22 Thread nicolas.o...@gmail.com
> I'm really sorry but I don't follow...I'm only doing (:value best) or > (:value next). best or next return a Move-Value (it has :move and :value > keys) where the :value key could be Integer/MIN_VALUE - I'm not doing > (:value Integer/MIN_VALUE) anywhere... Then you want to write: (defn best ([]

Re: real-world usage of reducers?

2012-08-22 Thread nicolas.o...@gmail.com
You should replace your functions that computes the board by function that does return 30 times the same board. And evaluation function by something that returns a constant value. And check : speed and speed-up for folding. Then you will know for sure whether the slowness comes from the explore an

Re: What is the meaning of :while in a for ?

2012-08-22 Thread nicolas.o...@gmail.com
= On Tue, Aug 21, 2012 at 11:50 AM, Arie van Wingerden wrote: > Extra restrictions on (range of values of) variables used in the for. > See here: > http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/for > The link says nothing about the meaning of the modifiers. (I agree it shoul

Re: real-world usage of reducers?

2012-08-23 Thread nicolas.o...@gmail.com
If it is so slow, that's maybe because the branching factor is very high. Could you have an atom incremented in your evaluation function, or in next level, to check how many boards are generated for level 2 or 3? (At least this could give an approximate time for computing each board. (83 - 8) / num

Re: What is the meaning of :while in a for ?

2012-08-23 Thread nicolas.o...@gmail.com
gt; Note: Anyone with a free account can add/edit examples on that site. > > Andy > > On Aug 21, 2012, at 8:34 AM, nicolas.o...@gmail.com wrote: > >> I understand now. >> The documentation could be clearer on that. >> Your triangular example is very clear. > > -- &

Re: real-world usage of reducers?

2012-08-24 Thread nicolas.o...@gmail.com
More optimsation ideas: > (defn next-level [b dir] > > (r/map #(Move->Board. % (core/try-move %)) > (core/team-moves @curr-game b dir))) ;;curr-game is a promise > (definline team-moves > [game b dir] > `(let [team# (gather-team ~b ~dir) >tmvs# (r/mapcat (fn [p#] (r/ma

Performance of concatenating two vectors

2012-08-24 Thread nicolas.o...@gmail.com
Dear all, After reading this: http://infoscience.epfl.ch/record/169879/files/RMTrees.pdf I was wondering what was the current performance characteristics of the different ways to concatenate arrays in clojure? Best regards, Nicolas. -- You received this message because you are subscribed to

Re: profiler help...

2012-08-24 Thread nicolas.o...@gmail.com
> (and creates vectors via (into [] (r/map ))) Depending of your method of scoring, you could try to do it just with a reducer. (Without creating a vector with it). If your code does not spend its time in GC (can be seen in the first pane), CPU sampling might be a better place to look. --

Re: profiler help...

2012-08-24 Thread nicolas.o...@gmail.com
> (defn score-by-count ^long [b dir] > (let [ hm (into [] (core/gather-team b dir)) >aw (into [] (core/gather-team b (unchecked-negate dir)))] > (unchecked-subtract (count hm) > (count aw > (defn counting-accumulator [acc _] (inc acc)) (defn score-by-count ^lo

Re: problem 58 on 4clojure

2012-08-25 Thread nicolas.o...@gmail.com
Here's my take: We want to define a function my-comp. It takes n functions and return their composition. We want to return a function of any number of arguments, so let's start by working with a given set of argument args, and returning the value of the composition applied to those arguments. - I

Re: A Performance Comparison of SBCL & Clojure

2012-08-26 Thread nicolas.o...@gmail.com
On Sun, Aug 26, 2012 at 3:07 PM, David Nolen wrote: > I haven't found this to be the case. Java fares pretty well on Alioth. http://shootout.alioth.debian.org/help.php#java Shows that it does not change much on programs that run for mor than a few seconds. -- You received this message because

Re: 'functional' performance VS 'imperative' complexity

2012-08-26 Thread nicolas.o...@gmail.com
> > 1. Gary Bernhardt has been playing with a "new" approach he calls > "Functional Core, Imperative Shell". Essentially, it's another take on > the question of how to limit the scope of mutation in order to get the > most out of the correctness of mutation-free algorithms and the > performance of

Re: how to translate this snippet from Scheme to Clojure

2012-08-31 Thread nicolas.o...@gmail.com
It is quite easy to write a macro define in clojure that does that: (defmacro define [head & body] (if (sequential? head) `(define ~(first head) (fn [ ~@(rest head)] ~@body)) `(def ~head ~@body))) (define ((A [p1 p2]) [p3 p4]) [p2 p4])) ((A [1 2]) [3 4]) => [2 4] -- You recei

Re: quick question about #'

2012-09-02 Thread nicolas.o...@gmail.com
I tend to like 1 better. I do not like working with vars without a good reason. -- 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 pa

Re: Clojure : a good start for non-programmers?

2012-09-26 Thread nicolas.o...@gmail.com
Clojure is a good language to start. The only thing is that there are more ressource for beginners in other languages. For Racket (another Lisp), you have the very good: How to design programs. http://www.ccs.neu.edu/home/matthias/HtDP2e/ (this is the second edition, you might have to peak in th

Re: Does Clojure support efficient coroutines?

2012-09-26 Thread nicolas.o...@gmail.com
No continuations or coroutines support on the JVM, as far as I know. However, there are a few monad libraries for clojure with which you would probably be able to do what you want. (Using the continuation monad...) http://www.intensivesystems.net/tutorials/monads_101.html , for example. Delimited

Re: Does Clojure support efficient coroutines?

2012-09-27 Thread nicolas.o...@gmail.com
Depending of the code they have to write, you can walk their code at compile time and transform it to monadic normal form or CPS style, which would allow to do what you want. I would tend to think that with a lot of threads you will win with closures and not native threads. And would only a few th

Re: best practices for small RAM usage

2012-10-04 Thread nicolas.o...@gmail.com
You have 2 distinct problems: - allocating many short-lived objects. It can affect performance but does not matter for long-term memory occupation - keeping too many things in memory. Then you have to resolve an algorithmic question, quite independent of the technology you use. On Wed, Oct 3,

Re: Is game development Clojure(functional in general) friendly?

2012-10-30 Thread nicolas.o...@gmail.com
The usual approach to this kind of things is to have a Functional representation of the world, that contains the game logic. To have pure functions that modifies the world with the time and inputs of players. And everytime you want to render a frame to call a render function that does all the work.

Re: monads

2012-10-30 Thread nicolas.o...@gmail.com
In a few lines: Monads are a common framework to represent any sequential computation. What is a sequential computation? - either no computation at all. return :: a -> m a does that. - or I have already a computation and want to go on with my computation. But then, I need to be able to look

Re: About code help: is it ok to ask for how to improve?

2012-10-30 Thread nicolas.o...@gmail.com
I would think so. But to maximise your chances of getting useful help, it is often better to post small pieces of codes and explain what you are trying to achieve with them. Best, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to

Re: Simple loop in Clojure is ~15 times slower than in Java

2010-10-18 Thread nicolas.o...@gmail.com
I happened to stumble on something like that in 1.2, with = slower than >=, which is in turn slower than zero?. (Even when everything is a primitive) I never really understood why and would be happy to understand it better. Dimitry, have you tryed to replace (= x y) by (zero? (- x u)), or with an

Re: Simple loop in Clojure is ~15 times slower than in Java

2010-10-18 Thread nicolas.o...@gmail.com
You can try == for numbers -- 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 unsubscribe from this

Re: Clojure performance on shootout

2010-10-26 Thread nicolas.o...@gmail.com
Maybe optimizing now is a bit early, as a lot of the performance caracteristics of clojure programs will change with 1.3. Might be better to start writing programs that will be fast with 1.3. On Tue, Oct 26, 2010 at 9:46 AM, Marko Kocić wrote: > Clojure has recently been added to http://shootout

Re: creating a function from a sexp

2010-10-27 Thread nicolas.o...@gmail.com
You need to use both eval and a macro to get then environment. I think &env contains the lexical environment in any macro call now. (I don't know in each form though). So you need to walk the term, looking for free variables, close under free variables by creating a function and then call eval. Th

Re: apply an higher order function on an arbitrary nested data structure

2010-10-28 Thread nicolas.o...@gmail.com
Functor's fmap in Haskell is passed where to apply the function as an (hidden in the type class dictionary) argument. You would need somehow to be more specific about where you want to apply your function in the data-structure. (On predefined position, a la Functor, or on every leaf, with a defini

Re: monads m-seq and m-lift

2010-11-02 Thread nicolas.o...@gmail.com
As I understand it, m-seq is transforms a list of monadic computation into a computation returning the list of result. The resulting computation just sequentially does every computationin the sequence and keep the result. It is useful when the arity is not known at runtime foir example. On Tue,

Re: A question on distributed computing

2010-11-03 Thread nicolas.o...@gmail.com
Some things are certainly possible. It depends whether you consider all computers to be friendly of some of them to be evil. If all of them are friendly, you can annotate your data by permissions. Else, you need either to check what you send to other computers, or crypt with different keys. --

Re: Some questions about Clojure Protocols

2010-11-03 Thread nicolas.o...@gmail.com
On Wed, Nov 3, 2010 at 10:32 AM, ka wrote: > 1.  How to combine protocols? > AFAIK, it is not possible. You must implement all the different protocols. It might look desapointing, but on the other hand it is not necessary. (As there is no static typing in Clojure) What is your use-case? > 2. Do

Re: A suggestion for the next Conj

2010-11-03 Thread nicolas.o...@gmail.com
Very fast 3 minutes talk could be fun too. Name, nicknames, and what you are using Clojure for. No slides of course. Best, Nicolas. -- 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 t

Re: Some questions about Clojure Protocols

2010-11-04 Thread nicolas.o...@gmail.com
I see your point. Somehow, it is annoying to have to manipulate a set of protocols that always go together. And it would be nice to have a shorthand. I have a very small prototype here: git://nicolasoury.repositoryhosting.com/nicolasoury/type-classes.git of some code to allow "type-classes" like

swank-clojure and clojure 1.3

2010-11-05 Thread nicolas.o...@gmail.com
Dear all, Currently swank-clojure SNAPSHOT does not show the stack, nor the exception, on some uncaught exception. Is it something I can do to inspect the errors? Best, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group

Re: Why isn't there a fold-right?

2010-11-07 Thread nicolas.o...@gmail.com
On Sun, Nov 7, 2010 at 3:28 PM, iko...@gmail.com wrote: > 2010/11/7 David Sletten >> >> Or for those of you who prefer that other people won't be able to read >> your code: >> (defn foldr [f coll] >>  (reduce #(f %2 %1) (reverse coll))) >> > fold-right can not be made tail-recursive and in one-p

Re: macroexpand

2010-11-09 Thread nicolas.o...@gmail.com
If you want that, you don't need macro. (defn bench [f] (let [start ... result (f)] ; note the call to f )) But you would have to call it with: (bench #(expr)) or (bench (fn [] expr)) You cannot do it directly because it would evaluate expr before the call to bench. This one

Re: macroexpand

2010-11-09 Thread nicolas.o...@gmail.com
Last point: on very fast bench, the time of a function call is not negligeable. -- 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 pa

Re: macroexpand

2010-11-09 Thread nicolas.o...@gmail.com
Sorry. Last line should read: (defmacro bench [expr] `(bench-fn (fn [] ~expr))) On Tue, Nov 9, 2010 at 1:06 PM, nicolas.o...@gmail.com wrote: > If you want that, you don't need macro. > > (defn bench [f] >  (let [start ... >        result (f)] ; note the call to f >

Re: Find all ties in a sorted list

2010-11-11 Thread nicolas.o...@gmail.com
A solution based on unfold with the last element read (or initially nil) and the rest of the list as a seed. On Thu, Nov 11, 2010 at 12:12 AM, David Jacobs wrote: > Thanks for all of the options, and Ken, thanks for the detailed comparison. > This will be extremely useful. (I'm trying to port so

Re: Incorrect behaviour for large s-expressions :(

2010-11-14 Thread nicolas.o...@gmail.com
JVMs has a strange limitation for the size of methods. I don't know if there is a plan to solve that on the JVM side. It is quite hard to solve that on the compiler side. When I bumped inot this (once for an ICFP contest), I rewrote a macro so that it emitted smaller methods called from a big meth

Re: Incorrect behaviour for large s-expressions :(

2010-11-14 Thread nicolas.o...@gmail.com
> I believe the underlying problem is a limit of the JVM.  Maybe it > would be possible for the Clojure compiler to work around the > limitation, though. It has a non trivial interaction with the lack of TCO. The trivial transformation of going from a big method to a sequence of small methods coul

  1   2   >