Hello,
I've never used monads but I have a problem that feels like it could
be solved elegantly with them.
I have a sequence of functions of arbitary size and an input sequence
s. Each function is given a sequence and returns a sequence that can
be bigger than the input sequence. I want the out
On Jan 13, 9:18 am, Saul Hazledine wrote:
> Hello,
> I've never used monads but I have a problem that feels like it could
> be solved elegantly with them.
>
> I have a sequence of functions of arbitary size and an input sequence
> s. Each function is given a sequence and returns a sequence that
One common case also, is if you want to store in a datastructure not the
current function of a global var, but rather the var itself, so that
everytime you want to use it, you'll get the current value bound to the var,
and not the value bound that happened to be bound to the var when at the
point i
On a related note, is there any way to completely clear all the
bytecode that's being stored internally by the jvm, forcing it to fall
back to the hard-disk version of the classfiles available on the
classpath?
sincerely,
--Robert McIntyre
On Tue, Jan 11, 2011 at 5:04 PM, Stuart Sierra
wrote:
>
On Thursday, January 13, 2011 11:26:16 AM UTC+1, Robert McIntyre wrote:
>
> On a related note, is there any way to completely clear all the
> bytecode that's being stored internally by the jvm, forcing it to fall
> back to the hard-disk version of the classfiles available on the
> classpath?
No,
I tried to do it the other way around: find all symbols in a given
namespace and use your protocol? function to find out which of these
is a protocol, and next check with extenders if the class of my object
is included.
However this fails because my code to get all symbols from a
namespace:
(map
Hi,
Try this:
(map #(isprotocol? @(val %)) (ns-publics *ns*)))
However just checking extenders is not enough, because it does not
contain classes, which implement the protocol directly.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" grou
I'm missing something blindingly obvious. Where can I download this?
On Wed, Jan 12, 2011 at 3:48 PM, Miki wrote:
> [fs "0.2.0-SNAPSHOT"] is out, featuring:
>
> abspath
> Return absolute path
> basename
> Return the last part of path
> copy
> Copy a file
> cwd
> Return the current
Thanks for your answer. I guess the right approach is to check with
extends? against the list of protocols that I found in the namespace.
Maurits
On Jan 13, 2:00 pm, Meikel Brandmeyer wrote:
> Hi,
>
> Try this:
> (map #(isprotocol? @(val %)) (ns-publics *ns*)))
>
> However just checking extender
Hi,
On 13 Jan., 14:15, Maurits wrote:
> Thanks for your answer. I guess the right approach is to check with
> extends? against the list of protocols that I found in the namespace.
Actually satisfies? with an instance of the class in question.
Sincerely
Meikel
--
You received this message beca
Hi,
On 12 Jan., 21:48, Miki wrote:
> [fs "0.2.0-SNAPSHOT"] is out
A SNAPSHOT is "out"? Please don't do this. If it is a release, get rid
of the SNAPSHOT. :(
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, s
probably clojars.org (or by putting [fs "0.2.0-SNAPSHOT"] in your
project.clj if you're using lein...
On Thu, Jan 13, 2011 at 7:11 AM, Tim Visher wrote:
> I'm missing something blindingly obvious. Where can I download this?
>
> On Wed, Jan 12, 2011 at 3:48 PM, Miki wrote:
>> [fs "0.2.0-SNAPSHOT"
> > [fs "0.2.0-SNAPSHOT"] is out
>
> A SNAPSHOT is "out"? Please don't do this. If it is a release, get rid
> of the SNAPSHOT. :(
>
> Done, please use [fs "0.2.0"] :)
All the best,
--
Miki
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post
Thanks for all the feedback and answers.
I have added my implementation below.
Maurits
-
; test protocol and record
(defprotocol Log
(log [this] "Method to log"))
(defrecord Foo [f1 f2]
Log
(log [this] (println (:f1 this) (:f2 this
(def foo (Foo. 13 42))
(log foo
>> I'm missing something blindingly obvious. Where can I download this?
> probably clojars.org (or by putting [fs "0.2.0-SNAPSHOT"] in your
> project.clj if you're using lein...
Yup, it's in clojars. However if you prefer to download the jar manually,
you can
get it from https://bitbucket.org/tebe
2011/1/13 Miki
> >> I'm missing something blindingly obvious. Where can I download this?
> > probably clojars.org (or by putting [fs "0.2.0-SNAPSHOT"] in your
> > project.clj if you're using lein...
> Yup, it's in clojars. However if you prefer to download the jar manually,
> you can
> get it fro
Thanks for shaing. I was just about to write several functions along these
lines. I have a couple of comments.
First, I suggest that you look at the standard clojure.java.io package for some
useful functions that are already in Clojure 1.2. In particular, you could use
io/file instead of (Fi
The following solution by mtgred for http://clojure-
euler.wikispaces.com/">Project Euler Clojure problem 003 uses
implicit recursion.
(use '[clojure.contrib.lazy-seqs :only (primes)])
(defn prime-factors [n]
(let [f (some #(if (= 0 (rem n %)) %) primes)]
(if (= f n) #{f} (conj (prime-facto
A literal set is a unordered hash-set. To get the factors in order
change #{f} for (sorted-set f).
On Jan 13, 7:09 am, Vitaly Peressada wrote:
> The following solution by mtgred for http://clojure-
> euler.wikispaces.com/">Project Euler Clojure problem 003 uses
> implicit recursion.
>
>
> (use '
(conj) will add items to different places in the collection, depending
on the type of the collection. For a set, this can be at either the
end OR the beginning.
For this problem, the output is built by:
(conj (conj (conj #{6857} 1471) 839) 71)
which is equivalent to:
(-> #{6857} (conj 1471) (c
there is also this:
https://github.com/jashmenn/clj-file-utils
which seems to be very similar
On Thu, Jan 13, 2011 at 9:04 AM, Steve Miner wrote:
> Thanks for shaing. I was just about to write several functions along these
> lines. I have a couple of comments.
>
> First, I suggest that you l
> Second, fs is using a singe segment namespace. I remember that
> there have been some cautions against doing that. (But not everyone
> agrees.) My understanding is that it's best for Java interop to have a
> multi-segment namespace. (Reference links below.)
http://clojure.org/libs
A lib name
Armando, thanks for a plausible explanation. Here is what happened
after I made the suggested change:
user=> (prime-factors 600851475143)
n: 600851475143 , f: 71
n: 8462696833 , f: 839
n: 10086647 , f: 1471
n: 6857 , f: 6857
#
I guess this something subtle with unordered vs. sorted-set as
implici
On 13 January 2011 15:52, Maurits wrote:
> (defn all-protocols []
> (filter #(protocol? @(val %)) (ns-publics *ns*)))
>
> (defn implemented-protocols [sym]
> (filter #(satisfies? @(val %) sym) (all-protocols)))
Of course, this will restrict your search to protocols in a given namespace.
It mig
Armando's suggested change worked fine for me.
(use '[clojure.contrib.lazy-seqs :only (primes)])
(defn prime-factors [n]
(let [f (some #(if (= 0 (rem n %)) %) primes)]
(println "n:" n ", f:" f)
(if (= f n)
(sorted-set f)
(conj (prime-factors (/ n f)) f
user=> (prime-fac
Benny, thanks for your explanation. It does make sense and clarifies
the issue. What DOES NOT make sense is
Clojure 1.2.0
user=> (conj (conj (conj #{4} 3) 2) 1)
#{1 2 3 4}
user=> (conj (conj (conj #{6857} 1471) 839) 71)
#{71 839 6857 1471}
Any ideas?
On Jan 13, 11:36 am, Benny Tsai wrote:
> (
Replying to myself :-)
After some pondering, it DOES make sense if I pay attention to what
you guys saying: for unordered set conj can nondeterministically add
either at beginning OR end.
On Jan 13, 12:40 pm, Vitaly Peressada wrote:
> Benny, thanks for your explanation. It does make sense and cl
On Thu, Jan 13, 2011 at 17:36, Benny Tsai wrote:
> (conj) will add items to different places in the collection, depending
> on the type of the collection. For a set, this can be at either the
> end OR the beginning.
For a (hashed) set, this can be *anywhere* (between existing elements too).
FTF
Right, my bad. It was a typo. (sorted-set (f))
Thanks for your help.
On Jan 13, 12:16 pm, Benny Tsai wrote:
> Armando's suggested change worked fine for me.
>
> (use '[clojure.contrib.lazy-seqs :only (primes)])
>
> (defn prime-factors [n]
> (let [f (some #(if (= 0 (rem n %)) %) primes)]
> (
Good to know, thank you Ben :)
On Jan 13, 10:49 am, B Smith-Mannschott wrote:
> On Thu, Jan 13, 2011 at 17:36, Benny Tsai wrote:
> > (conj) will add items to different places in the collection, depending
> > on the type of the collection. For a set, this can be at either the
> > end OR the begi
On Thu, Jan 13, 2011 at 3:18 AM, Saul Hazledine wrote:
> Hello,
> I've never used monads but I have a problem that feels like it could
> be solved elegantly with them.
>
> I have a sequence of functions of arbitary size and an input sequence
> s. Each function is given a sequence and returns a s
On Jan 13, 7:35 pm, Ken Wesson wrote:
>
> > (let [seq-of-fns [f1 f2 f3 ... fm]]
> > (mapcat fm ... (mapcat f2 (mapcat f1 s)))
>
> > If any of the functions return nil, I'd like the computation to stop.
>
> I don't see any real reason not to use
>
> (reduce #(if %1 (mapcat %2 %1)) s seq-
Hi,
depending on the length of your function sequence you might run into stack
overflows, though. Just keep that in mind (or add a tactically placed doall).
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, sen
On Jan 13, 2011, at 11:54 AM, Tim Daly wrote:
> > Second, fs is using a singe segment namespace. I remember that
> > there have been some cautions against doing that. (But not everyone
> > agrees.) My understanding is that it's best for Java interop to have a
> > multi-segment namespace. (Referen
On Jan 13, 2011, at 3:16 PM, Chas Emerick wrote:
> Just to clarify my position (it's funny to see one's self quoted out of the
> blue from an old thread!), I'm not at all suggesting "java naming
> conventions" when it comes to namespacing.
By the way, I didn't mean to put Chas on the spot. Go
I noticed that although you can use assoc with sequences and vectors
to modify them, you could not use dissoc to eliminate elements from
them. Why is this so?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure
On Thu, Jan 13, 2011 at 4:05 PM, Eduardo Julian wrote:
> I noticed that although you can use assoc with sequences and vectors
> to modify them, you could not use dissoc to eliminate elements from
> them. Why is this so?
>
You cannot efficiently remove items from the middle of sequences or vectors
On Jan 13, 2011, at 3:59 PM, Steve Miner wrote:
> On Jan 13, 2011, at 3:16 PM, Chas Emerick wrote:
>
>> Just to clarify my position (it's funny to see one's self quoted out of the
>> blue from an old thread!), I'm not at all suggesting "java naming
>> conventions" when it comes to namespacing.
Hi all,
I've been reading about the changes to Clojure that are occurring with
regards to improving performance of arithmetic operations. For
example, + no longer auto promotes and +' has been introduced as an
auto-promoting addition operator.
The idea of introducing additional syntax is a bit o
On Thu, Jan 13, 2011 at 4:05 PM, Eduardo Julian wrote:
> I noticed that although you can use assoc with sequences and vectors
> to modify them
I get an exception trying to "assoc" a sequence in 1.2.
> you could not use dissoc to eliminate elements from
> them. Why is this so?
Deletion in the mi
> First, I suggest that you look at the standard clojure.java.io package for
> some useful functions that are already in Clojure 1.2. In particular, you
> could use io/file instead of (File. xxx) in your code to add some
> flexibility to the kinds of things that can be treated as a "file". I
> there is also this:
>
> https://github.com/jashmenn/clj-file-utils
>
Wasn't aware of this one, will have a look. At first glance it uses
common.io and I tried to depend on clojure only.
Thanks,
--
Miki
--
You received this message because you are subscribed to the Google
Groups "Clojure" g
I can't speak for Rich, but your suggestion would mean an additional
if statement being executed every time you call +. Not sure if
Hotspot (or other JVMs) would compile that away or not...
Colin
On Jan 13, 3:31 pm, RJ Nowling wrote:
> Hi all,
>
> I've been reading about the changes to Clojure
The result of `assoc` on a vector is well-defined, by treating the vector as
a map with integer indices as keys.
But the result of `dissoc` on a vector is not so clear. `dissoc` removes a
key from an associative thing. But you can't remove an index from the middle
of a vector. Even if you could
The goal of primitive math is better performance in the common case. The
implementation makes the assumptions that Java long is big enough for nearly
all cases, and that auto-promotion to BigInteger (and the resulting
performance hit) is rarely desirable.
The + function still promotes, it just
On Thu, Jan 13, 2011 at 7:28 PM, Stuart Sierra
wrote:
> The goal of primitive math is better performance in the common case.
Of course, this better performance is not needed "in the common case",
IMO, but only in hotspots that do number crunching, where people
already optimize using primitive loc
So I am converting some Ruby code I have into CLojure for practice/fun and I
am having trouble finding info via Google.
I want to take something like this from Ruby and do it in Clojure:
DATE_REGEX = /^\s*(\d{4})\s+(\d{1,2})\s+(\d{1,2})/
token =~ DATE_REGEX
[$1, $2, $3]
So far my best guess has
> So I am converting some Ruby code I have into CLojure for practice/fun and I
> am having trouble finding info via Google.
Clojure uses the same regex style as Java, so you'll need to search
for information on Java regexes rather than Clojure regexes.
--
You received this message because you ar
Here is one way:
user=> (import 'java.util.regex.Pattern)
java.util.regex.Pattern
user=> (def p (Pattern/compile "mon|tue|wed|thu|fri|sat|sun"
Pattern/CASE_INSENSITIVE))
#'user/p
user=> (re-find p "I have a dentist appoint on Monday morning, so you'll
need to take the kids to school.")
"Mon"
Bi
i think you want to do something like this:
(let [_ year month day] (re-find date-regex line))
On Thu, Jan 13, 2011 at 8:50 PM, Eric Lavigne wrote:
>> So I am converting some Ruby code I have into CLojure for practice/fun and I
>> am having trouble finding info via Google.
>
> Clojure uses th
I see. So I may have to use some kind of clunky syntax instead of a nice
$1, $2, $3 syntax. I can handle that I guess :)
Thanks.
--
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
A blog entry I read (and now can't find) mentioned being able to use syntax
like (?i) to do the ignore case.
--
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 new members
For accessing groups in a match, you can use (re-matches). It will
always give the full match as the first element though:
user=> (re-matches date-regex "2011 1 13")
["2011 1 13" "2011" "1" "13"]
So to replicate the Ruby code's behavior maybe you'll just want (rest
(re-matches date-regex line)).
On Thu, Jan 13, 2011 at 9:54 PM, Alex Baranosky
wrote:
> I see. So I may have to use some kind of clunky syntax instead of a nice
> $1, $2, $3 syntax. I can handle that I guess :)
Hey, it's a Lisp! You can use almost any syntax you want. How about %1, %2, %3:
(defn re-do [f regex input]
(app
They do seem to allow whatever you like if you upload your own
package. I'm hooked on using their built-in editor, so in some cases
I copy-and-paste code until they get around to updating their version
of Clojure. The one nice thing about the site is that they do seem
rather responsive to questio
On Thu, Jan 13, 2011 at 10:04 PM, John Svazic wrote:
> They do seem to allow whatever you like if you upload your own
> package. I'm hooked on using their built-in editor, so in some cases
> I copy-and-paste code until they get around to updating their version
> of Clojure. The one nice thing ab
bah! good catch.
(let [[_ year month day]] (re-find date-regex line))
fixed!
On Thu, Jan 13, 2011 at 9:03 PM, Ken Wesson wrote:
> On Thu, Jan 13, 2011 at 9:54 PM, Alex Baranosky
> wrote:
>> I see. So I may have to use some kind of clunky syntax instead of a nice
>> $1, $2, $3 syntax. I can ha
On Thu, Jan 13, 2011 at 10:22 PM, gaz jones wrote:
> bah! good catch.
> (let [[_ year month day]] (re-find date-regex line))
>
> fixed!
Oh, gaz. I'm so so sorry. :(
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to
lol oh noes! i should really stop doing this while watching 30rock...
On Thu, Jan 13, 2011 at 9:38 PM, Ken Wesson wrote:
> On Thu, Jan 13, 2011 at 10:22 PM, gaz jones wrote:
>> bah! good catch.
>> (let [[_ year month day]] (re-find date-regex line))
>>
>> fixed!
>
> Oh, gaz. I'm so so sorry. :(
The latest version of Clojure in Small Pieces is up.
http://daly.axiom-developer.org/clojure.pamphlet
http://daly.axiom-developer.org/clojure.pdf
A few people have volunteered to write sections.
More volunteers are welcome.
There are new sections. The LispReader is split apart
and is undergoing
As HTML-y as it it is, PHP is Turing complete and thus a "real"
programming language.
It's got foreach loops, mutable arrays, and boolean logic, and that's
one particular set of operations to simulate a Turing machine.
http://en.wikipedia.org/wiki/Turing_machine
http://aturingmachine.com/
sincer
On Fri, Jan 14, 2011 at 1:13 AM, Robert McIntyre wrote:
> As HTML-y as it it is, PHP is Turing complete and thus a "real"
> programming language.
So are LaTeX, Javascript, and a few others, but from what I've seen
they're all meant for specific purposes rather than general-purpose
software engine
62 matches
Mail list logo