Monad newbie question

2011-01-13 Thread Saul Hazledine
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

Re: Monad newbie question

2011-01-13 Thread Saul Hazledine
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

Re: When to use #'

2011-01-13 Thread Laurent PETIT
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

Re: Compiling dynamically created namespaces, without on-disk source code?

2011-01-13 Thread Robert McIntyre
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: >

Re: Compiling dynamically created namespaces, without on-disk source code?

2011-01-13 Thread Alessio Stalla
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,

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Maurits
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

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Meikel Brandmeyer
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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread Tim Visher
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

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Maurits
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

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Meikel Brandmeyer
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

Re: fs - file system utilities for Clojure

2011-01-13 Thread Meikel Brandmeyer
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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread gaz jones
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"

Re: fs - file system utilities for Clojure

2011-01-13 Thread Miki
> > [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

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Maurits
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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread 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 from https://bitbucket.org/tebe

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread Laurent PETIT
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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread Steve Miner
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

Question On Implicit Recursion

2011-01-13 Thread Vitaly Peressada
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

Re: Question On Implicit Recursion

2011-01-13 Thread Armando Blancas
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 '

Re: Question On Implicit Recursion

2011-01-13 Thread Benny Tsai
(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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread gaz jones
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

Java namespaces, Cobol, and Hierarchical file systems

2011-01-13 Thread Tim Daly
> 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

Re: Question On Implicit Recursion

2011-01-13 Thread Vitaly Peressada
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

Re: How do I find implemented protocols in Clojure object?

2011-01-13 Thread Daniel Werner
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

Re: Question On Implicit Recursion

2011-01-13 Thread Benny Tsai
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

Re: Question On Implicit Recursion

2011-01-13 Thread Vitaly Peressada
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: > (

Re: Question On Implicit Recursion

2011-01-13 Thread Vitaly Peressada
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

Re: Question On Implicit Recursion

2011-01-13 Thread B Smith-Mannschott
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

Re: Question On Implicit Recursion

2011-01-13 Thread Vitaly Peressada
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)] >     (

Re: Question On Implicit Recursion

2011-01-13 Thread Benny Tsai
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

Re: Monad newbie question

2011-01-13 Thread Ken Wesson
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

Re: Monad newbie question

2011-01-13 Thread Saul Hazledine
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-

Re: Monad newbie question

2011-01-13 Thread Meikel Brandmeyer
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

Re: Java namespaces, Cobol, and Hierarchical file systems

2011-01-13 Thread Chas Emerick
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

Re: Java namespaces, Cobol, and Hierarchical file systems

2011-01-13 Thread Steve Miner
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

Why is DISsoc being DIScriminated?

2011-01-13 Thread Eduardo Julian
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

Re: Why is DISsoc being DIScriminated?

2011-01-13 Thread David Nolen
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

Re: Java namespaces, Cobol, and Hierarchical file systems

2011-01-13 Thread Chas Emerick
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.

Enhanced Primitive Support Syntax

2011-01-13 Thread RJ Nowling
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

Re: Why is DISsoc being DIScriminated?

2011-01-13 Thread Ken Wesson
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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread Miki
> 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

Re: [ANN] fs - file system utilities for Clojure

2011-01-13 Thread Miki
> 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

Re: Enhanced Primitive Support Syntax

2011-01-13 Thread trptcolin
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

Re: Why is DISsoc being DIScriminated?

2011-01-13 Thread Stuart Sierra
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

Re: Enhanced Primitive Support Syntax

2011-01-13 Thread Stuart Sierra
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

Re: Enhanced Primitive Support Syntax

2011-01-13 Thread Ken Wesson
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

Clojure regexs

2011-01-13 Thread Alex Baranosky
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

Re: Clojure regexs

2011-01-13 Thread Eric Lavigne
> 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

Re: Clojure regexs

2011-01-13 Thread .Bill Smith
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

Re: Clojure regexs

2011-01-13 Thread gaz jones
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

Re: Clojure regexs

2011-01-13 Thread Alex Baranosky
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

Re: Clojure regexs

2011-01-13 Thread Alex Baranosky
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

Re: Clojure regexs

2011-01-13 Thread Benny Tsai
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)).

Re: Clojure regexs

2011-01-13 Thread Ken Wesson
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

Re: Clojure Quizzes?

2011-01-13 Thread John Svazic
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

Re: Clojure Quizzes?

2011-01-13 Thread Ken Wesson
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

Re: Clojure regexs

2011-01-13 Thread gaz jones
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

Re: Clojure regexs

2011-01-13 Thread Ken Wesson
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

Re: Clojure regexs

2011-01-13 Thread gaz jones
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. :(

Clojure in Small Pieces

2011-01-13 Thread Tim Daly
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

Re: Clojure Quizzes?

2011-01-13 Thread Robert McIntyre
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

Re: Clojure Quizzes?

2011-01-13 Thread Ken Wesson
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