Re: another binding issue?

2009-07-14 Thread Mark Engelberg
On Tue, Jul 14, 2009 at 12:40 PM, Jarkko Oranen wrote: > This is a common gotcha. It's actually a laziness issue: the seq > produced by filter is realised only after it exits the binding scope, > thus producing '(1). You need to use "doall" to force the seq if you > want the binding to apply. Yea

Re: another binding issue?

2009-07-14 Thread Mark Engelberg
It almost seems like what you want is for lazy data structures to close over the dynamic vars that have been modified from their root bindings at the time the lazy data structure is created. Seems like coming up with well-defined semantics for this would be an interesting research problem, and if

Re: Clojure emacs formatting of letfn

2009-07-14 Thread Mark Engelberg
On Tue, Jul 14, 2009 at 7:15 PM, Phil Hagelberg wrote: > I haven't used letfn; could you give an example of how it's formatted > and how you think it should be formatted? > > -Phil This is a total nonsense function, just to show formatting (will it even show up in googlegroups with the proper for

Re: Clojure emacs formatting of letfn

2009-07-14 Thread Mark Engelberg
On Tue, Jul 14, 2009 at 7:46 PM, Phil Hagelberg wrote: > I see. The way I usually see let-forms is having the argument list start > on the same line as the "let" itself, which would look like: > >> (defn test-letfn [n] >>   (letfn [(function1 [a b] >>                      (+ (function2 a) sqr-n))

Re: Clojure vectors

2009-07-15 Thread Mark Engelberg
On Wed, Jul 15, 2009 at 3:51 AM, Jan Rychter wrote: > I am not sure what you mean about subvecs, though -- I currently use > them for dropn and rot operations, and I don't know how to avoid using > them: The problem with subvec is that it doesn't really create a "new" vector, it just adds a level

Re: Clojure vectors

2009-07-15 Thread Mark Engelberg
On Wed, Jul 15, 2009 at 9:58 AM, Mark Engelberg wrote: > The problem with subvec is that it doesn't really create a "new" > vector, it just adds a level of indirection off of the original > vector.  So for example, if you look up, say, index 2 in the subvec, > it kno

Re: Is there a standard function testing if a sequence starts with a sequence

2009-07-17 Thread Mark Engelberg
On Fri, Jul 17, 2009 at 1:32 PM, samppi wrote: > > Is there a function in clojure.core or clojure.contrib so that: >  (and (mystery-fn '(a b c d) '(a b)) >        (not (mystery-fn '(a b c d) '(a b d how about something like: (defn mystery-fn [l1 l2] (every? identity (map = l1 l2))) --~--~--

Re: Uncle Bob: bowling meets Clojure

2009-07-20 Thread Mark Engelberg
I think you guys are really overthinking this problem. Because Clojure inherits Java's stack limitations, we tend to get hung up on converting elegant recursive code into loop/recur/accumulator structures. But here, we have a problem that we know isn't going to blow the stack, so just think recu

Re: Uncle Bob: bowling meets Clojure

2009-07-20 Thread Mark Engelberg
Whoops, I guess I don't understand bowling scoring as well as I thought. Now that I've read up a bit more on bowling scoring, I see that if you get down to three rolls, (say 10, 7, 2) it must be scored differently depending on whether it is a strike in the 9th frame followed by 2 balls in the 10t

Re: Uncle Bob: bowling meets Clojure

2009-07-20 Thread Mark Engelberg
Sorry for the confusing choice of variable name. Should be "game" not "games" in: (defn score [game] (sum (take 10 (frame-scores game --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to th

Re: Uncle Bob: bowling meets Clojure

2009-07-20 Thread Mark Engelberg
Where is the original problem statement? On Mon, Jul 20, 2009 at 11:16 AM, Jim Oly wrote: > > My main concern was that the problem statement doesn't just specify > the score function but also a roll function to accumulate the ball > rolls. --~--~-~--~~~---~--~~ Yo

Re: when should functions "seq" their arguments?

2009-07-27 Thread Mark Engelberg
Yeah, but this case is different because nth is much faster if the input is a vector, and calling seq on the input will actually degrade the performance for vector inputs. Maybe you could test for vectorness, and call seq otherwise. --~--~-~--~~~---~--~~ You recei

Re: Transient Data Structures

2009-08-03 Thread Mark Engelberg
So if you want to make 10 changes to a vector, would it be worthwhile to turn it into a transient, make the 10 changes, and then turn it back to persistent? If no, then 100 changes? 1000? In other words, how much overhead is there in the transformation back and forth, and therefore, about how m

Re: Transient Data Structures

2009-08-03 Thread Mark Engelberg
On Mon, Aug 3, 2009 at 5:39 PM, Rich Hickey wrote: > In short, the O(1) overhead is less than the cost of even a single > edit. So, e.g. into/vec/vector now use transients unconditionally if > possible. Excellent. I'm glad to hear that the core functions will use transients so I don't have to ma

Re: a better reductions?

2009-08-07 Thread Mark Engelberg
I believe that if you're going for speed, another trick is to use if-let to bind a name to (seq coll) and reuse the new name, rather than coll, when applying first and rest later in the function. --~--~-~--~~~---~--~~ You received this message because you are subsc

Re: Clojure performance tests and clojure a little slower than Java

2009-08-08 Thread Mark Engelberg
On Fri, Aug 7, 2009 at 5:14 PM, John Harrop wrote: >     (if (and (not (= 0 i)) (< (+ zr2 zi2 limit-square))) I believe that (zero? i) is faster than (= 0 i). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure"

Re: Pure-functional N-body benchmark implementation

2009-08-10 Thread Mark Engelberg
Andy, My understanding is that any double that gets stored in a vector or map is boxed, and therefore, the vast majority of your double conversions aren't really doing anything, because when you pull them out of the vector or map, they'll just be Double objects again. I believe that the biggest

Re: Pure-functional N-body benchmark implementation

2009-08-10 Thread Mark Engelberg
On Mon, Aug 10, 2009 at 11:15 PM, Andy Fingerhut wrote: > I suspect I'm doing something wrong in my mutable Java array > implementation, but I don't see what it could be. There still seems to be a lot of boxing and unboxing going on. For example, in: (let [[momx momy momz] (offset-momentum bodie

Re: Pure-functional N-body benchmark implementation

2009-08-11 Thread Mark Engelberg
On Tue, Aug 11, 2009 at 12:39 AM, Andy Fingerhut wrote: > Wow, you ain't kiddin.  I changed about 10 lines from my last version, > to avoid using aset-double, using aset and type hints until the > reflection warnings went away, and it sped up by a factor of 10.  I'm > leaving the previous version'

Re: Pure-functional N-body benchmark implementation

2009-08-17 Thread Mark Engelberg
Here's what I've learned from following this benchmark thread: >From the various things I've read about Clojure's performance, I've always had this sense that: a) if you have a performance problem, there's probably some inner loop that needs to be optimized, and so b) you can use Clojure's type-h

Re: Pure-functional N-body benchmark implementation

2009-08-17 Thread Mark Engelberg
On Mon, Aug 17, 2009 at 9:25 AM, Bradbev wrote: > I found > another 2-3x speed up by coercing the indexes with (int x), ie > (defmacro mass [p] `(double (aget ~p (int 0 Which makes me wonder why aget doesn't automatically coerce an index to an int. Would an input that can't be coerced to an

Re: questions about datalog

2009-09-14 Thread Mark Engelberg
On Mon, Sep 14, 2009 at 10:02 PM, Tom Faulhaber wrote: > > Did you also read the overview that's part of contrib at > http://richhickey.github.com/clojure-contrib/doc/datalog.html. > So because of this thread, I just went and perused the description of the Clojure datalog library. Some things I

Re: idomatic sudoku?

2009-10-10 Thread Mark Engelberg
Represent each cell as a row number, column number, and a set of possible digits that can go in that cell. Create a map that generates a keyword for the sector name from the row and column numbers. You're going to write a recursive function that processes a sequence of cells that still need to be

Re: idomatic sudoku?

2009-10-10 Thread Mark Engelberg
There is a pretty wide range of ways to solve problems in Clojure, arguably more so than Python. This isn't exactly how I'd code it, but there's nothing so egregious in it that I'd call it un-idiomatic. I'd probably use keywords rather than strings. I'd probably use lists rather than some of th

Re: Clojure's 2nd Birthday!

2009-10-15 Thread Mark Engelberg
Uh oh, time for the "terrible twos". Who wants to throw the first tantrum? :) --~--~-~--~~~---~--~~ 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 p

Re: Beginner: performance of vector creation/"modification"

2009-10-19 Thread Mark Engelberg
This reminds me, is there anything in contrib that works like Scheme's build-vector which works like: (build-vector n f) produces (vec (map f (range n))), i.e., [(f 0) (f 1) (f 2) ... (f (dec n))] ? It would be great if someone's already tested a few variations of this fairly useful function to

Re: Infinite sequences hang sets and maps

2009-10-28 Thread Mark Engelberg
This is basically the behavior I would expect. I expect that when I put two sequences into a set, they are compared for equality, which is clearly impossible if they are infinite. I don't think I'd want some automatically truncated comparison. If I really wanted truncated comparison, there are

Re: Infinite sequences hang sets and maps

2009-10-29 Thread Mark Engelberg
On Wed, Oct 28, 2009 at 11:08 PM, John Harrop wrote: > For the specific case of hashCode, no; identical values must have identical > hashes but different values need not have different hashes. Collisions due > to the hypothetical cutoff get exponentially less likely with each > additional increme

Re: (into) improvement

2009-11-03 Thread Mark Engelberg
On Tue, Nov 3, 2009 at 7:56 PM, mbrodersen wrote: > It would be nice to have (into) work for more parameters: > > (into [] [1 2] [3 4] [5 6 7]) => [1 2 3 4 5 6 7] If you did this, it would be very easy to get confused and think that: (into [] [1 2] [3 4] [5 6 7]) would yield [[1 2] [3 4] [5 6 7

Re: Running out of memory when using loop/recur and destructuring

2009-11-03 Thread Mark Engelberg
I agree that seqs carry a large degree of risk. You have to work very hard to avoid giving your large sequences a name, lest you accidentally "hang on to the head". In Clojure's early days, I complained about this and described some of my own experiments with uncached sequences. Rich said he wa

Re: Converting to TCO

2009-11-08 Thread Mark Engelberg
Hint: Use an accumulator. http://htdp.org/2003-09-26/Book/curriculum-Z-H-39.html#node_chap_31 In fact, you may want to consider reading How to Design Programs before SICP. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Gro

Re: Imperative into functional?

2009-11-08 Thread Mark Engelberg
On Sun, Nov 8, 2009 at 8:41 AM, Michael Jaaka wrote: > Can any imperative code be transformed to functional equivalent? > (Give an answer in terms of the same way I can answer on recursion and > loops) Short answer: Yes. Long answer: Yes, but sometimes the transformation can get rather unwieldy

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
The general philosophy in Clojure seems to be that if you use a function in a way that is not intended, there's no guarantee about what might happen. You might get an error, or you might just get a strange result. --~--~-~--~~~---~--~~ You received this message be

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
2009/11/9 Tiago Antão : > What is the rationale for even? and contains? having different > behaviors for the exact same error (ie, one throws the other works > fine and just returns false on a type error)? From a design > perspective this seems to increase the cognitive load to programmers > witho

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
On Mon, Nov 9, 2009 at 12:32 PM, Kevin Downey wrote: > > the behavior of functions outside of their domain is undefined. I > guess I still don't get it. why would you use a function on something > outside of its domain? do people just pick functions at random to > compose their programs? Of cour

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
pen in the block of code that is causing the problem and not later. On Mon, Nov 9, 2009 at 12:35 PM, Mark Engelberg wrote: > On Mon, Nov 9, 2009 at 12:32 PM, Kevin Downey wrote: >> >> the behavior of functions outside of their domain is undefined. I >> guess I still don'

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
2009/11/9 Tiago Antão : > But the end result with strings and vectors is a tad unintuitive... Right, strings and vectors can be thought of as either collections, or as associative mappings from integers to characters/objects. contains? treats them as associative mappings. Yes, it's unintuitive,

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
On Mon, Nov 9, 2009 at 5:41 PM, John Harrop wrote: > In the meantime, the main thing still missing from Clojure is a convenient > queue. What's wrong with clojure.lang.PersistentQueue? --~--~-~--~~~---~--~~ You received this message because you are subscribed to

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
On Mon, Nov 9, 2009 at 5:54 PM, David Brown wrote: > Perhaps the GHC Data.Sequence library could be ported.  It's based on > 2-3 finger trees, and allows efficient adding and removal from either > end of the sequence. I've tried porting finger trees to Scheme before, and although it is efficient

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
Yes, it's in Clojure 1.0, it just doesn't have a convenient name. So give it a convenient name like this: (def empty-queue clojure.lang.PersistentQueue/EMPTY) and then you're ready to go. conj, peek, pop, into and all the other sequence-based functions work the way you'd expect. The implementa

Re: Consistency of the API

2009-11-09 Thread Mark Engelberg
> How does it efficiently deal with when the list-part has been completely > consumed? Well, the latest code is here: http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/PersistentQueue.java I don't know whether it has changed since 1.0. Just look in the src/jvm/clojure/lang dir

Re: Using agents and blocking I/O.

2009-11-09 Thread Mark Engelberg
On Mon, Nov 9, 2009 at 8:28 PM, David Brown wrote: > Let's say I have some thing that keeps track of the state of some I/O > entity, let's say some kind of file-based storage.  There is state > associated with the entity.  It's important that only one thread be > able to read or write from this s

Re: Datatypes and Protocols - early experience program

2009-11-12 Thread Mark Engelberg
I'm still trying to get my head around the new features. Seeing more code examples will definitely help. In the meantime, here is some stream-of-consciousness thoughts and questions. Datatypes: I'm a little worried about the strong overlap between reify/proxy, deftype/defstruct, and defclass/ge

Re: Datatypes and Protocols - early experience program

2009-11-13 Thread Mark Engelberg
Rich, thanks for the extended explanation of the overlap between the old and new constructs; I found this explanation much clearer than what is currently on the wiki. Basically, the key for me was realizing that these new constructs are all you're likely to need as long as you are just programming

Re: Datatypes and Protocols - early experience program

2009-11-14 Thread Mark Engelberg
On Fri, Nov 13, 2009 at 12:58 AM, Konrad Hinsen wrote: > Coming from a Python background, I don't think access restrictions are > necessary. However, flagging fields as "not meant for use by > outsiders" could be of interest for documentation tools, to make it > clear what client code can safely r

Re: Clojure Scoping Rules

2009-11-20 Thread Mark Engelberg
Conceptually, the best way to think about it is that your binding sets the global x to 100 and restores the global x to 1 when exiting the scope of the binding construct. It has no effect on your local x. Dynamic binding is confusing, and should be used with care. If you stick with the lexical s

Re: Clojure Scoping Rules

2009-11-20 Thread Mark Engelberg
On Fri, Nov 20, 2009 at 8:02 PM, Mark Engelberg wrote: > Dynamic binding is confusing, and should be used with care. Elaborating on my previous point: it's especially confusing because dynamic binding interacts poorly with lazy data structures, which is predominantly what you deal

Re: Clojure Scoping Rules

2009-11-21 Thread Mark Engelberg
On Sat, Nov 21, 2009 at 8:12 AM, Armando Blancas wrote: > I sympathize with your difficulties, but isn't there something > fundamentally incompatible between the later-or-never of lazy-seq and > the this-way-here-and-now for which dynamic binding is good for? In > this case you picked laziness ove

Re: Clojure Scoping Rules

2009-11-23 Thread Mark Engelberg
Meikel's blog post quotes: "running into a lot of such trouble is a sign, that you misuse dynamic variables. Use them wisely." I'd like to see examples of what you think is a good, clean, compelling use of dynamic variables that are properly used wisely. My own experience is that if the code is s

Re: Clojure Scoping Rules

2009-11-24 Thread Mark Engelberg
On Mon, Nov 23, 2009 at 11:39 PM, Garth Sheldon-Coulson wrote: > Hi Mark, > > In Clojuratica I make what I think is "good, clean, compelling use" of > dynamic vars. I rewrote the code to use dynamic vars after I found that > doing it the other way became unwieldy and inelegant. OK this makes sens

Re: How to internally refer to other keys in a hashmap?

2009-12-09 Thread Mark Engelberg
On Wed, Dec 9, 2009 at 5:24 PM, CuppoJava wrote: > I've run into this problem before also actually. Basically from what I > read, self-recursive data-structures are hard to do in an eager > functional programming language. I think you have to resort to > mutation to handle it nicely. But I would b

Re: lazy sequence question

2009-12-09 Thread Mark Engelberg
There are only 9 items that satisfy your predicate. (take 10 ...) demands a 10th, and it keeps searching the (iterate inc 1) stream forever, endlessly searching for that 10th item it will never find. On Wed, Dec 9, 2009 at 9:41 PM, Mike K wrote: > On Dec 9, 10:35 pm, Mike K wrote: > >> The firs

Re: Funding Clojure 2010

2009-12-14 Thread Mark Engelberg
For me, Clojure actually decreases my income. I can program so much faster in Clojure that I generate fewer billable hours :) . Seriously though, I am donating because Clojure makes programming more fun. That's reason enough for me. -- You received this message because you are subscribed to th

Re: Parenthesis Inference

2009-12-18 Thread Mark Engelberg
The main downside of such an approach is that if you copy and paste your code to a new context in which it has a different level of indenting, it's very easy to screw things up. You then have no way to re-indent the code without fully analyzing and understanding the *semantics* of the code, becaus

Re: Parenthesis Inference

2009-12-19 Thread Mark Engelberg
On Sat, Dec 19, 2009 at 9:21 AM, David Nolen wrote: > I don't think anybody in the Clojure community wants to Clojure to be a > fringe language. Actually, I don't mind if Clojure retains a certain degree of "fringe" status. To clarify, I think the ideal size for a language community is somewhere

Re: Second Lisp to Learn

2009-12-20 Thread Mark Engelberg
http://plt-scheme.org/ Use the textbook htdp.org and you will develop a very deep understanding of how to structure programs in Lisp (and this understanding will transfer to other languages as well). You mentioned that you want to see if there are other ideas worth stealing. Not only does PLT Sch

Re: Clojure + Music Notation

2009-12-22 Thread Mark Engelberg
Despite what others have said, I'm going to chime in and say that I think an immutable hierarchy is going to be awkward for the use case you describe. In your example, notes are buried fairly deep in a hierarchy. Now if you always tend to make manipulations by starting from the root score node an

Re: Convert arabic to roman

2009-12-25 Thread Mark Engelberg
Structurally, I'd say your program is just fine. But, it did take me a while to convince myself that your program worked, and understand why, so I'd say it is less clear than it could be. When striving for clarity, it is essential to: 1. Break your program into small, easily understandable functi

Re: Why "recur"?

2010-01-17 Thread Mark Engelberg
Even if Java and thus Clojure eventually adds TCO, I hope recur sticks around, because I have come to prefer loop-recur syntax for the kinds of things I do with named let in Scheme. TCO would certainly be useful, though. -- You received this message because you are subscribed to the Google Groups

Re: Clojure Conference Poll

2010-01-23 Thread Mark Engelberg
I second Seattle. On Fri, Jan 22, 2010 at 1:19 PM, ajay gopalakrishnan wrote: > I vote for Seattle. > > -- 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 ar

Re: Leiningen plugin: run

2010-01-23 Thread Mark Engelberg
Is Leiningen a Linux-only tool? -- 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

Replacing proxy with reify/deftype

2010-01-24 Thread Mark Engelberg
As has been discussed here previously, one way to generate an uncached stream of numbers is: (defn incs [i] (proxy [clojure.lang.ASeq] [] (first [] i) (next [] (incs (inc i) ASeq implements most of the machinery of sequences, so you can just implement the parts that differ. I'd like

Re: Full Disclojure - I Need Topics!

2010-01-24 Thread Mark Engelberg
Debugging techniques, including: * How to make sense of Clojure's stack traces. * How to use Java debugging and profiling tools with 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

Re: Full Disclojure - I Need Topics!

2010-01-26 Thread Mark Engelberg
Topic idea: What is the most elegant way to write a GUI in Clojure? (Swing? JavaFX?) Any great contrib libraries that make GUI programming noticeably easier? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojur

Re: Style for mutable data

2010-01-30 Thread Mark Engelberg
How about Cell? -- 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 group, sen

Re: Interesting ICFP slides from Guy Steele -- Organizing Functional Code for Parallel Execution

2010-02-10 Thread Mark Engelberg
2010/2/10 André Ferreira : > What he said is basically right, only instead of list it's called > vector. Not sure if vector branching is 64 or 32. If you could append two vectors quickly in Clojure, you'd be able to use a lot of the techniques described in those slides. The whole discussion also

deftype comment

2010-02-13 Thread Mark Engelberg
I was doing some experimenting with deftypes this evening. I understand that you need to specify clojure.lang.IPersistentMap as an interface in order to make your type behave like a general-purpose map (supporting assoc, dissoc, etc.). After playing around, I think it would be ideal that if you *

Re: deftype comment

2010-02-13 Thread Mark Engelberg
Yes, that's what I meant :) . On Sat, Feb 13, 2010 at 11:27 PM, Brendan Ribera wrote: > >> You should be able to do (assoc p :x 3), you should get back #:Posn{:x >> 1, :y 2} > > You meant that you get back #:Posn{:x 3, :y 2}, right? Sounds reasonable to > me. > > -- > You received this message be

Re: deftype comment

2010-02-14 Thread Mark Engelberg
On Sun, Feb 14, 2010 at 8:56 AM, Stuart Sierra wrote: > Rich's stated reason against this is that he wants to be able, some > day, to implement maps and map-like things with deftype. Hmmm, if so, then there's a bit of a design tension between that goal and the goal of "prefer deftype to defstruct

Re: deftype comment

2010-02-14 Thread Mark Engelberg
Actually, the more I think about it, the more I feel like deftype's "specify clojure.lang.IPersistentMap as an interface with no implementation, and you'll get a default implementation" seems like a weird exception, and I can't help but wonder if there's a more general way to handle it that would h

Re: into map?

2010-02-16 Thread Mark Engelberg
dotimes is for side effects. What you want is to use a for loop that produces a sequence of key-value pairs. (into {} (for [i (range 3)] [i (range 4)])) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@goo

Re: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Mark Engelberg
On Wed, Mar 3, 2010 at 5:20 PM, Rick Moynihan wrote: > > If you have a single value representing the whole world, then it seems > that protecting it with an atom would be the simplest and most > idiomatic solution. ... > For a single value > there seems to be little reason to adopt refs, ... I

Re: Some basic guidance to designing functional vs. state parts of app

2010-03-05 Thread Mark Engelberg
When you increment the contents of an atom, for example, it happens immediately. If it is inside a transaction, and the transaction retries, the contents will be incremented multiple times. Refs, on the other hand, retry from the initial state at the beginning of the transaction, so as long as th

Re: clojure.core/compare and persistent lists

2010-03-09 Thread Mark Engelberg
My recollection is that when I posted this question several months ago, Rich's response was that there was no particular reason that PersistentLists don't implement Comparable, other than that it hadn't been done yet. So I assume a patch is welcome on this, but no one has stepped forward to do it

Re: "Interesting" integer behavior

2010-03-11 Thread Mark Engelberg
If (inc 21471493647) and (+ 1 21471493647) produce different types of numbers, I would definitely categorize this as a "bug" and not just "strange behavior". This means that if you use 2147493748 as a key in a map or set it might work improperly depending on what computation you used to arrive at

Re: Why clojure does not have remove-duplicates and delete-duplicates ?

2010-03-12 Thread Mark Engelberg
Why not just use the "set" function? On Fri, Mar 12, 2010 at 10:20 AM, Giacecco wrote: > All, > Why does clojure miss lisps' remove-duplicates and delete-duplicates? > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send em

Re: Why clojure does not have remove-duplicates and delete-duplicates ?

2010-03-12 Thread Mark Engelberg
You could also use the "distinct" function, if you really need a lazy sequence. 2010/3/12 Mark Engelberg > Why not just use the "set" function? > > On Fri, Mar 12, 2010 at 10:20 AM, Giacecco wrote: > >> All, >> Why does clojure miss li

Ensure

2010-03-14 Thread Mark Engelberg
What's a minimal example that demonstrates when ensure is necessary? -- 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

Re: Ensure

2010-03-15 Thread Mark Engelberg
Michal, aren't those examples backwards? I would expect the ensure version to be the one that needs to retry, and the deref version to be the one that doesn't. 2010/3/14 Michał Marczyk > On 15 March 2010 06:47, Mark Engelberg wrote: > > What's a minimal example that

Re: Ensure

2010-03-15 Thread Mark Engelberg
2010/3/14 Meikel Brandmeyer > In short: ensure is used when you require only read access to a Ref, > but need the value to be constant through the transaction. If you > modify the a Ref via alter or ref-set, the ensure is not necessary. > > OK, I think I've finally figured out why I've always fou

Re: Ensure

2010-03-15 Thread Mark Engelberg
Thanks Michal, those annotations helped quite a bit. It also demonstrates to me that my mental model of how the STM works is quite out of touch with how it actually does. I'm especially surprised that derefs work the way your example illustrates. >From the STM docs, it really sounded like derefs

Re: Ensure

2010-03-15 Thread Mark Engelberg
Wow, the STM works far, far differently than I imagined, but I think I get it now. The adaptive history clarification helped tremendously. Thanks, Mark -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@goo

Question about overriding print-method for deftypes

2010-03-21 Thread Mark Engelberg
Consider the following deftype: (deftype Piece [#^int number #^char letter]) (def piece (Piece 1 \A)) Now, when I evaluate piece at the REPL, I want it to print: 1A rather than #:Piece{:number 1, :letter \A} similarly, I would like (str piece) to yield "1A". A while back, I was told on this lis

Question about overriding print-method for deftypes

2010-03-21 Thread Mark Engelberg
Consider the following deftype: (deftype Piece [#^int number #^char letter]) (def piece (Piece 1 \A)) Now, when I evaluate piece at the REPL, I want it to print: 1A rather than #:Piece{:number 1, :letter \A} similarly, I would like (str piece) to yield "1A". A while back, I was told on this lis

Re: Question about overriding print-method for deftypes

2010-03-21 Thread Mark Engelberg
Speaking of overriding methods, what am I doing wrong here: (deftype Piece [#^int number #^char letter] Comparable (compareTo [x y] (let [c1 (compare (:number x) (:number y))] (if (zero? c1) (compare (:letter x) (:letter y)) c1 What other interesting things can be overridden for

Re: Question about overriding print-method for deftypes

2010-03-21 Thread Mark Engelberg
I'm kind of surprised that *print-dup* behavior isn't automatically enabled for deftypes. Is there a standard way to add this in for a specific deftype? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@goog

Getting an arbitrary element from a transient hash-set

2010-03-21 Thread Mark Engelberg
On a set s, you can just do (first s) to get an arbitrary element of s. Any way to get an arbitrary item for a transient set? -- 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

Bug: contains? doesn't work on transient maps or sets

2010-03-22 Thread Mark Engelberg
Disturbingly, it doesn't error, it just always returns false. This is in version 1.1. Can someone check and see if this is still a problem on the latest version? Thanks, Mark -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, se

Re: listing factors of a number

2010-03-24 Thread Mark Engelberg
Check out clojuratica. It interfaces Clojure to a free version of mathematica which has a very fast implementation called FactorInteger. --Mark -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups

Re: listing factors of a number

2010-03-24 Thread Mark Engelberg
Rubin wrote: > Except Mathematica is kind of expensive $250 for the home edition. It > looks like there is also Incanter which is a similar project using R > free statistical computing environment > > On Mar 24, 12:55 pm, Mark Engelberg wrote: > > Check out clojuratica. It

Re: ANN: labrepl, making Clojure more accessible

2010-03-24 Thread Mark Engelberg
I tried following Rob Wolfe's zip file instructions. The bin\lein deps command seemed to work fine, but when I then invoked bin\repl, I got the following error: CLASSPATH=";C:\labrepl-package\lib\ant-1.6.2.jar;C:\labrepl-package\lib\ant-laun cher-1.6.2.jar;C:\labrepl-package\lib\antlr-2.7.2.jar;C:

Re: converting long string to number

2010-03-25 Thread Mark Engelberg
Another unadvertised function that is useful to be aware of is clojure.lang.Numbers/reduce which will simplify a number to its most simple type. I often find that I want to use some BigInteger function, but then it is important to turn it back into a "typical Clojure number" at the end. For examp

printf question

2010-03-31 Thread Mark Engelberg
printf doesn't seem to do anything inside a gen-class -main function, when run from the executable jar program (compiled by the latest Netbeans Enclojure release). Is this normal, and if so, what's the workaround? Thanks, Mark -- You received this message because you are subscribed to the Goog

Re: Question about 'chains' of derefs a request for better ideas

2010-04-04 Thread Mark Engelberg
I don't understand why you need to "get rid of the delay" once it has been updated. Delays are cheap; why not just be consistent about having your data be a ref of a delay? It will keep your code simpler, and that's well worth it. -- You received this message because you are subscribed to the G

Re: Reorder a list randomly?

2010-04-04 Thread Mark Engelberg
On my system, knuth-shuffle performs several times faster than Spector's recursive functional shuffle on smallish lists, and the difference grows even more dramatic as the list grows, which is what I'd expect (since knuth-shuffle is O(n) and shuffle is O(n^2)). -- You received this message becaus

Re: Set as function

2010-04-05 Thread Mark Engelberg
On Mon, Apr 5, 2010 at 8:56 PM, Richard Newman wrote: > Why this behavior? >> > > It's useful: e.g., you can use a set as a filter. > > user=> (filter #{2 3 4 5} (range 1 10)) > (2 3 4 5) > > filter works just as well with a function that returns true and false, so that's not a particularly good

Re: Missing fns: rotate & rotate-while

2010-04-21 Thread Mark Engelberg
On Wed, Apr 21, 2010 at 8:46 AM, Sean Devlin wrote: > You're right about changing the docstring to read ""sequence" > > I think the lazy-cat version looses the ability to rotate in reverse, > which I've come to love from Ruby.  Also, I have found use cases where > I want to rotate a period longer

Re: Missing fns: rotate & rotate-while

2010-04-21 Thread Mark Engelberg
In some languages, split-at is more performant than doing take and drop separately. But in Clojure, split-at is simply defined as: (defn split-at "Returns a vector of [(take n coll) (drop n coll)]" [n coll] [(take n coll) (drop n coll)]) So by using split-at, you gain nothing other than t

Re: Datatypes and Protocols update

2010-04-22 Thread Mark Engelberg
I tried using deftype relatively recently, but realized it wouldn't work for my needs because serialization via *print-dup* wasn't yet implemented. I'd recommend including this with the 1.2 release (or is there a new recommended way to serialize Clojure data?) -- You received this message becaus

Re: Datatypes and Protocols update

2010-04-23 Thread Mark Engelberg
A few meandering observations: I like the latest change to include a this argument. It makes the number of arguments line up which is a good thing. I like the idea of defrecord for the common case, rather than having to request default implementations of various interfaces within deftype. Still

<    1   2   3   4   5   6   7   8   9   10   >