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-
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
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
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
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
> (
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
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
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
> 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
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 %)
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.
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
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
>
>
>
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
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
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
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
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
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
[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
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
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
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
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
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
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
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
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
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
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)
>
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
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
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
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
34 matches
Mail list logo