Problem reading record instances

2010-04-30 Thread Praki
I am unable to read-string record instances produced by pr-str. user> (defrecord Z [x y]) user.Z user> (read-string (pr-str (Z. 1 2))) ; Evaluation aborted. The exception is: java.lang.Exception: No dispatch macro for: : [Thrown class java.lang.RuntimeException] However, struct instances are

rand-int with bignums

2010-04-30 Thread Lee Spector
In an earlier thread, in which I learned (from Timothy Pratley) that (. (new java.util.Random) X) gives an error if X is a bignum, I said that at least Clojure's rand-int "does the right thing." Upon further investigation I see that this is only true in the sense that it doesn't produce an err

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
0On Fri, Apr 30, 2010 at 8:41 PM, Michał Marczyk wrote: > That will overflow the stack when you do, say, > > (last (apply pairup (range 2))) > > That can be fixed by wrapping (cons ...) in lazy-seq. > Sure. Laziness good. Another version: > > (defn pairup [& args] > (map vector args (re

Re: something stupid I'm trying to do

2010-04-30 Thread Michał Marczyk
On 30 April 2010 18:25, Mark J. Reed wrote: > (defn pairup >     ([a b] (list [a b])) >     ([a b & rest]   (cons [a b] (apply pairup rest That will overflow the stack when you do, say, (last (apply pairup (range 2))) That can be fixed by wrapping (cons ...) in lazy-seq. Another versio

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
Ok, so I was right the first time. It think it's past everyone's bedtime. :) On Fri, Apr 30, 2010 at 5:49 PM, Douglas Philips wrote: > On 2010 Apr 30, at 5:45 PM, Mark J. Reed wrote: > >> Of course. Which is what I would have done automatically with a >> Lispier construct. Just still not used

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread ataggart
Clojure embraces this "laziness": user=> (get #{:foo :bar} :foo) :foo 'get uses a "key" to return a "value". A vector is not a map is not a set, but all of them can have their values accessed in constant-time using a "key". On Apr 30, 3:14 pm, "Steven E. Harris" wrote: > Phil Hagelberg write

Re: something stupid I'm trying to do

2010-04-30 Thread Michael Wood
On 30 April 2010 23:49, Douglas Philips wrote: > On 2010 Apr 30, at 5:45 PM, Mark J. Reed wrote: >> >> Of course.  Which is what I would have done automatically with a >> Lispier construct. Just still not used to seeing literal vectors as >> functions.  :) >> >> On Friday, April 30, 2010, Michael

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Steven E. Harris
Phil Hagelberg writes: > Actually I do consider sets to have keys, since internally they are > implemented using maps, so the exact same semantics apply for their > lookup. They're just maps where the key and value are the same thing: But that implementation is one of convenience, of possibly ad

Re: something stupid I'm trying to do

2010-04-30 Thread Douglas Philips
On 2010 Apr 30, at 5:45 PM, Mark J. Reed wrote: Of course. Which is what I would have done automatically with a Lispier construct. Just still not used to seeing literal vectors as functions. :) On Friday, April 30, 2010, Michael Wood wrote: Well, you didn't *have* to call list. You could hav

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
Of course. Which is what I would have done automatically with a Lispier construct. Just still not used to seeing literal vectors as functions. :) On Friday, April 30, 2010, Michael Wood wrote: > On 30 April 2010 18:25, Mark J. Reed wrote: > [...] >> (defn pairup >>     ([a b] (list [a b])) >>

Re: something stupid I'm trying to do

2010-04-30 Thread Michael Wood
On 30 April 2010 18:25, Mark J. Reed wrote: [...] > (defn pairup >     ([a b] (list [a b])) >     ([a b & rest]   (cons [a b] (apply pairup rest > I got an error when I tried ([a b]) instead of (list [a b]), by the way: > Clojure 1.1.0 > user=> (cons [1 2] ([3 4])) > java.lang.IllegalArgumen

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Sophie
On Apr 29, 3:21 am, ataggart wrote: > Functions named contains-key? and contains-val? would make a lot more > sense to me than the current contains? and new seq-contains?. Amen. Even independent of any performance expectations. -- You received this message because you are subscribed to the Go

Re: defrecord question

2010-04-30 Thread Jarkko Oranen
On Apr 30, 9:46 pm, russellc wrote: > Should this compile? > > (defprotocol P (p [this])) > (defrecord R [k] P (p [{:keys [k]}] k)) > > java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot > be cast to clojure.lang.Symbol defrecord doesn't yet support destructuring as far as I k

labrepl updated

2010-04-30 Thread Stuart Halloway
I have updated the labrepl [1] to use the latest clojure 1.2 and contrib 1.2 snapshots. Also, most of the dependencies are now frozen to specific snapshot timestamps (the project.clj file may be of interest to people living on the development edge). After a "lein clean; lein deps" everythi

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Michael Gardner
On Apr 30, 2010, at 6:33 AM, Rich Hickey wrote: > Would contains-val? be fast for sets? As a user of sets, I consider them > collections of values, and I absolutely would reach for contains-val? in any > library that had it, for use with sets. If so, and I used contains-val?, and > I moved cod

Re: defrecord question

2010-04-30 Thread Sean Devlin
Oh, wait, my bad... you're getting the keyword args special destructuring. i.e., you're telling Clojure to expect a map and store the appropriate keys in the proper symbols user=> ((fn [{:keys [k]}] (str k)) {:k "Awesome" :l "Beer"}) "Awesome" user=> ((fn [{:keys [k l]}] (str k l)) {:k "Awesome"

Re: defrecord question

2010-04-30 Thread Russell Christopher
Why does this work? (defrecord R [k]) (extend-protocol P R (p [{:keys [k]}] k)) On Fri, Apr 30, 2010 at 2:52 PM, Sean Devlin wrote: > I think you have your destructuring backwards. > > You fn should probably be (fn [{k :keys}] k) > > For example, > > user=> ((fn [{k :keys}] k) {:keys "Awesome"})

Re: defrecord question

2010-04-30 Thread Sean Devlin
I think you have your destructuring backwards. You fn should probably be (fn [{k :keys}] k) For example, user=> ((fn [{k :keys}] k) {:keys "Awesome"}) "Awesome" On Apr 30, 2:46 pm, russellc wrote: > Should this compile? > > (defprotocol P (p [this])) > (defrecord R [k] P (p [{:keys [k]}] k))

defrecord question

2010-04-30 Thread russellc
Should this compile? (defprotocol P (p [this])) (defrecord R [k] P (p [{:keys [k]}] k)) java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.Symbol -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to th

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Douglas Philips
On 2010 Apr 30, at 7:33 AM, Rich Hickey wrote: > People don't consider sets, vectors, arrays or strings to have 'keys'. That is not consistent with the documentation: Sets: http://clojure.org/data_structures: Sets support 'removal' with disj, as well as contains? and get, the latter returni

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread ataggart
On Apr 30, 4:33 am, Rich Hickey wrote: > People don't consider sets, vectors, arrays or strings to have 'keys'.   > But, like maps, they all support fast lookup of some sort. But of course we do. I point to the doc for contains? and get: Usage: (contains? coll key) Returns true if key is prese

Re: clojure box: Problem with classpath (noob question)

2010-04-30 Thread Shawn Hoover
On Thu, Apr 29, 2010 at 6:58 PM, Rainer wrote: > Hello, > > I'm stuck with "Programming Clojure" on page 37 on a Windows 7 > machine. After downloading the "examples" dir into "C:/clojure", I > typed: > > user> (require 'examples.introduction) > > and I got > > ; Evaluation aborted. > > java.io.F

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Mark Engelberg
On Fri, Apr 30, 2010 at 5:18 AM, Laurent PETIT wrote: > While it sounds soo evident now that you say that explicitly ( the > contains? / get pair ), it may be good to reflect that in the docs of > the functions rather than just keep this knowledge here ? Agreed. This explanation of the relations

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
On Fri, Apr 30, 2010 at 12:25 PM, Mark J. Reed wrote: > I got an error when I tried ([a b]) instead of (list [a b]), by the way: > > Clojure 1.1.0 > user=> (cons [1 2] ([3 4])) > java.lang.IllegalArgumentException: Wrong number of args passed to: > PersistentVector (NO_SOURCE_FILE:0) > To be cle

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
Sorry, let me try answering your questions instead of just proposing an alternative. :) As written, your base case and your recursive call are inconsistent. If you want (pairup 1 2 3 4) to return ([1 2] [3 4]), then you need to wind up calling (cons [1 2] [[3 4]]). What you're calling instead is

Re: what is wrong with (use `clojure.contrib.string) ?

2010-04-30 Thread gary ng
On Thu, Apr 29, 2010 at 10:43 PM, David Nolen wrote: > My rule of thumb is: > > use + :only > require + :as > > I believe this should be documented as the 'suggested usage'. As contrary to Python where 'from module import *'(which is 'use' in clojure) is right in there saying 'you know what you ar

Re: something stupid I'm trying to do

2010-04-30 Thread Sean Devlin
I'd use the built-in, partition user=> (partition 2 (range 1 9)) ((1 2) (3 4) (5 6) (7 8)) And add a mapping operation user=> (map vec (partition 2 (range 1 9))) ([1 2] [3 4] [5 6] [7 8]) Am I missing a requirement? On Apr 30, 11:55 am, "Mark J. Reed" wrote: > I think you want this: > >  

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Phil Hagelberg
On Fri, Apr 30, 2010 at 4:33 AM, Rich Hickey wrote: > On Apr 29, 2010, at 4:21 AM, ataggart wrote: >> Functions named contains-key? and contains-val? would make a lot more >> sense to me than the current contains? and new seq-contains?.  Anyone >> looking at contains-val? should expect it to be O(

Re: Defining a namespace inside a let

2010-04-30 Thread Stuart Sierra
"ns" and "in-ns" have special evaluation rules. In general, they don't work as you'd expect in block expressions such as "do" or "let". If you want to create namespaces programatically, use "create-ns" and "intern". -SS On Apr 26, 6:25 pm, David McNeil wrote: > I am experimenting with clojure

Re: what is wrong with (use `clojure.contrib.string) ?

2010-04-30 Thread Stuart Sierra
On Apr 30, 1:43 am, David Nolen wrote: > My rule of thumb is: > > use + :only > require + :as Yes. clojure.contrib.string deliberately has short function names, which means there is some overlap with clojure.core. Note: (use '[clojure.contrib.string :as st :only ()]) also works. -SS -- You r

Re: something stupid I'm trying to do

2010-04-30 Thread Mark J. Reed
I think you want this: (defn pairup [a b & rest] (cons [a b] (if rest (apply pairup rest) []))) On Thu, Apr 29, 2010 at 3:32 PM, john.holland wrote: > I'm pounding my head against the wall trying to understand how to do a > simple task. What I want to do is write a function that will take a >

Re: Agents, eval, quasi-quote & closures

2010-04-30 Thread Sean Devlin
Okay, found a fix do my own bug. You can use the with-ns namespace to solve this issue. I changed the form to be like this: (send test-result (fn [& args] (with-ns 'my-ns (eval `(->> ~@(deref test-query)) FYI On Apr 29, 5:09 pm, Sean Devlin wrote: > Right... > Is there a way to force an

Fwd: clojure box: Problem with classpath (noob question)

2010-04-30 Thread Rainer Wolf
Hello, yesterday, I sent my noob question about the classpath to the group. So far, my message has not shown up yet. Could you please post my message to the Clojure group? Thank you in advance. Kind regards, Rainer Wolf -- Forwarded message -- From: Rainer Date: Fri, Apr 30, 20

Re: Newbie: Finding performance bottlenecks

2010-04-30 Thread msappler
I fixed my bottleneck-finding problem by applying the right jvisualvm parameters. You say: >It's discouraged to use the mutable reference types in a fine-grained way >like this. I would recommend changing your code to just be a vector of >Clojure PersistentMaps that you map over. What do you mea

protocols metadata

2010-04-30 Thread Andrea Tortorella
Hi everyone, Reading the documentation I found that except for the docstring there is no way to tell that InternalReduce is a protocol, it's tagged simply as a var. Why don't add a :protocol true to the metadata for protocols like :macro true for macros? Andrea. -- You received this message bec

clojure box: Problem with classpath (noob question)

2010-04-30 Thread Rainer
Hello, I'm stuck with "Programming Clojure" on page 37 on a Windows 7 machine. After downloading the "examples" dir into "C:/clojure", I typed: user> (require 'examples.introduction) and I got ; Evaluation aborted. java.io.FileNotFoundException: Could not locate examples/ introduction__init.cl

something stupid I'm trying to do

2010-04-30 Thread john.holland
I'm pounding my head against the wall trying to understand how to do a simple task. What I want to do is write a function that will take a even-numbered set of numbers and split them into pairs. What I have right now is the following user> (defn pairup ([a b] [a b])([a b & rest] (cons (pairup

Re: Defining a namespace inside a let

2010-04-30 Thread Armando Blancas
In a clean repl: C:\>repl Clojure 1.2.0-master-SNAPSHOT user=> (println (do (ns ns-1) (def my-namespace *ns*) my-namespace)) # nil ns-1=> On Apr 30, 1:17 am, alux wrote: > Hello Armando, did you try the second half of you experiment in a > clean REPL? > > As you describe it, the first evaluation

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Christophe Grand
Hi, On Thu, Apr 29, 2010 at 7:48 AM, Meikel Brandmeyer wrote: > > On 29 Apr., 01:38, Mark Engelberg wrote: > > > 1. Don't include seq-contains? The behavior you want can usually be > > achieved by using (some #{item} coll). Disadvantage - if you're > > testing to see if the collection contains

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Stephen C. Gilardi
On Apr 29, 2010, at 2:19 PM, MarkSwanson wrote: > On Apr 29, 4:21 am, ataggart wrote: >> I know it won't matter, but for posterity if nothing else... >> >> Functions named contains-key? and contains-val? would make a lot more >> sense to me than the current contains? and new seq-contains?. Any

Re: labrepl: kl...@feersum:~/projects/labrepl$ script/repl java.lang.ExceptionInInitializerError (control.clj:9)

2010-04-30 Thread Stuart Halloway
I will check in a fix later this morning. Stu klang writes: laprepl starts up with the following error and localhost:8080 does not respond kl...@feersum:~/projects/labrepl$ script/repl Clojure 1.2.0-master-SNAPSHOT java.lang.ExceptionInInitializerError (control.clj:9) Looks like labrepl

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Laurent PETIT
2010/4/30 Rich Hickey : > > On Apr 29, 2010, at 4:21 AM, ataggart wrote: > >> I know it won't matter, but for posterity if nothing else... >> >> Functions named contains-key? and contains-val? would make a lot more >> sense to me than the current contains? and new seq-contains?.  Anyone >> looking

Re: Beginner's question regarding implementing a constructor using gen-class

2010-04-30 Thread Adrian Cuthbertson
> simple, you'd be embarrassed to admit that you didn't see WHAT WAS > STARING YOU IN THE FACE all along? Don't be too hard on yourself - it takes a while for the clojure patterns to sink in so you easily spot the simple errors. Best to throw it out there so someone else can help. Gen-class is a

Re: clojure 1.2 seq fn enhancement FAQ

2010-04-30 Thread Rich Hickey
On Apr 29, 2010, at 4:21 AM, ataggart wrote: I know it won't matter, but for posterity if nothing else... Functions named contains-key? and contains-val? would make a lot more sense to me than the current contains? and new seq-contains?. Anyone looking at contains-val? should expect it to be

Re: Does clojure.contrib.io.slurp work with binary files?

2010-04-30 Thread Matt Culbreth
Ok great, thanks guys. Exactly what I needed. On Apr 30, 12:12 am, Alex Osborne wrote: > Hi Matt, > > Matt Culbreth writes: > > I'm using slurp to read data from a file and send it to a stream, but > > sometimes that's failing.  I've got a theory that it has to do with > > slurp not reading bin

Re: labrepl: kl...@feersum:~/projects/labrepl$ script/repl java.lang.ExceptionInInitializerError (control.clj:9)

2010-04-30 Thread Alex Osborne
klang writes: > laprepl starts up with the following error and localhost:8080 does not > respond > > kl...@feersum:~/projects/labrepl$ script/repl > Clojure 1.2.0-master-SNAPSHOT > java.lang.ExceptionInInitializerError (control.clj:9) Looks like labrepl is not locked to a particular version of Cl

Re: what is wrong with (use `clojure.contrib.string) ?

2010-04-30 Thread Heinz N. Gies
On Apr 30, 2010, at 9:15 , ataggart wrote: > > > On Apr 29, 10:43 pm, David Nolen wrote: >> My rule of thumb is: >> >> use + :only >> require + :as > > > (inc *1) (inc *1) (conj *2 " Also use is handy for your own nameslaces, if you've a project that consists out of more then one to help y

Re: Defining a namespace inside a let

2010-04-30 Thread alux
Hello Armando, did you try the second half of you experiment in a clean REPL? As you describe it, the first evaluation may have created the var. Regards, alux On 29 Apr., 21:32, Armando Blancas wrote: > > The REPL switches to the namespace ns-1 and the var my-namespace is in > > user ! > > > I

Re: Beginner's question regarding implementing a constructor using gen-class

2010-04-30 Thread Meikel Brandmeyer
Hi, On 30 Apr., 08:16, Gregg Williams wrote: > And what's with the slashes in "[java/lang/Object]"--I've never seen > that before. Alex wrote you before: :extends does not take a vector. Ad your constructor question: see :post-init. Sincerely Meikel -- You received this message because you