Re: BigInt + 0.5 = Infinity?

2010-10-08 Thread Per Vognsen
Sure. BigInteger.doubleValue() casts to infinity if the value is too large to be represented: user> (double (fact 1000)) Infinity You could try this using BigDecimals instead of doubles: user> (+ 0.5M (fact 1000)) -Per On Sat, Oct 9, 2010 at 11:08 AM, Miki wrote: > If the following intentiona

Re: Is This Function Idiomatic Clojure?

2010-10-07 Thread Per Vognsen
Since variety is the spice of life, here's my (less clean and untested) code that I was about to post when your message arrived in my inbox: (apply map #(into {} %) (for [[k vs] args] (for [v vs] [k v] -Per On Thu, Oct 7, 2010 at 3:18 PM, Jason Wolfe wrote: > (defn d-map [& args] >  (appl

Re: Is This Function Idiomatic Clojure?

2010-10-06 Thread Per Vognsen
Your manual composition of concat and map is the same as the built-in function mapcat. Anyway, all this is what (for ...) does for you under the covers. -Per On Thu, Oct 7, 2010 at 1:52 PM, Michael Gardner wrote: > On Oct 7, 2010, at 1:29 AM, Stefan Rohlfing wrote: > >> Following an Enlive tuto

Re: Is This Function Idiomatic Clojure?

2010-10-06 Thread Per Vognsen
Sorry, the 'in' is obviously a typo and should be left out. I tested the code in the REPL but then retyped it from memory rather than copy and pasting. :) -Per On Thu, Oct 7, 2010 at 1:53 PM, Per Vognsen wrote: > Try something like this: > > (defn dmap [& args] >

Re: Is This Function Idiomatic Clojure?

2010-10-06 Thread Per Vognsen
Try something like this: (defn dmap [& args] (for [[head items] args] item in items] [head item])) -Per On Thu, Oct 7, 2010 at 1:29 PM, Stefan Rohlfing wrote: > Dear Clojure Group, > > Following an Enlive tutorial I wanted to implement a function 'd-map' > that takes an arbitrary

Re: Screencast of the Emacs front end to the Clojure Debugging Toolkit:

2010-10-01 Thread Per Vognsen
That's some great work there, George! Are there any basic obstructions in the backend to doing expression-oriented rather than line-oriented breakpoints and stepping? -Per On Sat, Oct 2, 2010 at 3:32 AM, George Jahad wrote: > For your delectation: > http://www.vimeo.com/15462015 > > -- > You re

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

2010-09-29 Thread Per Vognsen
With all these reports of performance degradation, it sounds like it would be really useful to have a performance regression suite. -Per On Thu, Sep 30, 2010 at 1:19 PM, Mark Engelberg wrote: > bitwise-and and bitwise-shift-right and bitwise-shift-left run more > than 50 times slower in clojure

Re: Iterating through two seqs at once for side-effects

2010-09-25 Thread Per Vognsen
I would use something like this: (defn zip [& xss] (apply map vector xss)) (doseq [[x y] (zip [1 2 3] [11 22 33])] (println x y)) Most of the time I use parallel mapping directly. But in cases like this one I think the intention of the code is better expressed by the above se

Re: Something hanging onto the head?

2010-09-24 Thread Per Vognsen
The namespace binding is what's holding onto the head. This is a common enough question (which tends to occur more in toy programs than real ones) that it probably belongs in a FAQ. -Per On Fri, Sep 24, 2010 at 9:58 PM, Jeff Palmucci wrote: > Sorry, I posted this question and it turned up under

Re: ANN: Durable refs with ACID guarantees - Phase I

2010-09-23 Thread Per Vognsen
enforces a global transaction order.  If writes were outside > LockingTransaction.run(), the order could (and probably would) be > different between in-memory resources and durable resources.  For > ultimate safety, we need to be even more intrusive and add a prepare > phase to the STM.

Re: ANN: Durable refs with ACID guarantees - Phase I

2010-09-23 Thread Per Vognsen
On Thu, Sep 23, 2010 at 8:16 PM, Alyssa Kwan wrote: > There's no need for any transaction boundary; you just > have to make sure that compareAndSet does a durable swap. I had the chance to read your code today. You have a transaction boundary in DRef.set() which is called by LockingTransaction.ru

Re: ANN: Durable refs with ACID guarantees - Phase I

2010-09-23 Thread Per Vognsen
Cool! I'm getting back to Clojure after an extended absence. Just today I was pondering the design of a solution to a similar problem, though I suspect our requirements diverge on several points. My tentative conclusion was that it could be done entirely in Clojure and without modifying existing c

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

2010-09-22 Thread Per Vognsen
If you have a fixed cell topology, you can also find a coloring of the graph and use it for contention-free scheduling. With a regular grid, you can use the obvious 2-coloring (a checkerboard pattern), so you would handle all the white squares in phase 1 and all the black squares in phase 2. -Per

Re: Is reflection free clojure code possible?

2010-09-19 Thread Per Vognsen
With XNA running on the Xbox 360, reflection is the least of your worries. The runtime uses a very poor non-generational mark-and-sweep collector. At the rate of memory allocation in a typical Clojure program, you would be faced with constant GC hitches. Even people writing XNA games in C# (where i

Re: Response

2010-07-17 Thread Per Vognsen
On Sun, Jul 18, 2010 at 11:32 AM, Carson wrote: > I guess different people see things differently.  I actually didn't > understand the intent of the imperative version, even though it takes > less lines I guess.  There's quite a few things called convolution. > My naive implementation was function

Re: removing the need for refer-clojure ?

2010-05-05 Thread Per Vognsen
Here's how it works with Haskell: The Prelude module is imported automatically into all modules as if by the statement `import Prelude', if and only if it is not imported with an explicit import declaration. This provision for explicit import allows values defined in the Prelude to

Re: rand-int with bignums

2010-05-01 Thread Per Vognsen
any of the textbook algorithms for generating non-power-of-two random numbers from random bit streams should apply to this kind of situation. -Per On Sat, May 1, 2010 at 8:48 PM, Per Vognsen wrote: > On Sat, May 1, 2010 at 7:25 PM, Lee Spector wrote: >> about how to write a real rand

Re: rand-int with bignums

2010-05-01 Thread Per Vognsen
On Sat, May 1, 2010 at 7:25 PM, Lee Spector wrote: > about how to write a real random bignum generator. Let n be the bignum upper bound on the desired range. Find the quotient q and remainder r of n by b = 2^31-1. Generate q random numbers with upper bound b and one random number with upper bound

Re: Laziness and deadlocks

2010-04-26 Thread Per Vognsen
Okay, that is a blatant infinite loop that has nothing to do with deadlocks. I give up. This combination of laziness and concurrency and locking is giving me a headache. Sorry about the distraction, everyone. -Per On Mon, Apr 26, 2010 at 6:23 PM, Per Vognsen wrote: > On Mon, Apr 26, 2010 a

Re: Laziness and deadlocks

2010-04-26 Thread Per Vognsen
On Mon, Apr 26, 2010 at 6:15 PM, Per Vognsen wrote: > [...] > The idea is to try to create a situation where a pair of LazySeqs, xs > and ys, are interlinked in a cycle such that the first thread forces > them in order xs, ys while the second thread concurrently forces them >

Re: Laziness and deadlocks

2010-04-26 Thread Per Vognsen
On Mon, Apr 26, 2010 at 5:55 PM, Meikel Brandmeyer wrote: > Hi, > > On 26 Apr., 11:22, Per Vognsen wrote: > >> Consider: >> >> (def as (lazy-seq (cons 1 bs))) >> (def bs (lazy-seq (cons 2 cs))) >> ;; ... >> (def zs (lazy-seq (cons 26 as))) >&

Laziness and deadlocks

2010-04-26 Thread Per Vognsen
Consider: (def as (lazy-seq (cons 1 bs))) (def bs (lazy-seq (cons 2 cs))) ;; ... (def zs (lazy-seq (cons 26 as))) Suppose you start two threads concurrently. The first forces 'as' and the second forces 'zs'. If the timing is just right, this can result in a deadlock: // LazySeq.java final synch

Re: Datatypes and Protocols update

2010-04-24 Thread Per Vognsen
A lot of these arguments go away with functional programming. With a functional queue, you might as well store the length as a value attribute because it won't ever change. In some cases I can see the argument for on-demand computation of fields with referentially transparent caching. That's where

Re: Reading from file

2010-04-22 Thread Per Vognsen
r/parseInt (.readLine r)) (repeatedly #(.readLine r)))] (map #(Integer/parseInt %) (.split line " ") -Per On Thu, Apr 22, 2010 at 10:29 PM, Per Vognsen wrote: > How about this? > > (use 'clojure.contrib.str-utils 'clojure.contrib.duck-

Re: Reading from file

2010-04-22 Thread Per Vognsen
How about this? (use 'clojure.contrib.str-utils 'clojure.contrib.duck-streams) (defn parse [file] (let [r (reader file)] (map (fn [line] (map #(Integer/parseInt %) (.split line " "))) (take (Integer/parseInt (.readLine r)) (repeatedly #(.readLine r)) (defn unparse [xss file

Re: Missing fns: rotate & rotate-while

2010-04-21 Thread Per Vognsen
function. >From this, it follows (with no extra work) that the conjugate transformation of an invertible function is an invertible function. -Per On Thu, Apr 22, 2010 at 10:38 AM, Michał Marczyk wrote: > On 22 April 2010 03:51, Per Vognsen wrote: >> Yet another variation: >> &

Re: Missing fns: rotate & rotate-while

2010-04-21 Thread Per Vognsen
Yet another variation: (defn conjugate [f g & [g-inv]] (comp (or g-inv g) f g)) (defn composite [f f-inv n x] (nth (iterate (if (pos? n) f f-inv) x) (abs n))) (defn rotate-left [xs] (when (seq xs) (concat (rest xs) [(first xs)]))) (def rotate-right (conjugate rotate-left reverse)) (defn

Re: (- x 1) and (dec x) behave differently

2010-04-20 Thread Per Vognsen
On Tue, Apr 20, 2010 at 7:02 PM, Per Vognsen wrote: > With the way primitive types are currently supported in the compiler, > if you wanted it to work the way you expect, you'd need to express the > complicated arithmetic tower and its grid of type conversions in a > static form

Re: (- x 1) and (dec x) behave differently

2010-04-20 Thread Per Vognsen
On Tue, Apr 20, 2010 at 6:43 PM, jvshahid wrote: > Thanks Per, > > This definitely works > >> Try (loop [x (. 1 longValue)] (if (= 0 x) x (recur (- x (long 1). > > but from my understanding of clojure internals clojure.lang.Numbers > should take care of that. The Numbers class doesn't do any

Re: Event-handling and Clojure

2010-04-20 Thread Per Vognsen
You might want to check out this paper on a simple functional I/O system: http://www.ccs.neu.edu/scheme/pubs/icfp09-fffk.pdf The basic idea is really simple and natural. I've used something similar in my own past programs and I noticed that Penumbra has a GLUT-like event-driven interface that wor

Re: getting compiler-like meta data from read

2010-04-19 Thread Per Vognsen
) >     ;; gets the metatdata from the var, but changes :name to rule's > name >     (let [reg-r# (with-meta r# (assoc (meta (var r#)) :name (:name > r#)))] >       (register-rule reg-r#) >       reg-r#))) > > > > > On Apr 17, 10:48 am, Per Vognsen wrote: >

Re: (- x 1) and (dec x) behave differently

2010-04-19 Thread Per Vognsen
On Tue, Apr 20, 2010 at 8:34 AM, jvshahid wrote: > (loop [x (. 1 longValue)] (if (= 0 x) x (recur (- x 1 Try (loop [x (. 1 longValue)] (if (= 0 x) x (recur (- x (long 1). -Per -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: primitive arrays, am I reading this right?

2010-04-19 Thread Per Vognsen
On Mon, Apr 19, 2010 at 6:29 PM, Meikel Brandmeyer wrote: > PS: Tested with 1.0, though. So maybe this changed to 1.1. No, even in HEAD there is only support for reading doubles. It would be nice if the reader supported the customary 'f' suffix for reading floats. I actually made that change loca

Re: questions about clojure's core library organization

2010-04-18 Thread Per Vognsen
On Mon, Apr 19, 2010 at 12:15 PM, falcon wrote: > As I understand it, map is, itself, lazy. Does that mean that using > map to implement these methods would create extra intermediate > structures? Yes. > What if often used functions such as map/reduce/filter were macros, > that could 'deforest'

Re: questions about clojure's core library organization

2010-04-18 Thread Per Vognsen
referring symbols, you can then specify a group mask with :only-groups and :exclude-groups to compliment the current :only and :exclude features. -Per On Mon, Apr 19, 2010 at 11:28 AM, Per Vognsen wrote: > On Mon, Apr 19, 2010 at 10:30 AM, falcon wrote: >> 1. core.clj is a gigantic library

Re: questions about clojure's core library organization

2010-04-18 Thread Per Vognsen
On Mon, Apr 19, 2010 at 10:30 AM, falcon wrote: > 1. core.clj is a gigantic library with more than 400 function > definitions (378 defns and 62 defmacros to be exact).  I didn't expect > to find sequence related functions, such as map/reduce in core. > Doesn't it make sense to move functions to mo

Re: Not so happy with my code

2010-04-18 Thread Per Vognsen
(use 'clojure.contrib.combinatorics 'clojure.contrib.str-utils) (defn anagrams [xs] (map #(str-join "" %) (distinct (permutations xs Of course, the real meat is in the permutations function. The implementation in the combinatorics library is a bit complicated. Here's something simpler

Re: getting compiler-like meta data from read

2010-04-17 Thread Per Vognsen
On Sat, Apr 17, 2010 at 2:29 AM, Kevin Livingston wrote: > I have an application that will read in a large number of structures > from a file.  those structures will be used throughout the application > to produce additional data etc.  since they are "user" configurable, > it would be nice to know

Re: do we have is-delivered? for promise

2010-04-17 Thread Per Vognsen
On Sat, Apr 17, 2010 at 11:07 PM, alux wrote: > Hello Per, > > thats very cool! Many thanks! Completely solves my problem. (As far as > I can see :-) > > I'm not sure whether I completely understand the implications of the > nondeterminism you described; will think about it. You say "When each > p

Re: do we have is-delivered? for promise

2010-04-17 Thread Per Vognsen
Not currently. I added the capability to some code I posted last month for fixing print-method for promises so they aren't auto-dereferenced when undelivered: (defn promise? [p] (isa? (type p) ::Promise)) (defn promise-delivered? [p] (zero? (.getCount (:d p (defmethod print-method ::

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 1:05 AM, Per Vognsen wrote: > You can only do slow > linear-time lookups by traversing the tree's nodes exhaustively. Correction: You do not have to do a linear search on the whole tree but only on the subset of the tree for which the comparator returns

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
> Equality and ordinality are not the same thing.  It should be > perfectly reasonable to hand someone a set of unique objects sorted by > some non-unique attribute of the elements of the set. Sure, it's perfectly reasonable but it implies a different data structure. It sounds like you want a data

Re: "wrong number of args" with nested map

2010-04-16 Thread Per Vognsen
Tangent: On Fri, Apr 16, 2010 at 7:41 PM, Douglas Philips wrote: > (1) http://clojure.org/data_structures says: > ... seq returns a sequence of map entries, which are key/value pairs. ... > > I haven't yet found where in the docs a pair is defined, so I am guessing > that the concrete type (list,

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 12:01 AM, Sean Devlin wrote: > I know you might not like it, but there is a convention in JavaLand > that a comparator value of 0 is identical in a sorted collection. It's not a Java convention. It's intrinsic to the business of sorting. For sorting to give well-defined re

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
Maybe the example was poorly picked but the point stands: if you're asking for a sorted set based on a comparator, you should expect duplicate elements as dictated by comparator to be eliminated. If you wanted to sort a set of people by age, you wouldn't use a sorted set but a sorted sequence. That

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
It doesn't seem confusing to me. You are taking complete control of the set's local notion of ordering and equality. This is what I'd expect. Here's an example. First, a handy little function from Haskell: (defn on [key f] #(apply f (map key %&))) Then: user> (sorted-set-by (on :id compare)

Re: Problem with Destructuring in A Function Call

2010-04-16 Thread Per Vognsen
rt in the literal syntax and so impose no symmetry constraints. -Per On Fri, Apr 16, 2010 at 9:25 PM, Asim Jalis wrote: > On Fri, Apr 16, 2010 at 2:15 AM, Per Vognsen wrote: >> What may confuse is that map destructuring swaps the positions of keys >> and values as compared to map

Re: Translation from CL - "On Lisp" program

2010-04-16 Thread Per Vognsen
On Fri, Apr 16, 2010 at 12:41 PM, Aravindh Johendran wrote: > Sorry, I shoulda been clearer.  By similar functionality, i meant a 20- > q game with > 1) the network implemented as closures and There are various ways you can do this while separating concerns. If you don't mind specifying the quest

Re: Problem with Destructuring in A Function Call

2010-04-16 Thread Per Vognsen
What may confuse is that map destructuring swaps the positions of keys and values as compared to map literals: user> (let [{x :body} {:body 42}] x) 42 It does conform to the pattern that the bound variable precedes the value to bind in forms like let. A benefit of this ordering is that

Re: Interrupting the Repl

2010-04-15 Thread Per Vognsen
http://groups.google.com/group/clojure/search?group=clojure&q=control-c+repl Or you could use some REPL front-end (Emacs or the IDE of your choice) that takes care of this for you. -Per On Fri, Apr 16, 2010 at 1:06 PM, Brian Watkins wrote: > Is there a way to interrupt the Repl when I've set to

Re: clojure.contrib.prxml output control?

2010-04-15 Thread Per Vognsen
You can rebind *prxml-indent*. It's by nil by default, which means no indentation and (confusingly) no line breaks. If you set it to 0, you will get line breaks but with no indentation. With a greater value, you will get line breaks with indentation. If you had looked at the code, this should have

Re: clojure.set index not handling large sets...

2010-04-15 Thread Per Vognsen
That sounds weird. If you know what keys weren't making it into the index as expected, did you try reducing the problem to a smaller test case involving those exceptional keys? -Per On Fri, Apr 16, 2010 at 11:50 AM, Luc Préfontaine wrote: > Hi all, > > I tripped over something strange yesterday.

Re: apparent bug with binding (or contrib.sql ?) in current master branches

2010-04-15 Thread Per Vognsen
Is there any written rationale for direct binding? It sounds like a poor man's inlining, except we already have perfectly good opt-in inlining. If these screwy semantics are to remain, an absolute minimum courtesy would be for 'binding' to throw an exception at macro expansion time when one tries

Re: Events vs Threads paper

2010-04-15 Thread Per Vognsen
On Fri, Apr 16, 2010 at 3:16 AM, TimDaly wrote: > This might be interesting when the discussion of events vs threads > comes up: > http://www.usenix.org/events/hotos03/tech/full_papers/vonbehren/vonbehren_html/ > > Essentially they argue that thread programming can scale (100k > threads?) This is

Re: Communication: How to model it?

2010-04-15 Thread Per Vognsen
The first thing I ever implemented with promises was dataflow programming in this style. A good read is the chapter on declarative concurrency in Peter van Roy's Concepts, Techniques and Models of Computer Programming. Oz has the concept of concurrent single-assignment variables, which are much the

Re: Translation from CL - "On Lisp" program

2010-04-15 Thread Per Vognsen
What do you mean by "similar functionality"? Without using mutable state, you won't be able to retain the defnode-style interface. But obviously a twenty-questions program like this is easy to implement in a purely functional way: (defn ask [questions node] (let [data (questions node)] (asse

Re: Symbol resolution (between quote and eval/execution)

2010-04-09 Thread Per Vognsen
On Sat, Apr 10, 2010 at 12:25 PM, Douglas Philips wrote: > The differences between def and binding are also weird, since binding does > not also shadow the meta-data on the var, so not only :macro will be wrong, > but :file, :line, :arglists could also be wrong. The binding form doesn't provide t

Re: Java interop question: proxy or gen-class?

2010-04-09 Thread Per Vognsen
On Sat, Apr 10, 2010 at 10:54 AM, Gregg Williams wrote: > Because this new class, ToggleShape, has the added state of > fIsPressed, is it possible to use proxy at all The proxy body can close over the lexical scope: (let [pressed? (ref false)] (proxy [PPath] [] ;; ... (

Re: Symbol resolution (between quote and eval/execution)

2010-04-09 Thread Per Vognsen
On Sat, Apr 10, 2010 at 10:22 AM, Douglas Philips wrote: > On 2010 Apr 9, at 9:04 PM, Per Vognsen wrote: > >> On Sat, Apr 10, 2010 at 7:48 AM, Douglas Philips wrote: >>> >>> Odd: >>>  user=> (binding [m1 (fn [a b] (println "m1 from binding"

Re: Symbol resolution (between quote and eval/execution)

2010-04-09 Thread Per Vognsen
On Sat, Apr 10, 2010 at 7:48 AM, Douglas Philips wrote: > Odd: >  user=> (binding [m1 (fn [a b] (println "m1 from binding" a b))] >                  (eval '(if true (m1 "true" "here") (m1 "false" "there" >  m1 from binding true here >  m1 from binding false there >  nil That doesn't even run

Re: cycles in data cause infinite recursion

2010-04-09 Thread Per Vognsen
Unfortunately the printer doesn't detect cycles, so when you type such code at the REPL, you risk an infinite loop when it tries to print the evaluated value. The ugly work-around is to limit the printer's recursion depth to some small arbitrary number, e.g. (set! *print-level* 5). -Per On Fri, A

Re: mutating multiple java swing components

2010-04-09 Thread Per Vognsen
On Fri, Apr 9, 2010 at 10:39 PM, Josh Stratton wrote: > Here's an example of trying to use "map" to bring the two tables > together together in the same scope.  I'm doing this because the nth > element in one sequence correlates to its nth counterpart in the > second sequence.  mainTables is a seq

Re: ANN: lein-search

2010-04-08 Thread Per Vognsen
Nice! Towards a similar purpose, I wrote a little Emacs hack last week that web-scrapes clojars.org and inserts the artifact declaration at the cursor. Since I had to rely on their search feature, I couldn't do proper regular expression matching. -Per On Fri, Apr 9, 2010 at 11:23 AM, Heinz N. Gie

Re: Symbol resolution (between quote and eval/execution)

2010-04-08 Thread Per Vognsen
On Fri, Apr 9, 2010 at 11:26 AM, Douglas Philips wrote: > On 2010 Apr 8, at 11:48 PM, Per Vognsen wrote: >> >> The body of fn is still compiled in an expression context. When the >> compiler sees (fn [...] ...), it will introduce the bindings into the >> local environm

Re: Symbol resolution (between quote and eval/execution)

2010-04-08 Thread Per Vognsen
On Fri, Apr 9, 2010 at 10:35 AM, Douglas Philips wrote: > On 2010 Apr 8, at 11:16 PM, Per Vognsen wrote: >> >> It's not a defn thing. If you write (do (a) (b) (c)) at the REPL, you >> should see the same exception. > > Yes, I would expect that since at

Re: Symbol resolution (between quote and eval/execution)

2010-04-08 Thread Per Vognsen
On Fri, Apr 9, 2010 at 10:04 AM, Douglas Philips wrote: > I'm trying to understand how the two forms here differ: > > In a fresh repl: > >        user=> '((a) (b) (c)) >        ((a) (b) (c)) > > which is OK, those are just symbols. > > But then: > >        user=> (defn x [] (a) (b) (c)) >        j

Re: iterating over a nested vector

2010-04-08 Thread Per Vognsen
Or you can separate concerns a bit more: (defn transpose [xs] (apply map vector xs)) Now Nurullah's original suggestion applies: (map #(apply max %) (transpose xs)) -Per On Fri, Apr 9, 2010 at 12:38 AM, James Reeves wrote: > On Apr 8, 1:13 pm, John Sanda wrote: >> [ >>   [1 2 3] >>   [2 5

Re: A syntax question: positional & keyword

2010-04-08 Thread Per Vognsen
You can easily code positional keyword parameters yourself. It takes only a few minutes for a basic version. Here's an admittedly not very pretty example: http://gist.github.com/360145 -Per On Thu, Apr 8, 2010 at 9:13 PM, Sophie wrote: > On Apr 7, 7:56 am, David Nolen wrote: >> The runtime cos

Re: question about "into"

2010-04-08 Thread Per Vognsen
ion like this. > It's often useful to execute the offending form step by step, to see > what the result of each computation is. > > Love the REPL. > > Sean > > On Apr 7, 8:45 pm, Per Vognsen wrote: >> The second case is equivalent to (into [] [{:a 1 :b 2}]). You&

Re: question about "into"

2010-04-07 Thread Per Vognsen
The second case is equivalent to (into [] [{:a 1 :b 2}]). You're passing a singleton list containing a single element which happens to be a map. -Per On Thu, Apr 8, 2010 at 7:35 AM, Base wrote: > Hi All - > > I have a question about into. > > When you run the into against a map you get a vector

Re: Proxy and the "do" special form / var question

2010-04-07 Thread Per Vognsen
On Wed, Apr 7, 2010 at 7:40 PM, Alex Osborne wrote: > "msapp...@web.de" writes: > > If it's truly immutable -- you never want to change or reload maps while > game is running and initialize-game only ever gets called once, I'd > personally probably say that's okay. I'd say it's the kind of thing

Re: Mutually-referencing structures

2010-04-06 Thread Per Vognsen
On Tue, Apr 6, 2010 at 10:43 PM, Douglas Philips wrote: > On 2010 Apr 6, at 10:59 AM, Christophe Grand wrote: >> >> The cycles are gone but the identity john-doe aand its curren-state are >> still conflated so you get the same problem: > > Thus, since simple trees have the exact same issues, circu

Re: Mutually-referencing structures

2010-04-06 Thread Per Vognsen
On Tue, Apr 6, 2010 at 9:59 PM, Christophe Grand wrote: > Btw, to some extent, one can create cyclic data-structures in Clojure (only > lazyseqs though -- unless you implement your own map or use lazy-map etc.) : > user=> (defn cyclic-seq [coll] (let [s (promise)] @(deliver s (lazy-cat coll > @s))

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
It's no more mutable than a pure lambda calculus with lazy evaluation. There is no _observable_ mutability. Anything else is an implementation detail. Single assignment comes from the tradition of logic programming and concurrent process calculus rather than lambda calculus. A single assignment va

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
ject graph traverser to find all references to a given object (e.g. gc.get_referrers() in Python) and then rewire those references on the fly. -Per On Mon, Apr 5, 2010 at 9:17 PM, Douglas Philips wrote: > On 2010 Apr 5, at 9:43 AM, Per Vognsen wrote: >> >> I already mentioned this in my or

Re: Set performance

2010-04-05 Thread Per Vognsen
I looked at the source code. ImmutableSet doesn't support adding adding or removing elements incrementally. You can make an ImmutableSet.Builder from an existing ImmutableSet of n elements and then make a batch of m updates from which it will construct a new ImmutableSet in O(n+m) time. It simply i

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
On Mon, Apr 5, 2010 at 8:24 PM, Michael Gardner wrote: > On Apr 5, 2010, at 7:49 AM, Sophie wrote: > >> Is this a Clojure restriction, or is it intrinsic to functional >> programming? > > It's a consequence of immutable data structures, which are an aspect of > functional programming. An immutabl

Re: Reorder a list randomly?

2010-04-05 Thread Per Vognsen
e past. > > Also, I'd reverse the arg order of with-transient.  I think > > (with-transient f x) > > reads easier.  Also, it should probably end with a bang, because I > don't think it's safe in the STM. > > Great work guys. > > Sean > > On Ap

Re: Mutually-referencing structures

2010-04-05 Thread Per Vognsen
You need a level of indirection. One way is to make the backward reference from accounts to owners be based on a non-pointer primary key (maybe a keyword) that can be resolved through some table. This is how it works in relational database systems If you want to use references of some sort, mutabi

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
version of my code. The code itself is only three lines; the rest consists of very general purpose utilities that I find myself using again and again. http://gist.github.com/356035 -Per >  -Lee > > On Apr 5, 2010, at 12:11 AM, Per Vognsen wrote: > >> Wow, you're right. The p

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
Wow, you're right. The partial laziness of his code was foiling my benchmark. -Per On Mon, Apr 5, 2010 at 11:05 AM, Mark Engelberg wrote: > On my system, knuth-shuffle performs several times faster than Spector's > recursive functional shuffle on smallish lists, and the difference grows > even m

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
>    (let [index (rand-int (count lst)) >          item (nth lst index) >          remainder (concat (subvec (into [] lst) 0 index) >                            (subvec (into [] lst) (inc index)))] >      (cons item (shuffle remainder) > >  -Lee > > On Apr 4, 2010, at 1

Re: Reorder a list randomly?

2010-04-04 Thread Per Vognsen
The seq-utils library has a shuffle function that calls out to java.util.Collections. If you want to do it yourself, the easiest would be (defn naive-shuffle [xs] (let [v (vec xs)] (->> (count v) range lex-permutations rand-elt (map v This uses the seq-utils and combinatorics libraries

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

2010-04-04 Thread Per Vognsen
5, 2010 at 1:34 AM, Bob Hutchison wrote: > > On 2010-04-04, at 11:15 AM, Per Vognsen wrote: > >> Interesting question. Here's something I whipped up in response: >> >> http://gist.github.com/355456 >> >> I intentionally provide only lazy-alter and no laz

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

2010-04-04 Thread Per Vognsen
Interesting question. Here's something I whipped up in response: http://gist.github.com/355456 I intentionally provide only lazy-alter and no lazy-ref-set. The reason is that lazy-alter can be coded so that all the unwrapping and rewrapping of delays can be abstracted away from the user-provided

Re: fn? question

2010-04-04 Thread Per Vognsen
(map #(fn? (when-let [x (resolve (symbol %))] @x)) ["map", "first", "nofun"]) should do the trick. But before you go ahead and do this, make sure it's what you actually need. -Per On Sun, Apr 4, 2010 at 3:06 PM, Manfred Lotz wrote: > Hi there, > > I can ask if something is an fn, like this: (fn?

Re: STM and Garbage Collection

2010-04-03 Thread Per Vognsen
You talk of transactions, "persistent in-memory" and garbage collection. Are you sure you understand what persistence means here? It's a matter of efficient structural sharing of data structures rather than persistence in the database sense. -Per On Sat, Apr 3, 2010 at 9:13 PM, David R. Smith wr

Re: STM and Garbage Collection

2010-04-03 Thread Per Vognsen
They are not completely orthogonal. In fact they work well together. One of the core assumptions in generational garbage collection is that data in higher generations rarely grow pointers to data in lower generations. This is often true in imperative programs. But absent implicit mutation in the f

Statically scoped first-class labels with dynamic extent

2010-04-03 Thread Per Vognsen
Lazy data flow via sequences is a superior substitute for imperative control flow. But sometimes unrestrained control flow is convenient. Here's a proof of concept that provides statically scoped first-class labels with dynamic extent: http://gist.github.com/354676 The lexically scoped atom trick

Re: holding types or units in metadata vs pattern matching

2010-04-03 Thread Per Vognsen
rewrap the results in the newtype wrapper. (Clojure's arithmetic tower isn't expressible via protocol-style single dispatch, so this is vastly simplified, but you get the idea.) -Per On Sat, Apr 3, 2010 at 3:18 PM, Per Vognsen wrote: > Unfortunately you can only attach metad

Re: holding types or units in metadata vs pattern matching

2010-04-03 Thread Per Vognsen
Unfortunately you can only attach metadata to types that implement the IObj interface. That excludes native Java types like Integer and Float: user=> (with-meta 42 {:foo 42}) java.lang.ClassCastException: java.lang.Integer (NO_SOURCE_FILE:0) user=> (with-meta 42.0 {:foo 42}) java.lang.ClassCastExc

Re: REPL and its command prompt

2010-04-02 Thread Per Vognsen
Well, while I don't like it much, there are in fact REPLs that work the way he expects, e.g. SBCL's: This is SBCL 1.0.24, an implementation of ANSI Common Lisp. More information about SBCL is available at . SBCL is free software, provided as is, with absolutely no warranty.

Re: "," is REAL whitespace...

2010-04-02 Thread Per Vognsen
tion.  But not so weird that it's not useful, > mostly for separating key/value pairs from other key/value pairs in a map. >  It's like Perl's "fat comma" arrow operator in that sense - syntactically > no different from comma, but stylistically helpful. > > On

Re: REPL and its command prompt

2010-04-02 Thread Per Vognsen
In most character-buffered REPLs the enter key serves two purposes: quoting a new line character and submitting input to the REPL. Some systems like Mathematica require a special key combination like shift-enter or control-enter to submit input. That is a clean separation of concerns but it is awfu

Re: "," is REAL whitespace...

2010-04-01 Thread Per Vognsen
It doesn't feel right only if you still think you are programming in an Algol-style language where , is a separator token. I can't imagine this is going to change. -Per On Fri, Apr 2, 2010 at 12:37 PM, Frank Siebenlist wrote: > Even though the specs clearly say that commas are whitespace, the f

Re: characters permitted in symbols??

2010-04-01 Thread Per Vognsen
-Per On Thu, Apr 1, 2010 at 4:02 PM, Meikel Brandmeyer wrote: > Hi, > > On Apr 1, 10:42 am, Per Vognsen wrote: > >> Are you serious? It is neither complete nor consistent. How can it be >> authoritative? > > The list is by definition complete and consistent. Use ch

Re: characters permitted in symbols??

2010-04-01 Thread Per Vognsen
On Thu, Apr 1, 2010 at 12:29 PM, Meikel Brandmeyer wrote: > Hi, > > On Apr 1, 6:58 am, Douglas Philips wrote: > >> According to:http://clojure.org/reader >> Symbols begin with a non-numeric character and can contain >> alphanumeric characters and *, +, !, -, _, and ? (other characters >> will be

Infixup: DWIM hoisting and splicing in the reader

2010-03-31 Thread Per Vognsen
I spent the last few days sick in bed in a Jakarta hotel room without any Internet. What little lucidity I had was spent on odd hacks. One of them was particularly neat or particularly nasty depending on your perspective. It is a reader extension for list hoisting and splicing. You can write (a `b

Re: concurrency and rand-int

2010-03-26 Thread Per Vognsen
On Fri, Mar 26, 2010 at 9:55 AM, Chas Emerick wrote: > Hi Lee, > > Indeed -- from the docs for Math.random(): > > "This method is properly synchronized to allow correct use by more than one > thread. However, if many threads need to generate pseudorandom numbers at a > great rate, it may reduce co

Re: Choosing a Clojure build tool

2010-03-25 Thread Per Vognsen
On Fri, Mar 26, 2010 at 12:59 PM, Chas Emerick wrote: > > On Mar 26, 2010, at 12:59 AM, Per Vognsen wrote: > >> On Fri, Mar 26, 2010 at 11:50 AM, Chas Emerick >> wrote: >>> >>> Because they're common processes that are ideally built once, and then >

  1   2   >