Re: filtering with multiple predicates

2010-07-23 Thread Mark Triggs
I cheated and used 'every?' :) (defn andf [& preds] (fn [& args] (every? #(apply % args) preds))) ".Bill Smith" writes: > I want to filter a list based on the logical AND of a set of > predicates. For example, let's say I have single-argument functions > f, g, and h (without side-

Re: filtering with multiple predicates

2010-07-23 Thread Meikel Brandmeyer
Hi, Am 23.07.2010 um 23:27 schrieb .Bill Smith: > (filter #(and (f %) (g %) (h %)) my-list) Here a completely different approach. Note, it also preserves short-circuiting. (defn and-pred [& preds] (if-let [preds (seq preds)] (fn [x] (seq (drop-while identity (map #(% x) preds

Re: filtering with multiple predicates

2010-07-23 Thread David Cabana
Here's an approach that doesn't use macros. I'm not sure I'd actually do this, but here it is just for grins. (defn bind [pred] (fn [[x bool]] [x (and (pred x) bool)])) (defn comp# [ & preds ] (let [ phi (reduce comp (map bind preds))] (fn [x] (second (phi [x true]) user> (filter (c

Re: filtering with multiple predicates

2010-07-23 Thread David Cabana
Alex, Very slick; I really liked that. Thank you for posting it . David On Fri, Jul 23, 2010 at 6:33 PM, ataggart wrote: > Not that preserves the short-circuiting behavior of 'and.  This works > though: > > (defmacro andf [& fns] >  (let [x# (gensym)] >    `(fn [~x#] (and ~@(map #(list % x#) f

Re: filtering with multiple predicates

2010-07-23 Thread ataggart
Quite right! Being a variation on the actual implementation of the 'and macro, it's probably easier to understand than my cobbled together version (needing a gensym should have been a giveaway). On Jul 23, 4:07 pm, ".Bill Smith" wrote: > For that matter, I could do this: > > (defmacro andp >   (

Re: filtering with multiple predicates

2010-07-23 Thread .Bill Smith
For that matter, I could do this: (defmacro andp ([] true) ([x p] `(~p ~x)) ([x p & next] `(let [and# (~p ~x)] (if and# (andp ~x ~...@next) and# On Jul 23, 5:33 pm, ataggart wrote: > Not that preserves the short-circuiting behavior of 'and.  This works > though: > > (defm

Re: filtering with multiple predicates

2010-07-23 Thread ataggart
The problem is that 'comp passes the result of one function as the arg of the next, which isn't likely to be applicable for predicate functions, nor will it compose with the 'and macro. On Jul 23, 3:28 pm, Peter Schuller wrote: > > Is there a more terse way to express the same thing?  I suspect t

Re: filtering with multiple predicates

2010-07-23 Thread ataggart
Not that preserves the short-circuiting behavior of 'and. This works though: (defmacro andf [& fns] (let [x# (gensym)] `(fn [~x#] (and ~@(map #(list % x#) fns) user=> (filter (andf integer? odd?) [1 2 3.1]) (1) On Jul 23, 2:27 pm, ".Bill Smith" wrote: > I want to filter a list base

Re: filtering with multiple predicates

2010-07-23 Thread Peter Schuller
> Is there a more terse way to express the same thing?  I suspect there > is a mechanism similar to (or perhaps a generalization of) composition > for that, but I couldn't find it in the API docs. http://stackoverflow.com/questions/2822140/function-composition-clojure -- / Peter Schuller -- Yo

filtering with multiple predicates

2010-07-23 Thread .Bill Smith
I want to filter a list based on the logical AND of a set of predicates. For example, let's say I have single-argument functions f, g, and h (without side-effects), and I want those items x in the list such that (f x), (g x) and (h x) are all true. I know I can do this: (filter #(and (f %) (g %)

Idea - generic conversion multimethod

2010-07-23 Thread Adam Schmideg
Hi, I want to share an idea I've been playing with recently. I noticed I want to convert between different representations of roughly the same value every now and then, string to number, a var to symbol and vice versa, even a filename to an open stream. There are two approaches in the language.

Re: Slime, debug-repl & clojure debugging toolkit

2010-07-23 Thread Krukow
On Jul 23, 3:59 pm, "Hugo Duncan" wrote: > On Fri, 23 Jul 2010 02:35:13 -0400, Krukow wrote: > > So I guess the problem is in swank/break. > > Should be fixed in 1.3.0-SNAPSHOT now. > > -- > Hugo Duncan I've verified that it works here. Thanks for responding so quickly. /Karl -- You receive

Re: New git repo for enclojure-repl

2010-07-23 Thread Laurent PETIT
Yepee ! 2010/7/23 Eric Thorsen > There has been interest in reusing some of the features of the Enclojure > repl tools outside of Netbeans or swing. I have created a separate repo to > help the effort in moving in that direction. > > http://github.com/EricThorsen/enclojure-repl > > Eric > > >

New git repo for enclojure-repl

2010-07-23 Thread Eric Thorsen
There has been interest in reusing some of the features of the Enclojure repl tools outside of Netbeans or swing. I have created a separate repo to help the effort in moving in that direction. http://github.com/EricThorsen/enclojure-repl Eric -- You received this message because you are subscr

Re: ANN: clj-dropbox, Dropbox client library in Clojure

2010-07-23 Thread Marc Spitzer
I need to look at this. Thanks for the toy. marc On Thu, Jul 22, 2010 at 8:23 PM, aria42 wrote: > Hi all, > > I've released my clojure library for accessing the Dropbox API. Its > called clj-dropbox and it can be found at: > > http://github.com/aria42/clj-dropbox > > Hope some people get use ou

Re: Trying to write idiomatic clojure to create vector of vectors

2010-07-23 Thread Meikel Brandmeyer
Hi, On Jul 23, 4:19 pm, Konrad Hinsen wrote: > Instead of (take size (repeat nil)), you can write (replicate size   > nil). You can then make a square board filled with nils with Or just (repeat size nil). I think replicate was replaced by the two- arg form of repeat. Sincerely Meikel -- You

Re: RFC on my letrec macro

2010-07-23 Thread George Jahad
Just realized there are many types of recursive functions for which trampoline can't be used in this way. It's an interesting problem though. I'm going to think some more about it. On Jul 22, 11:11 pm, George Jahad wrote: > sorry, wrong gist.  here's one that tests for a function and only > ca

Re: Trying to write idiomatic clojure to create vector of vectors

2010-07-23 Thread Konrad Hinsen
On 22 Jul 2010, at 14:37, Rising_Phorce wrote: I will need to traverse the vectors sequentially but at each step there will be lots of sequential back and forward tracking. Arrays would be the natural imperative choice, but the docs recommend this only for inter-op. So are vectors the best choi

Re: Slime, debug-repl & clojure debugging toolkit

2010-07-23 Thread Hugo Duncan
On Fri, 23 Jul 2010 02:35:13 -0400, Krukow wrote: So I guess the problem is in swank/break. Should be fixed in 1.3.0-SNAPSHOT now. -- Hugo Duncan -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@google

Re: Memoizing a recursive function?

2010-07-23 Thread Mike Meyer
[Context lost to top posting.] On Thu, 22 Jul 2010 15:56:32 -0700 (PDT) logan wrote: > I tried defn-memo .. it still does not appear to memoize the original > fib call? I tried this using clojure 1.2 beta. Reading the code > definition for defn-memo it seems like it should work, but calling > (f

contrib deprecations and removals

2010-07-23 Thread Stuart Halloway
Hi all, Aaron and I are spending the day cleaning up contrib, starting with marking deprecations in the 1.2 branch. The approach we are taking is (1) Things are deprecated for one full (minor version number) release (in this case 1.2). (2) Then things may (and in contrib usually will) be remo

Re: IDE agnostic question on user assistance (emacs/vimClojure users help appreciated too !)

2010-07-23 Thread Lee Spector
I too often use a file as a pseudo-REPL in this way, but note that this means putting top-level forms in the file, which is apparently discouraged, and in the context of CCW's default setting of rebuild-on-save will cause your top-level forms to be re-evaluated each time you save (which you say

Re: CCW in Eclipse Market Place + needs a logo !

2010-07-23 Thread Laurent PETIT
Via this ml google group's web interface, there's a "file" section 2010/7/23 Victor S > I can send you something, but I don't know how to attach files here... > > - V > > On Jul 22, 7:09 am, Laurent PETIT wrote: > > Hello, > > > > Just a word to inform you that I've provisioned the Eclipse Mark

Re: Memoizing a recursive function?

2010-07-23 Thread Laurent PETIT
Yes, because the code I posted still makes me wonder what's happening ... 2010/7/23 Meikel Brandmeyer > Hi, > > On Jul 23, 3:02 am, logan wrote: > > > paul what version did you use? your version was the first one I tried, > > and on 1.2 at least it does not work. > > It works on 1.1. I guess th

Re: Anyone working with Eclipse and log4j? I have a beginner labrepl question...

2010-07-23 Thread Laurent PETIT
And may I add that "crazy easy labrepl installation for ccw" is around the corner: http://github.com/smuehlst/ccw/tree/labrepl-sample-project ! 2010/7/23 Victor S > I finally got labrepl to work with one IDE, tried with intelliJ but > didnt work, also comand line didnt work on mac os x. But Ecli

Re: Memoizing a recursive function?

2010-07-23 Thread Meikel Brandmeyer
Hi, On Jul 23, 3:02 am, logan wrote: > paul what version did you use? your version was the first one I tried, > and on 1.2 at least it does not work. It works on 1.1. I guess there is some issue with the direct linking introduced in 1.2. Sincerely Meikel -- You received this message because

Re: Trying to write idiomatic clojure to create vector of vectors

2010-07-23 Thread Edmund Jackson
Hi, Some time back Lau Jensen blogged something like this. Its starts here http://www.bestinclass.dk/index.clj/2009/10/brians-functional-brain.html but there are at least two follow ups. It might spark inspiration if you've not yet read it. Edmund On 22 Jul 2010, at 13:37, Rising

Anyone working with Eclipse and log4j? I have a beginner labrepl question...

2010-07-23 Thread Victor S
I finally got labrepl to work with one IDE, tried with intelliJ but didnt work, also comand line didnt work on mac os x. But Eclipse version seems to work! Yay! So I can't wait to start learning more about Clojure, but the road so far is pretty bumpy... Any help in figuring out what this log4j err

Re: CCW in Eclipse Market Place + needs a logo !

2010-07-23 Thread Victor S
I can send you something, but I don't know how to attach files here... - V On Jul 22, 7:09 am, Laurent PETIT wrote: > Hello, > > Just a word to inform you that I've provisioned the Eclipse Market Place for > Counterclockwise. > > That way, installing counterclockwise from Eclipse Helios is even

Re: Memoizing a recursive function?

2010-07-23 Thread logan
paul what version did you use? your version was the first one I tried, and on 1.2 at least it does not work. Jules version works, except lambda should be fn in clojure. On Jul 22, 4:51 pm, Paul Mooser wrote: > Why not simply do: > > (defn fib [n] >   (println "called with " n) >   (if (> n 2) >

Re: Memoizing a recursive function?

2010-07-23 Thread logan
I tried defn-memo .. it still does not appear to memoize the original fib call? I tried this using clojure 1.2 beta. Reading the code definition for defn-memo it seems like it should work, but calling (fib 41) still takes a long time after calling (fib 40), when it should basically be an instantane

Trying to write idiomatic clojure to create vector of vectors

2010-07-23 Thread Rising_Phorce
I'm coming from an imperative background and trying to stay away from "for loops" to do the task at hand. Given a size, I want to create a vector of vectors to represent a game board similar to Rich's ants or Conway's Game of Life (no wrapping necessary for me). A couple of questions. I will nee

Re: IDE agnostic question on user assistance (emacs/vimClojure users help appreciated too !)

2010-07-23 Thread Zmitro Lapcjonak
On Jul 20, 10:02 pm, Laurent PETIT wrote: > that'll bit anybody from time to time ( after having spent 15 minutes > understanding why this doesn't work anymore: "OH YES, I have forgotten to > synchronize the REPL ...") thus i do enter nothing in the CCW repl. all code, both business logic and all

Re: Memoizing a recursive function?

2010-07-23 Thread ajuc
On 23 Lip, 01:51, Paul Mooser wrote: > Why not simply do: > > (defn fib [n] >   (println "called with " n) >   (if (> n 2) >     (+ (fib (- n 2)) (fib (- n 1))) >     1)) > > (def fib (memoize fib)) > > I inserted the println to verify when we were actually calling the > function, and I believe t