Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Carson
I should add, "oops, ignore what I wrote". :) see: https://groups.google.com/group/clojure/tree/browse_frm/thread/33366bccc6df7756/415072576d83b757?rnum=11&_done=%2Fgroup%2Fclojure%2Fbrowse_frm%2Fthread%2F33366bccc6df7756%3F#doc_0d0a3759a0a10328 Carson On Jul 17, 3:58 pm, Carson wrote: > Hi, T

Re: Response

2010-07-17 Thread Carson
Hi Per, woh, take it easy. I don't claim to be an expert. Thanks for showing me that though. It certainly didn't seem right at first, but I had trouble figuring out the laziness in clojure, me being new to it. Anyway, have a good weekend! Carson On Jul 17, 10:02 pm, Per Vognsen wrote: > How a

Re: persistent LRU cache (request for input)

2010-07-17 Thread ataggart
This might be of related interest: http://kotka.de/blog/2010/03/The_Rule_of_Three.html On Jul 17, 3:19 pm, Peter Schuller wrote: > Another thing occurred to me: While not necessarily important in the > cache of an LRU cache, one might want a data structure, even if it > tends to be used in a side

Re: clojure.string namespace missing from API page?

2010-07-17 Thread Adrian Cuthbertson
Yes, sorry, my post referred to the source, not the online doc API. Perhaps someone else can answer regarding that? On Sat, Jul 17, 2010 at 5:58 PM, Btsai wrote: > Thank you Adrian.  I did see in the release announcement thread that > that is the new source site for 1.2.  However, I was unable to

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: Why does using a dynamic binding make a function impure?

2010-07-17 Thread Brisance
Interestingly, the results are different for me. ; SLIME 2010-05-01 user> (def *forty-two* 42) #'user/*forty-two* user> (defn impure-add42 [n] (+ n *forty-two*)) #'user/impure-add42 user> (impure-add42 1) 43 user> (binding [*forty-two* 23] (impure-add42 1)) 24 On Jul 18, 7:14 am, Moritz Ulrich w

Re: Response

2010-07-17 Thread Carson
Thanks David. On Jul 17, 4:58 pm, David Nolen wrote: > I tried this, it runs in about the same amount of time as it did for you. > > On Sat, Jul 17, 2010 at 7:17 PM, Carson wrote: > > Hi David, > > Would appreciate if you could try out my attempt at this [1] on your > > machine.  My machine ain'

Re: Response

2010-07-17 Thread Carson
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 functional and pretty fast. Turns out it can be even faster with

The role of type hints with deftype and defrecord fields...

2010-07-17 Thread Eric Thorsen
I notice that only certain type hints turn into concrete java types in the signature of the genned constructors and field definitions (such as int and float) where as string, date, etc. turn into Objects. Do these other type hints just get discarded/ignored? Thanks, Eric -- You received this mes

Re: Response

2010-07-17 Thread Frederick Polgardy
I think it really doesn't get any clearer than this in terms of intent. While I was adept at calculus-level math 20 years ago, I've forgotten the little I knew of matrices. This is the first algorithm that has communicated by visual inspection (to me) exactly what a convolution is. -Fred -- Sc

Re: Response

2010-07-17 Thread Carson
Have you taken a look at my attempt at a solution (on the other/ original thread)? https://groups.google.com/group/clojure/tree/browse_frm/thread/ee4169bc292ab572/6d03461efde166ad?rnum=11&_done=%2Fgroup%2Fclojure%2Fbrowse_frm%2Fthread%2Fee4169bc292ab572%3F#doc_6d03461efde166ad I don't know if it

Re: Response

2010-07-17 Thread Frederick Polgardy
This example is beside the point of the original question. It uses mutable arrays. It's very much dropping to the Java level. Am I missing something? -Fred -- Science answers questions; philosophy questions answers. On Jul 17, 2010, at 6:04 PM, David Nolen wrote: > (defn ^{:static true} convol

Re: Response

2010-07-17 Thread j-g-faustus
On 17 Jul, 22:43, Isaac Hodes wrote: > It's just a shame, it seems to me, that there is such a nice way to > represent the procedure in Python or even C, yet Clojure (or any Lisp > really) struggles to idiomatically answer this question of > convolution. I'll have to disagree with the conclusion.

Re: Response

2010-07-17 Thread David Nolen
I tried this, it runs in about the same amount of time as it did for you. On Sat, Jul 17, 2010 at 7:17 PM, Carson wrote: > Hi David, > Would appreciate if you could try out my attempt at this [1] on your > machine. My machine ain't as fast as yours apparently... > > [1] > > https://groups.googl

Re: Response

2010-07-17 Thread Carson
Hi David, Would appreciate if you could try out my attempt at this [1] on your machine. My machine ain't as fast as yours apparently... [1] https://groups.google.com/group/clojure/tree/browse_frm/thread/ee4169bc292ab572/6d03461efde166ad?rnum=11&_done=%2Fgroup%2Fclojure%2Fbrowse_frm%2Fthread%2Fee4

Re: Why does using a dynamic binding make a function impure?

2010-07-17 Thread Moritz Ulrich
(def *forty-two* 42) (defn impure-add42 [n] (+ n *forty-two*)) (impure-add42 1) => 43 (binding [*forty-two* 23] (impure-add42 1)) => 65 On Sun, Jul 18, 2010 at 12:57 AM, Laurent PETIT wrote: > Hi, > > 2010/7/17 Paul Richards >> >> The "Programming Clojure" book states: "Functions that use

Re: Response

2010-07-17 Thread Michael Gardner
On Jul 17, 2010, at 3:43 PM, Isaac Hodes wrote: > It's just a shame, it seems to me, that there is such a nice way to > represent the procedure in Python or even C, yet Clojure (or any Lisp > really) struggles to idiomatically answer this question of > convolution. No, it's pretty easy to do conv

Re: Response

2010-07-17 Thread David Nolen
(defn ^{:static true} convolve ^doubles [^doubles xs ^doubles is] (let [xlen (count xs) ilen (count is) ys (double-array (dec (+ xlen ilen)))] (dotimes [p xlen] (dotimes [q ilen] (let [n (+ p q), x (aget xs p), i (aget is q), y (aget ys n)] (aset ys n

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Carson
Hi, Try this: (defn stationary-convolve [n fs gs] (let [window-size (count fs) padding (repeat window-size 0) padded-gs (concat padding gs padding) new-center (+ n window-size) window-of-gs (subvec (vec padded-gs) (- (inc new-center) w

Re: Why does using a dynamic binding make a function impure?

2010-07-17 Thread Laurent PETIT
Hi, 2010/7/17 Paul Richards > The "Programming Clojure" book states: "Functions that use dynamic > bindings are not pure functions.." (P2.0, page 174). > > I do not understand why this must be the case, can someone explain why? > Because then the result of the function does not *only* depend o

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread David Cabana
I thought this problem was interesting enough to merit better treatment than I can give it here, hence a blog post was in order. Brief version: I think I have a lazy, functional, and idiomatic implementation with decent performance. Check it out here: http://erl.nfshost.com/2010/07/17/discrete-co

Response

2010-07-17 Thread Isaac Hodes
Thanks everyone for the input! I've also got some nice replies on Stack Overflow – there's some sort of a discussion there as well. I thought I'd add my voice to the crowd. First off, purely imperative C is fairly elegant itself. I've made it a simple function (along with the Python version on the

Re: clojure.string namespace missing from API page?

2010-07-17 Thread Btsai
Thank you Adrian. I did see in the release announcement thread that that is the new source site for 1.2. However, I was unable to find an online API there. http://richhickey.github.com/clojure/ is the only online API I have seen. And again, the other new 1.2 namespaces like clojure.java.io show

deftype and extend-protocol syntax

2010-07-17 Thread Vadim Shender
The ways to define methods with different arities in deftype and extend-type syntactically differ: (deftype Foo [] P (bar [x] x) (bar [x y] (+ x y))) (extend-type Foo P (bar ([x] x) ([x y] (+ x y Is this inconsistence deliberate decision? -- You received this message becau

Why does using a dynamic binding make a function impure?

2010-07-17 Thread Paul Richards
The "Programming Clojure" book states: "Functions that use dynamic bindings are not pure functions.." (P2.0, page 174). I do not understand why this must be the case, can someone explain why? PS. I tried to post this on the discussion page for the book (http://forums.pragprog.com/forums/91), b

Re: persistent LRU cache (request for input)

2010-07-17 Thread Peter Schuller
Another thing occurred to me: While not necessarily important in the cache of an LRU cache, one might want a data structure, even if it tends to be used in a side-effectful manner, to participate in STM co-ordinated transactions. If one hides an underlying ref, this means that either callers do not

Re: persistent LRU cache (request for input)

2010-07-17 Thread Peter Schuller
> Assuming there is a legitimate need for a persistent data structure > (such as for concurrent background introspection purposes), what would > be your favored approach in terms of an interface? I should clarify that no, I'm not really willing to use a state monad since I'm trying to figure out t

Re: persistent LRU cache (request for input)

2010-07-17 Thread Peter Schuller
>>   lru-peak -> [value] > > I take it you meant "peek", not "peak". Yes - Yes. How embarrassing ;) Thanks. >> One possibility I was thinking of was that, since the expected use >> case of an LRU cache is so specific, it may be acceptable to have the >> lru "library" itself provide a side-effect

Re: persistent LRU cache (request for input)

2010-07-17 Thread Steven E. Harris
Peter Schuller writes: > lru-peak -> [value] I take it you meant "peek", not "peak". [...] > One possibility I was thinking of was that, since the expected use > case of an LRU cache is so specific, it may be acceptable to have the > lru "library" itself provide a side-effect aware interface

persistent LRU cache (request for input)

2010-07-17 Thread Peter Schuller
Hello, I wrote a persistent LRU cache, but I'm not sure I am satisfied with the interface in particular (and perhaps the implementation). It's at: http://github.com/scode/plru git://github.com/scode/plru.git (Btw in general I'd appreciate any feedback - especially negative about the implem

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread James Reeves
On 17 July 2010 18:41, David Cabana wrote: > I tried to run Jame's code, but the compiler (1.2 beta) squawked at me: > Unable to resolve symbol: indexed in this context >  [Thrown class java.lang.Exception] > > What do I need to pull in to pick up the "indexed" function? Sorry, I should have ment

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Wilson MacGyver
It's in contrib.seq-utils http://richhickey.github.com/clojure-contrib/seq-utils-api.html#clojure.contrib.seq-utils/indexed On Jul 17, 2010, at 1:41 PM, David Cabana wrote: > I tried to run Jame's code, but the compiler (1.2 beta) squawked at me: > Unable to resolve symbol: indexed in this con

Re: defrecord with identity as an equality semantic

2010-07-17 Thread Nicolas Oury
More specifically, I am trying to build Hash Consed trees whose nodes are records. http://en.wikipedia.org/wiki/Hash_consing This is a necessary step in a lot of algorithms. It is a benefit of being principled about not mutating values. And it can not be implemented, without overriding hashCode

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread David Cabana
I tried to run Jame's code, but the compiler (1.2 beta) squawked at me: Unable to resolve symbol: indexed in this context [Thrown class java.lang.Exception] What do I need to pull in to pick up the "indexed" function? On Sat, Jul 17, 2010 at 5:08 AM, James Reeves wrote: > Perhaps something lik

Re: defrecord with identity as an equality semantic

2010-07-17 Thread Nicolas Oury
Well. I totally agree that value equality is the correct approach. And I am very happy it is the default. But, in some situations, you want to have accessors but do want to have identity as an equality. You cannot use identical? in Clojure data structures, for example. I am in a situation where

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Frederick Polgardy
This statement is interesting. Part of what makes the Python implementation so expressive is precisely the use of functional constructs like list comprehensions, ranges, and all the awesome stuff in itertools. A purely imperative implementation would probably be as clunky as the purely functiona

Re: defrecord with identity as an equality semantic

2010-07-17 Thread ataggart
No. Use identical? if you want to test for object identity. IIRC Rich commented that the inability to override equals/hashCode was intentional as value equality was the correct approach. See http://clojure.org/state On Jul 17, 7:00 am, Nicolas Oury wrote: > Dear all, > > I was wondering if th

Re: Clojure 1.2 Beta 1

2010-07-17 Thread Jeffrey Schwab
On 7/17/10 5:50 AM, Meikel Brandmeyer wrote: On 7/16/10 2:42 PM, Cyrus Harmon wrote: Going to http:// clojure.org, searching for git and following the "Clojure goes git" link would lead one to http://groups.google.com/group/clojure/msg/ca4fb58428052554 which suggests that the rickhickey pag

Re: clojure.string namespace missing from API page?

2010-07-17 Thread Adrian Cuthbertson
Hi Benny, The 1.2 release source site has moved to http://github.com/clojure/ -Regards, Adrian On Sat, Jul 17, 2010 at 8:00 AM, Btsai wrote: > Hi Clojurians, > > The recent 1.2 beta release is the first time I played with 1.2.  When > reading the release notes, I saw a number of new namespaces.

defrecord with identity as an equality semantic

2010-07-17 Thread Nicolas Oury
Dear all, I was wondering if they were a way to define a record type with identity as an equality semantic? (defrecord A[] Object (hashCode ...) (equals ...)) do not work. Is there a way to do that? (Defining a deftype around the defrecord is a bit annoying) Best regards, Nicolas. --

clojure.string namespace missing from API page?

2010-07-17 Thread Btsai
Hi Clojurians, The recent 1.2 beta release is the first time I played with 1.2. When reading the release notes, I saw a number of new namespaces. I was able to find most of them (clojure.java.io, etc.) on the API site (http://richhickey.github.com/clojure/). However, I could not find the clojur

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Isaac Hodes
On Jul 16, 11:26 pm, Frederick Polgardy wrote: > Where's the link? :) > > -Fred Whew. Here it is; my bad! http://stackoverflow.com/questions/3259825/trouble-with-lazy-convolution-fn-in-clojure -- You received this message because you are subscribed to the Google Groups "Clojure" group. To p

Re: Question on namespace/packages of defrecord

2010-07-17 Thread Eric Thorsen
That's correct...not generating a valid java package from the clojure namespace...hyphens to underscores does not appear to happen for defrecord in 1.2 beta. On Jul 17, 8:29 am, Rasmus Svensson wrote: > 2010/7/17 Moritz Ulrich > > > clojure-namespaces should be treated like java-namespaces: (ns

Re: Question on namespace/packages of defrecord

2010-07-17 Thread Rasmus Svensson
2010/7/17 Moritz Ulrich > clojure-namespaces should be treated like java-namespaces: (ns > foo.bar) instead of (ns foo-bar) > I think he refered to the fact that the hyphen in the (single) namespace segment was not translated into an underscore. // raek -- You received this message because yo

Re: Question on namespace/packages of defrecord

2010-07-17 Thread Moritz Ulrich
clojure-namespaces should be treated like java-namespaces: (ns foo.bar) instead of (ns foo-bar) On Sat, Jul 17, 2010 at 3:45 AM, Eric Thorsen wrote: > Congrats on the 1.2 beta guys! > > When I AOT a defrecord it does not javaize the clojure namespace into > a proper java package name. > (ns this-

Re: Implementing a protocol with using a base implementation?

2010-07-17 Thread Meikel Brandmeyer
Hi, one way to do that is using extend. (def defaults {fn1 (fn ...) fn2 (fn ...) fn3 (fn ...)}) (defrecord R1 [...]) (def R1-fns {fn1 (fn ...)}) (defrecord R2 [...]) (def R2-fns {fn2 (fn ...) fn3 (fn ...)}) (extend YourProtocol R1 (merge defaults R1-fns) R2 (merge defaults R

Re: ClojureDocs.org week 1

2010-07-17 Thread Tassilo Horn
Hi Zack, I just had a look at ClojureDocs.org and it's really neat! Some observations I made: - When I view the docs of let's say clojure.set/rename, the clojure.set part is a link. But instead of pointing to to clojure.set summary page, it is only http:. - In the source section, not all r

Re: Clojure 1.2 Beta 1

2010-07-17 Thread Meikel Brandmeyer
Hi, Am 16.07.2010 um 20:56 schrieb Jeffrey Schwab: > On 7/16/10 2:42 PM, Cyrus Harmon wrote: >> Going to http:// clojure.org, searching for git and following the "Clojure >> goes git" link would lead one to >> http://groups.google.com/group/clojure/msg/ca4fb58428052554 which suggests >> that t

Re: Implementing a protocol with using a base implementation?

2010-07-17 Thread Nicolas Oury
Hi Toni, The key thing is that you can implement protocol on Object. So if you have one protocol per function, (Let's call your function f1,..., fn and the protocols implementing them F1,,Fn) You can define a default value for each function: (extend-type Object F1 (f1 ...) Fn (fn)

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread James Reeves
On 16 July 2010 20:57, Isaac Hodes wrote: > I am trying to create a lazy/functional/efficient/Clojuresque function > to carry out convolution on two lists/vectors of (ideally BigDecimals > but that may be inefficient) doubles. Perhaps something like this? (defn convolve [ns ms] (loop [nums (fo

Re: ClojureDocs.org

2010-07-17 Thread zkim
Islon- See the week 1 post on the CD.org group (http:// groups.google.com/group/clojuredocsorg/browse_thread/thread/ af7edbf85a6607c4) as to where this fits in on the timeline. Lee- Very cool, I've added it to the UserVoice page. Daniel- I agree, a great search experience is key for documentation

ClojureDocs.org week 1

2010-07-17 Thread zkim
Hi All- I've just posted a summary of feedback and the plan moving forward for ClojureDocs.org (http://groups.google.com/group/clojuredocsorg/ browse_thread/thread/af7edbf85a6607c4). If you're interested in being involved in shaping the site please take a look (and sign up for the group). I'd li

Re: Saving runtime clojure image

2010-07-17 Thread atreyu
and serialized continuations ? could they be used to save a "image" of a moment of a execution to return to it lately? -- 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 n

Re: Function called from macro loses record structure

2010-07-17 Thread Quzanti
Thanks Michał I suppose this raises a deeper question - should an expression and what it evaluates to always be interchangeable in source code? I naively assumed it should, but then after reading Kyle's explanation decided that maybe there is a difference? On Jul 17, 2:18 am, Michał Marczyk wrot