Re: (ab)using STM for longish calculations, network I/O

2010-10-15 Thread Nicolas Oury
dosync is a way of ensuring whole stateful operation is done atomically. (ie as if everything was happening in one step.) That contradicts b). During a whole dosync, you can only see one state of the world. If you do not need atomicity, do multiple dosync. You should create another abstraction fo

Re: generator in Clojure

2010-10-14 Thread Nicolas Oury
(defn iterate [s] (let [a (atom s)] (fn [] (let [s @a] (reset! a (next s)) (first s)) but it's not very idiomatic in clojure. (In Lisp it is traditional to hide a state in a closure. A lot of toy object language work like that) On Thu, Oct 14, 2010 at 9:38

Re: precise numbers

2010-10-14 Thread Nicolas Oury
Another proof: Let study the sequence sn = 0....9 , with n 9s. Or s0= 0 and s(n+1) = sn + 9 / 10 ^n lim sn = 0.9... and lim sn = 1. so If I remember my meth correctly, the number 0... does not exist. This not a legal decimal sequence. (Any decimal sequence finishing b

Re: precise numbers

2010-10-13 Thread Nicolas Oury
On Tue, Oct 12, 2010 at 8:35 PM, cej38 wrote: > The more that I think about it, the more I would rather have a set of > equalities that always work.  float= was a good try. > > The only way to do so is to have numbers with infinite precision. For example as lazy-seq of their digits. But: - it i

Re: precise numbers

2010-10-12 Thread Nicolas Oury
If you want to be really precise, most real numbers are an infinite number of decimals. If you encode them as a lazy seq of decimals, + - and other ops are doable. Comparison is semi-decidable only: it terminates only in certain case (finite number of decimals) or when the number are different. b

Re: clojure-cake

2010-10-08 Thread Nicolas Oury
I had a similar error last time I tried. Didn't manage to solve it. On Fri, Oct 8, 2010 at 10:49 AM, Sunil S Nandihalli wrote: > I forgot to mention the versions... > My cake version is "0.4.18" > and ruby version is "ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]" > On Fri, Oct 8, 2010 at 3

Re: Clojure 1.3 alpha 1 report - bitwise operations extremely slow

2010-10-01 Thread Nicolas Oury
> David pointed out what should have been the obvious overhead (I'll > blame it on being up at 2am), and Nicolas pointed out the specific > problem. two solutions: - writing all combinations of unboxed/boxed for every function - having a more clever code generator that try to box every primiti

Re: Clojure 1.3 alpha 1 report - bitwise operations extremely slow

2010-10-01 Thread Nicolas Oury
There is no java definition for (Number, long) or (Number, int). As 1 is now a primitive, I think it cannot find any corresponding function. Strangely, putting 1M or (num 1) might be faster. Can someone try? On Fri, Oct 1, 2010 at 10:28 AM, David Powell wrote: > >> So, if it is true that rang

Re: anonymous fn or partial?

2010-09-30 Thread Nicolas Oury
> Note that you can't make readermacros yet. It's a supported in CL not > in Clojure but maybe in future versions how knows. I meant, if you want to modify Clojure to allow a shorter notation for partial application, it is better to add a reader macro (directly in Clojure) than to change evaluatio

Re: anonymous fn or partial?

2010-09-30 Thread Nicolas Oury
The two styles are ok. Matter of taste. (partial ...) have probably a slight cost I wouldn't worry about except if profiler tells me to worry. The (partial...) style is called point-less, because you directly manipulate the arrows and not the points. It is the same kind of question as : should yo

Re: How often do you use REPL?

2010-09-28 Thread Nicolas Oury
On Tue, Sep 28, 2010 at 12:03 PM, David Cabana wrote: > My standard practice is to split the (Emacs) screen, one side is a > Clojure mode edit session, the other a repl.  Best of both worlds. > One can easily build up complex expressions as required,  and still > easily evaluate expressions in eit

Re: question regarding macro (ab)usage

2010-09-28 Thread Nicolas Oury
I hadn't time to read the whole post, but, I I understand it well, this snipset (defmacro with-context [options & body] `(let [context# (create-context options) thread# (create-thread context) sources# (atom {}) receivers# (atom {})] (binding [init-receiver (partial in

Re: Macro expansion problem

2010-09-27 Thread Nicolas Oury
Difficult problem. macro are syntactic tools. So they are not made to evaluate things at runtime. You could expand to something that call eval at runtime but it is not a good idea (It involves the compiler at each call) If your (rest alist) is known at macro-expansion time, then it can work but to

Re: Hiccup with Sequence

2010-09-27 Thread Nicolas Oury
doseq do not return anything. (It is for side-effect only). You might be looking for 'for'. (doc for) - clojure.core/for ([seq-exprs body-expr]) Macro List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more

Re: finding value nearest x

2010-09-25 Thread Nicolas Oury
On Sat, Sep 25, 2010 at 3:40 PM, Jules wrote: > Maybe this: (min-key #(abs (- % 136)) xs) > Wouldn't that be (apply min-key #(abs (- % 136)) xs)? -- 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: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Nicolas Oury
> Your code was simple enough for me to make a couple of educated guesses. For > more complex code I'd use VisualVM, https://visualvm.dev.java.net/ > David > I use that too. Sampling for a first look, profiling with instrumentation for a more precise answer. (Here, the sampling gives even? and th

Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-24 Thread Nicolas Oury
Try (defn even? "Returns true if n is even, throws an exception if n is not an integer" {:added "1.0" :static true} [n] (zero? (bit-and (long n) (long 1 before your example. It is fast on my computer. (I believe there is a reflective call, without the explicit cast.) -- You recei

Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-24 Thread Nicolas Oury
After profiling even seems effectively the culprit. Some method reflector shows up too. On Fri, Sep 24, 2010 at 6:15 PM, David Nolen wrote: > (defn next-term [n] >   (if (= (mod n 2) 0) (/ n 2) >       (inc (* n 3 > (defn count-terms [n] >   (if (= 1 n) 1 >       (inc (count-terms (next-term

Re: Isn't STM good at building an ant colony?

2010-09-20 Thread Nicolas Oury
If you have a fixed geometry of cells, it is quite easy to have one ref per cell. Which reduce a lot of contention. For example, on a grid where ant can go instead of representing the world as a ref to a matrix, you can represent the world as a matrix of refs. Those refs can then be update concur

Re: why the big difference in speed?

2010-09-19 Thread Nicolas Oury
A first good start is to put (set! *warn-on-relection* true) at the start of the file and removes all reflective access. Before the 1.3 release, function cannot receive/returns primitive so you might consider (defmacro next-gaussian [] `(.nextGaussian ^Random r)) (^Random is here to make sure

Re: Using macro to generate part of fn

2010-09-18 Thread Nicolas Oury
in a (def f [] E), only a E is going to be macro-expanded. (I think the rule of thumb is that macro are only expanded in a position where an expression is.) You can build : (defmacro macro-expanding-defn [name l] ) using a combination of macro-expand, defn and macro? (You can also do a simpler

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

2010-09-17 Thread Nicolas Oury
(defn unfold ([grow seed] (lazy-seq (if-let [[elt next-seed] (grow seed)] (cons elt (unfold grow next-seed) ([grow finished? seed] (unfold #(when (not (finished? %)) (grow %)) seed))) (unfold (fn [x] [(* x x) (inc x)]) #(> % 10) 0) (0 1 4 9 16 25 36 49 64 81 100) (unfol

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

2010-09-17 Thread Nicolas Oury
I was just saying that not returning something that is a pair, for example nil, is good enough. (unfold (fn [x] (when (<= x 10) [(* x x) (inc x)])) would work. Both function can be written with each other anyway. And they don't have the same number of args so they are compatible with each othe

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

2010-09-16 Thread Nicolas Oury
I think that unfold (or co-reduce, or generate) should find its way in contrib. I am not sure we need finished arg though. The traditional finish in the seq family is nil. My own version of unfold: (defn unfold "(unfold seed grow) use the seed and a function grow that returns an element and an

Re: Feature idea: meta-macros

2010-09-16 Thread Nicolas Oury
The logged function would have to be already a generic method, no? On Wed, Sep 15, 2010 at 7:50 PM, Matt Fowles wrote: > All~ > My clojure is fairly weak, but the particular example given would be > accomplished in common lisp using generic methods and the >  :around modifier... > http://www.aiai

Re: Feature idea: meta-macros

2010-09-15 Thread Nicolas Oury
You can also use binding eval evil brother : alter-var-root. On Wed, Sep 15, 2010 at 8:04 PM, Richard Newman wrote: > My suggestion is inline with other commenters: use binding. If that doesn't > satisfy you, consider using or writing a preprocessor like m4. > > -- > You received this message bec

Re: Feature idea: meta-macros

2010-09-15 Thread Nicolas Oury
Your example can be solved with (binding ...) For the proposal, I think it's a bad idea : huge potential for abuse (and importing abuse from other namespaces written by other people) and little benefit. I wouldn't be so strongly against it if it was in a delimited scope. In any case, you can pro

Re: why doesn't a function have a type ?

2010-09-14 Thread Nicolas Oury
On Tue, Sep 14, 2010 at 2:35 PM, Belun wrote: > why isn't the type of a function : clojure.lang.IFn ? > Actually you assume the existence of an unique type. In most OO-language, and Clojure inherits that from its host, an object has multiple types. Indeed an object can be seen as of type its clas

Re: clojurescript and 1.2.0

2010-09-13 Thread Nicolas Oury
Thanks for the link. Very interesting indeed. Didn't know about it. On Mon, Sep 13, 2010 at 11:38 AM, Daniel Werner wrote: > On Sep 13, 9:40 am, Nicolas Oury wrote: >> I switched to Parenscript for my small JS project, even if I's rather >> have used Clojure than CL

Re: clojurescript and 1.2.0

2010-09-13 Thread Nicolas Oury
2010 at 5:59 AM, Chouser wrote: > On Sun, Sep 12, 2010 at 9:04 AM, Nicolas Oury wrote: >> Oooops. >> >> Ansered my question. >> >> Haven't seen the patch in the git repository. >> Will try to apply it to clojure 1.2. > > I imagine you'll have

Re: clojurescript and 1.2.0

2010-09-12 Thread Nicolas Oury
Oooops. Ansered my question. Haven't seen the patch in the git repository. Will try to apply it to clojure 1.2. On Sun, Sep 12, 2010 at 1:52 PM, Nicolas Oury wrote: > Dear all, > > I cannot manage to make ClojureScript work from clojure 1.2.0. > > It seems that *compile

clojurescript and 1.2.0

2010-09-12 Thread Nicolas Oury
Dear all, I cannot manage to make ClojureScript work from clojure 1.2.0. It seems that *compiler-analyse-only* used to exist but do not exist anymore. Does someone know what it was and what replaced it? Best regards, Nicolas. -- You received this message because you are subscribed to the Goo

new in ClojureScript

2010-09-11 Thread Nicolas Oury
Dear all, I am trying to use ClojureScrip for fun. (FOr the REPL now). I can not find a translation to the javascript: var image = new Image(); (def image (Image.)) or (def image (new Image)) does not work. Any idea? Best regards, Nicolas. -- You received this message because you are subsc

Re: Generating functions programmatically

2010-09-11 Thread Nicolas Oury
> So the problem is solved for me, although I have to use eval. I'm not > sure exactly how dirty this trick is and especially *why* it is > considered a "smell". I read it on Paul Graham's "On Lisp" and he > vehemently opposes its use but he doesn't explain why or where it is > acceptable. Note tha

Re: Improved stack traces

2010-09-09 Thread Nicolas Oury
http://github.com/clojure/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 first post. To unsubscribe fr

Re: Knowing in advance the complexity of count

2010-09-09 Thread Nicolas Oury
; > On 9 Sep., 16:45, Nicolas Oury wrote: > >> is it a way to do so? > > You can check the Counted marker interface for clojure collections. > But this won't cover Strings etc. More information here: > http://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/

Knowing in advance the complexity of count

2010-09-09 Thread Nicolas Oury
Dear all, I want to write a generic code that use count when it is O(1) and not when it is not O(n), is it a way to do so? 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@googlegr

Re: Some Problem with Recursion

2010-09-09 Thread Nicolas Oury
re just returned. > This should lead to this final result: > > [2 4 +] > > However, no vector is returned, just the initial argument to the > function. > > I really want to understand what I did wrong here :-) > > Stefan > > > > On Sep 9, 9:08 pm, Nicolas

Re: Some Problem with Recursion

2010-09-09 Thread Nicolas Oury
Yes. Have someone (for example your editor), do your indentation for you. By typing on tab on a good editor, you would have has: (defn prefix->postfix [expr] (if (coll? expr) (let [ [op arg1 arg2] expr] [ (prefix->postfix arg1) (prefix->postfix arg2) op])) expr) which is easier

Re: can't def m-bind because namespace

2010-09-09 Thread Nicolas Oury
can always do without them. Best. Nicolas. On Wed, Sep 8, 2010 at 2:27 PM, MohanR wrote: > So actually it looks like I need to understand type theory to > understand this. > > > Thanks, > Mohan > > On Sep 7, 7:04 pm, Nicolas Oury wrote: >> > ...and report your f

Re: Strange bug with mutable fields and try

2010-09-08 Thread Nicolas Oury
On Wed, Sep 8, 2010 at 6:36 PM, Alan wrote: > Are you using the release version of 1.2.0? I get the behavior you > describe when I use a snapshot of 1.2.0 from when I built from source, > but when I use lein repl in a project with a dependency on 1.2.0, all > three forms fail with the same excepti

Strange bug with mutable fields and try

2010-09-08 Thread Nicolas Oury
Dear all, Clojure 1.2.0 (deftype A [ ^{:unsynchronized-mutable true} foo ] Object (hashCode [x] (set! foo :foo)

Re: can't def m-bind because namespace

2010-09-07 Thread Nicolas Oury
> ...and report your findings here or blog somewhere if you don't mind > :) I've been reading a lot about monads lately and can't get my head > around it yet so any help appreciated (I'm coming from Java and > Clojure is my first real functional language - that's why it causes > headaches, I believ

Re: can't def m-bind because namespace

2010-09-07 Thread Nicolas Oury
http://clojure.org/namespaces You should require clojure.contrib.monad and bot use it. (ns my-namespace (:require (clojure.contrib.monad :as m)) m/m-bind, for example. Then you can define your own m-bind without conflict with an existing one. On Tue, Sep 7, 2010 at 1:13 PM, MohanR wrote: > j

Re: Mapping a function to a map

2010-09-06 Thread Nicolas Oury
Different reactions: 1. The reduce solution is O(n .log n) + time of mapping elements, as inserting in a map is O(log n). A tree with n leafs and arity at least binary is of size at most 2n. So a map on a map could be done in O(n) + time of mapping elements, but it would need a bit of support fro

Mapping a function to a map

2010-09-06 Thread Nicolas Oury
Dear all, is there a function to map a function to all values in a map, keeping the same keys? Reducing from the seqed map seems a bit slower that what could be done directly... Best, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: How to use Java array of primitive types as key of Clojure map?

2010-09-01 Thread Nicolas Oury
Multiple things: the internal type name for int arrays is [I So you should try something like: (deftype T [^"[I" keys ] ) then you are looking to overload equals and hashCode from the Object interface (deftype T [^"[I" keys ] Object (equals [x other] (java.util.Arrays/equals key (.key othe

Re: reflection warnings with defprotocol/deftype with type hints

2010-09-01 Thread Nicolas Oury
> Clojure is a dynamically typed language. I don't think that putting > types on protocols is very interesting. Type hints should be a low- > level construct put into low-level functions when perfomance needs > dictate it. Otherwise type hints should be omitted. Clojure gives the > developer every

Re: Help speed up an inner loop?

2010-08-31 Thread Nicolas Oury
On Tue, Aug 31, 2010 at 8:43 PM, tsuraan wrote: > >> In this situation, inlining (int 10) does not buy much. > > interesting; for me replacing the 10 with (int 10) brings my times > from 28.7ms to 19.6ms. I meant putting (int 10) instead of nl and a let. Anyway, it seems that we can get to java

Re: Help speed up an inner loop?

2010-08-31 Thread Nicolas Oury
This one is quite good for me. (defn countnl [#^bytes buf] (let [nl (int 10)] (areduce buf idx count (int 0) (if (== (int (aget buf idx)) nl) (unchecked-inc count) count It appears that == is not resolved for bytes. So converting to int works fine.

Re: Help speed up an inner loop?

2010-08-31 Thread Nicolas Oury
Replace also (unchecked-add count 1) with (unchecked-add count (int 1)) (this should get easier in 1.3) On Tue, Aug 31, 2010 at 4:20 PM, tsuraan wrote: >> (defn countnl-lite >>  [#^bytes buf] >>  (areduce buf idx count (int 0) >>           (if (= (clojure.lang.RT/aget buf idx) 10) >>          

Re: Why do is used in this function?

2010-08-31 Thread Nicolas Oury
One solution to remove it is to use when. (when (not (empty? s) (println (str "Item: " (first s))) (recur (rest s As there is only one case for a when, you can give multiple instructions for this case without grouping them Even better: (when-not (empty? s) (println

Re: Help speed up an inner loop?

2010-08-31 Thread Nicolas Oury
On Tue, Aug 31, 2010 at 1:53 PM, Nicolas Oury wrote: > I am not convince that (make-array Byte/TYPE *numbytes*) creates an > array of primitives. Actually it does, sorry for the noise. Should check before sending emails. Best, Nicolas. -- You received this message because you are subs

Re: Help speed up an inner loop?

2010-08-31 Thread Nicolas Oury
I am not convince that (make-array Byte/TYPE *numbytes*) creates an array of primitives. And I think byte [] is an array of primitives. That would make a difference. I don't know if clojure has a byte-array. It seems that there is no byte-array as there is int-array. Could you try your code with

Is there a construct-hash macro?

2010-08-29 Thread Nicolas Oury
Dear all, when you write a deftype and want to define a hashCode method, it would be really great to have access to a macro (construct-hash arg1 argn) that would compute the hash code of each arguments and combine them in a good way to produce a hash-code. Is there anything like that in co

Re: Clojure 1.2 and the Computer Language Benchmarks Game

2010-08-25 Thread Nicolas Oury
You can probably boost n-body on 1.2 by replacing arrays with deftypes. (definterface BodyIsh (^double getMass []) (setMass [^double x]) (^double getPosX []) .) (deftype Body [^double ^{:unsynchronized-mutable true} mass ^double ^{:unsynchronized-mutable true} posX .] BodyIsh

Re: Clojure 1.3: Integrating clj-stacktrace?

2010-08-25 Thread Nicolas Oury
I haven't had a lot of problems with stack-traces. I would be happy to have more information on the context, though. And maybe better reporting of exception occuring in a delayed context. (when forcing a seq and the excpetion occurs under a lazy.) In this situation I have sometimes fonud that the

Re: Clojure 1.2 and the Computer Language Benchmarks Game

2010-08-24 Thread Nicolas Oury
On Tue, Aug 24, 2010 at 5:33 PM, Isaac Gouy wrote: > > Well when Clojure 1.3 is released... > > The phrase "idiomatic code" often seems to be used to mean - code > written in a natural way for that language and as if performance > doesn't matter - whereas I seem to have the strange notion that bot

Re: Clojure 1.2 and the Computer Language Benchmarks Game

2010-08-24 Thread Nicolas Oury
>>> Clojure 1.3's performance improvements will significantly impact perf on >>> some of the benchmarks. If you are trying these out, please try them on >>> both 1.2 and 1.3. >> >> >> Has Clojure 1.3 been released? >> > > No, but since the num/prim/equiv work specifically targets performance, we

Re: parallel execution

2010-08-23 Thread Nicolas Oury
>> This seemed to be in clojure.parallel, but parallel is deprecated.  Why is >> it deprecated, >> and what's the replacement for it? > > I'd like to know that as well! I am not sure, so don't believe this blindly. I think it is due to changes in the plan for Java 7 and JSR266y. Some of the depe

Re: why data structure

2010-08-23 Thread Nicolas Oury
And it's usage is far less generalised than macros in LISP. It is not an usual solution to write acamlp4 preprocessor. On Mon, Aug 23, 2010 at 1:06 PM, Meikel Brandmeyer wrote: > Hi, > > On 23 Aug., 14:03, Nicolas Oury wrote: > >> If the AST of LISP were more complicate

Re: why data structure

2010-08-23 Thread Nicolas Oury
On Mon, Aug 23, 2010 at 3:45 AM, Victor Olteanu wrote: > Some examples to illustrate this would be very welcome. > Any macro is an example of that. For example, from clojure/core.clj (defmacro -> "Threads the expr through the forms. Inserts x as the second item in the first form, making a lis

Re: why data structure

2010-08-22 Thread Nicolas Oury
On Sun, Aug 22, 2010 at 11:30 AM, Belun wrote: > why does everything have to be a data structure ? like (operation > parameter parameter ...) Because it makes really easy to do meta-programming. If you want to generate some code, it is easier to do so if you just have to construct a data structur

Re: Processing large binary file?

2010-08-21 Thread Nicolas Oury
I am not sure but I think filter will always output a sequence. You can either: - write filter-array using a loop/recur. - read/write lazily the file in a sequence and use sequence function. If it is possible in your situation, I would advise this one. On Sat, Aug 21, 2010 at 4:42 PM, Piotr 'Q

Re: let binding ~'=

2010-08-21 Thread Nicolas Oury
Clojure whitin a `(...) context resolves the name space of symbols. This is most often what you want and prevent some name collisions at macro expension. But as binders can not be name-space resolved this do not allow to write: `(let [and ]) this would expand to (let [ns/and ...]) which is

Re: Game development in Clojure

2010-08-21 Thread Nicolas Oury
Just my 2 cents: sometimes these algorithms are easier to implement by constructing an infinite lazy trees of all the game, and then independently writing a few strategy to explore the tree. John Hughes gives an example of that in Section 5 of "Why functional programming matters", that can be fo

Re: Implementing a protocol with using a base implementation?

2010-08-21 Thread Nicolas Oury
m1 I meant. Apologies. On Sat, Aug 21, 2010 at 8:36 AM, Nicolas Oury wrote: > On Sat, Aug 21, 2010 at 6:33 AM, Toni Batchelli wrote: >> P-impl.)) >> (dotimes [_ 10] (time (dotimes [_ 1] (.m1 my-simple-P "hello" ; >> "Elapsed time: 131.973 m

Re: Implementing a protocol with using a base implementation?

2010-08-21 Thread Nicolas Oury
On Sat, Aug 21, 2010 at 6:33 AM, Toni Batchelli wrote: > P-impl.)) > (dotimes [_ 10] (time (dotimes [_ 1] (.m1 my-simple-P "hello" ; > "Elapsed time: 131.973 msecs" > "Elapsed time: 142.72 msecs" > "Elapsed time: 95.51 msecs" > "Elapsed time: 95.724 msecs" > "Elapsed time: 83.646 msecs" C

Re: questions about float operations

2010-08-20 Thread Nicolas Oury
> > - why does (+ 4.2 8.4) return 12.601 and (+ 1.5 2.6) 4.1? > Since 4.2, 8.4 and (+ 4.2 8.4) are java Doubles why does it not behave > as expected? What does clojure do in the background? That's not a bug. Doubles have a standard. Clojure implementation follows the standard. (as most

Fwd: Feedback on idiomatic clojure

2010-08-19 Thread Nicolas Oury
Damon reply to me and not the list, so I forward. On Thu, Aug 19, 2010 at 9:09 PM, Damon Snyder wrote: > Hi Nicolas, > Thanks for the suggestions. Regarding the first one: ah, I see. That > is a nice compact way to test to see if the str is nil. I added that I reckon that Meikel's suggestion of

Re: Program design

2010-08-19 Thread Nicolas Oury
A big part of inheritance can be done by using defrecord, keywords and functions instead of method, and getting read of the abstract class. (defrecord Orange [:mass :energy :juice]) (defrecord Apple [:mass :energy :juice : family]) (defn get-juice [fruit] (:juice fruit)) -- You received this

Re: REPL

2010-08-19 Thread Nicolas Oury
I use Ctrl+D. But I am on Linux. On Thu, Aug 19, 2010 at 4:28 PM, Abraham Varghese wrote: > How to exit from REPL? > > -- > 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 post

Re: Clojure 1.2 Release

2010-08-19 Thread Nicolas Oury
Congratulations!! I am very happy with 1.2, as everybody I think. Great improvements to my favorite language. Your announcement got me curious: what are the future call linkage improvements? Thanks to all of you, it's great. Best, Nicolas. -- You received this message because you are subscrib

Re: Feedback on idiomatic clojure

2010-08-19 Thread Nicolas Oury
A few remarks: > > ## begin > (defn f-to-seq[file] >  (with-open [rdr (java.io.BufferedReader. >                    (java.io.FileReader. file))] >    (doall (line-seq rdr > Do you need the doall? > (defn str-sort[str] >  (if (nil? str) >    str >  (String. (into-array (. Character TYPE) (sort

Re: Impedance mismatch

2010-08-19 Thread Nicolas Oury
In which situation nil is not treated as false in Clojure? If I understand well, Clojure separates nil/false from (). In particular, if you use next and not rest, your iteration example will work if translated into Clojure. empty? works in all case and is not ugly either. For the java typing sto

Re: cool compiler-project?

2010-08-18 Thread Nicolas Oury
There is a size limit on methods on the jVM. partial-evaluator would be a cool project, I think. On Thu, Aug 19, 2010 at 6:38 AM, Tim Daly wrote: > Could the compiler insert phantom "method bodies" around classes? > Or does the JVM insist that you can't "lie about the code structure"? > Am I bei

Re: defprotocol not working?

2010-08-18 Thread Nicolas Oury
You can create a new project, even if you don't use it: lein new experiments inside it will create a project.clj. Checks the dependencies look like that: :dependencies [[org.clojure/clojure "1.2.0-RC3"] [org.clojure/clojure-contrib "1.2.0-RC3"] Type lein deps in the directo

Re: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-18 Thread Nicolas Oury
auto-indentation and parens highlighting are better than lines with only one parens. At least for me. There is no law. Do what is best for you. You might, or not, change your mind when you have more practice with all those parens. -- You received this message because you are subscribed to the

Re: Nil Coalesce

2010-08-18 Thread Nicolas Oury
I have a solution : (defn unfold [f & as] (if-let [[hd new-as] (apply f as)] (lazy-seq (cons hd (apply unfold f new-as))) ())) unfold could be called co-reduce or coreduce. It is the dual operation of reduce, in category theory. Instead of reducing a seq to create a value, it

Re: Today's clojure trick question

2010-08-18 Thread Nicolas Oury
I am not an expert. Is it possible on some JDK to put a breakpoint on Boolean constructor and look at the stack? Or you can't put a breakpoint on standard library? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cl

Re: accessing a mutable field outside of a deftype

2010-08-18 Thread Nicolas Oury
And is the one that works (for non-mutable fields) reliable or just an implementation accident that could change in the future? On Wed, Aug 18, 2010 at 4:27 PM, Nicolas Oury wrote: > And they need to be in an interface first? > -- You received this message because you are subscribed

Re: accessing a mutable field outside of a deftype

2010-08-18 Thread Nicolas Oury
And they need to be in an interface first? -- 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 unsub

Re: Today's clojure trick question

2010-08-18 Thread Nicolas Oury
(defmacro fat-if) On Wed, Aug 18, 2010 at 4:09 PM, Brian Hurt wrote: > Consider the following bit of code: > > (let [ x (new java.lang.Boolean false) ] (if x "trouble" "ok")) > > As you might guess from the fact that I'm calling it's a trick question, the > above code returns "trouble", not "

accessing a mutable field outside of a deftype

2010-08-18 Thread Nicolas Oury
This works (deftype A [a]) (.a (A. 5)) This don't (deftype A [^{:volatile-mutable true} a]) (.a (A. 5)) Is this normal? Is this a bug? How could I access the field? Best, Nicolas. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to thi

Re: Simple question about name-spaces

2010-08-18 Thread Nicolas Oury
If you intern all the ns-public variable of a namespace, they will be reexoprted? Will there be an indirection at runtime or the JVM can sort that out? -- 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: Simple question about name-spaces

2010-08-18 Thread Nicolas Oury
That helps a lot. Thank you very much. That is not very nice though. I quite would like a :reexport option to use. Best, Nicolas. On Wed, Aug 18, 2010 at 11:17 AM, Meikel Brandmeyer wrote: > There is no standard way of doing that. There is immigrate of an old > Compojure version, which is a h

Simple question about name-spaces

2010-08-18 Thread Nicolas Oury
Dear all, I have a simple problem I can't manage to solve. I have a library of multiple namespaces( a b c) that I want to include in one namespace lib, so user of the library can only use/require lib and have access to all the functions i a, b and c. What is the standard way to do that? Best,

Re: Nil Coalesce

2010-08-17 Thread Nicolas Oury
> > Clojure golf is the most fun golf! > >  (defn nil-coalesce [a b] >    (map #(or %1 %2) a (concat b (repeat nil > > Or if you really want to treat nil and false differently: > >  (defn nil-coalesce [a b] >    (map #(if (nil? %1) %2 %1) a (concat b (repeat nil > I am not sure to get it.

Re: defprotocol not working?

2010-08-17 Thread Nicolas Oury
defprotocol is a new feature of Clojure 1.2. A fantastic RC3 of this fantastic software is available. A good way to get it is to use the amazing Leiningen. On Tue, Aug 17, 2010 at 7:17 AM, Henrik Mohr wrote: > Hi there! > > I'm a completely new newbie in the clojure sphere - old dog in Java > a

Re: What is reference?

2010-08-16 Thread Nicolas Oury
In Common LISP, you can modify anything, anywhere. In the ML family of language, there are refs, but, if they have the same name, they do not share the concept. They are closer of Clojure's atoms. There is no notion of transactions. Haskell and a few other languages have Software Transactional M

Re: Game development in Clojure

2010-08-16 Thread Nicolas Oury
> Sadly I feel that I'm going to have to target development at the > lowest common > denominator that I think users will have (hence I'm targeting Java > 1.5+) > Escape Analysis and GC tweeking does not need to change your code. It is activated by option to the JVM. It would be interesting to try

Re: Protocols and default method implementations

2010-08-16 Thread Nicolas Oury
On Mon, Aug 16, 2010 at 3:29 AM, Matthew Phillips wrote: > ;; Now, if I want any node's in-edges, I can't just call "in-edges" > ;; because Node implementations won't have it, so I compute them in > ;; that case. > (defn node-in-edges [n] >  (if (isa? Node2) >    (in-edges n) >    (compute-node-in

Re: Game development in Clojure

2010-08-16 Thread Nicolas Oury
On Mon, Aug 16, 2010 at 10:51 AM, Martin DeMello wrote: > Sometimes there's simply no way around it. For instance, I recently > had some python code that (stripped to its simplest form) had two > classes, Document and Attachment, where Attachment was a specialised > subclass of Document, but Docum

Re: What is reference?

2010-08-16 Thread Nicolas Oury
It's a clever box containing a value. You can open the box and read the current value. But you can't modify the content of the box directly. You need to change the value in a box in a transaction. The cleverness of refs comes form the fact that all read and all write in a transaction are consisten

Bug of instance? when called in deftype

2010-08-15 Thread Nicolas Oury
Dear all, I spotted something than I thought was unusual in 1.2-RC2 (haven't try RC3 yet) (defprotocol Test (test [x])) (deftype Foo [] Test (test [x] (instance? Foo x))) (test (Foo.)) => false (instance? Foo (Foo.)) => true Should I submit or I am missing something obvious? It is never

Re: Protocols and default method implementations

2010-08-14 Thread Nicolas Oury
On Sat, Aug 14, 2010 at 5:32 AM, Matthew Phillips wrote: > > One idea that I tried was to use extend-type on a protocol, say to > extend any Node to be a PrettyPrintableNode. Obviously this didn't > work, and I'm not sure it actually makes semantic sense, but it's > interesting that was my intuiti

Re: Game development in Clojure

2010-08-14 Thread Nicolas Oury
I have a similar problem with deftype/defecord If I need to mutually defined types... (declare new-a) (deftype B ... (new-a)...)) (deftype A) (defn new-a [] (A.)) On Sat, Aug 14, 2010 at 8:21 AM, Mark Engelberg wrote: > On Fri, Aug 13, 2010 at 9:39 PM, Eric Lavigne wrote: >> This

Re: Game development in Clojure

2010-08-13 Thread Nicolas Oury
On Fri, Aug 13, 2010 at 2:51 PM, Mike Anderson wrote: > 2. It would be great to reduce the amount of memory allocations. Yes, > I know memory is plentiful and GC is very cheap, but it's still not as > cheap as stack allocation and any noticeable GC pauses are not good > for the player experience i

Re: What is the good way of def-ing during macro expansion

2010-08-13 Thread Nicolas Oury
No problem Evan, (def constants (atom ())) (defn add-constant [name x] (let [sym (gensym name)] (reset! constants (cons ([sym x]) @constants) sym )) Then when I produce code, I call add-constant and use the returned symbol. (I only use it to produce new constants, which is the ann

Re: Protocols and default method implementations

2010-08-13 Thread Nicolas Oury
On Fri, Aug 13, 2010 at 2:46 PM, Meikel Brandmeyer wrote: > Using extend is slower, but more dynamic (read: mix-in via map merge > vs. hard-wiring things with inline definition). > > Interesting... Is there a link explaining how it is implemented in the extend situation and how much slower it is?

  1   2   3   >