ah, thank you for the help!
On Mon, Nov 9, 2009 at 1:57 AM, Alex Osborne wrote:
>
> Wilson MacGyver wrote:
>> Does Clojure have a function like Haskell's group?
>>
>> In Haskell,
>> Input: group [1,2,2,1,1,1,2,2,2,1]
>> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
>
> (use 'clojure.contrib.seq-utils)
Wilson MacGyver wrote:
> Does Clojure have a function like Haskell's group?
>
> In Haskell,
> Input: group [1,2,2,1,1,1,2,2,2,1]
> Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
(use 'clojure.contrib.seq-utils)
(partition-by identity [1 2 2 1 1 1 2 2 2 1])
=> ((1) (2 2) (1 1 1) (2 2 2) (1))
--~--~---
Hi,
I did search in the API docs for both core and contrib, but didn't
find anything like
it.
Does Clojure have a function like Haskell's group?
In Haskell,
Input: group [1,2,2,1,1,1,2,2,2,1]
Output: [[1],[2,2],[1,1,1],[2,2,2],[1]]
Thanks
--
Omnem crede diem tibi diluxisse supremum.
--~--~-
On Nov 4, 9:07 pm, Lauri Oherd wrote:
> With this patch, the trailing whitespace characters in clojure file
> buffer will be deleted automatically before each save if custom
> parameter 'clojure-mode-cleanup-whitespace' is set.
>
> This is based on the js2-mode where similar defcustom parameter i
On 2009-11-08, at 3:40 PM, Richard Newman wrote:
>
> Try
>
> (defmacro mydefroutes []
> `(defroutes my-routes
> (GET "/api"
> (my-code ~'request
Brilliant! I learn something new every day :-)
S.
--~--~-~--~~~---~--~~
You received this message
Try
(defmacro mydefroutes []
`(defroutes my-routes
(GET "/api"
(my-code ~'request
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googl
I have this Compojure code that works fine:
(defroutes my-routes
(GET "/api"
(my-code request)))
I want this code to be generated by a macro. My real code is more
complex but the error is the same.
(defmacro mydefroutes []
`(defroutes my-routes
(GET "/api"
(my-code req
On Sun, Nov 8, 2009 at 1:39 PM, Robert Campbell wrote:
> John: good catch.
Thanks.
> Can you confirm the difference between my original
> defn and your letfn? Both work, but as I understand it from the
> documentation, defn would actually define that local function
> globally, while letfn act
It's one thing to try to protect the programmer from accidentally
shooting himself on the foot, but I don't think it is as necessary for
a language to prevent him from doing it on purpose.
On 8 nov, 02:59, John Harrop wrote:
> user=> (def q 'G__723)
> #'user/q
> user=> (def r (gensym))
> #'user/
Mark: that looks a lot like the "collector" I learned about in The
Little Schemer. I actually do have How to Design Programs, but I
wanted to finish Seasoned Schemer first. I was poking around in SICP
because of a Project Euler problem. Thanks for the tip!
John: good catch. Can you confirm the di
On Sun, Nov 8, 2009 at 7:33 AM, Michael Jaaka
wrote:
> Hi! How would you solve such problem:
>
> I have a collection of pairs (key, value) ->
> [ [ "tom" 32 ] [ "tom" 2333 ] [ "anne" 12 ] [ "anne" 55 ] ]
>
> As you can see keys can occur more than once, also that collection is very
> large so it
On Sun, Nov 8, 2009 at 8:41 AM, Michael Jaaka
wrote:
> Can any imperative code be transformed to functional equivalent?
> (Give an answer in terms of the same way I can answer on recursion and
> loops)
Short answer: Yes.
Long answer: Yes, but sometimes the transformation can get rather unwieldy
You have a bug:
(defn exp-mod [base exp m]
(cond
(zero? exp) 1
(even? exp) (mod (Math/sqrt (exp-mod base (/ exp 2) m)) m)
:else (mod (* base (exp-mod base (inc exp) m)) m)))
should be
(defn exp-mod [base exp m]
(cond
(zero? exp) 1
(even? exp) (mod (Math/sqrt (exp-mod base
Can any imperative code be transformed to functional equivalent?
(Give an answer in terms of the same way I can answer on recursion and
loops)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to
Hi,
Am 08.11.2009 um 13:33 schrieb Michael Jaaka:
> Hi! How would you solve such problem:
>
> I have a collection of pairs (key, value) ->
> [ [ "tom" 32 ] [ "tom" 2333 ] [ "anne" 12 ] [ "anne" 55 ] ]
>
> As you can see keys can occur more than once, also that collection
> is very large so it
Hint: Use an accumulator.
http://htdp.org/2003-09-26/Book/curriculum-Z-H-39.html#node_chap_31
In fact, you may want to consider reading How to Design Programs before SICP.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Gro
One correction: after playing with the functions a bit I noticed I
screwed up, putting sqrt where I needed square.
On Sun, Nov 8, 2009 at 4:43 PM, Robert Campbell wrote:
> I've started reading SICP and I came across the Fermat primality test
> implemented an Scheme. I reimplemented it in Clojur
I've started reading SICP and I came across the Fermat primality test
implemented an Scheme. I reimplemented it in Clojure and was able to
switch the recursive call in fast-prime to TCO/recur, but I was unable
to do the same for the exp-mod function.
(defn exp-mod [base exp m]
(cond
(zero?
Hi Alex,
Wow! Thank you so much for this excellent explanation! It totally
makes sense now :-)
S.
On 2009-11-07, at 9:46 PM, Alex Osborne wrote:
>
> Stefan Arentz wrote:
>
>> I must admin that I don't fully understand the difference between foo
>> and #'foo. That is probably why I'm making
Hi! How would you solve such problem:
I have a collection of pairs (key, value) ->
[ [ "tom" 32 ] [ "tom" 2333 ] [ "anne" 12 ] [ "anne" 55 ] ]
As you can see keys can occur more than once, also that collection is very
large so it should be evaluated lazily (for example the collection cames
from
OK. I have figured it out. I just looked into core.clj and noticed that
keyfn is a function which know how to get a value from an element in a
collection. That value is just compared with other.
2009/11/7 Michael Jaaka
> Hello I have such data
>
> [ [ "tom" 23 ] [ "ann" 4434 ] [ "tom" 1234 ] ["m
Hi All,
I have been watching Clojure for about 6 months. I finally sat down
and tried to code a non-trivial task with it. I come from Java and
have dabbled in LISP but never for something significant.
So I am asking if you would look at the following code and provide
feedback on how it can be
Hello I have such data
[ [ "tom" 23 ] [ "ann" 4434 ] [ "tom" 1234 ] ["mike" 34 ] ]
I would like to sort these data so finally i got
[ [ "ann" 4434 ] ["mike" 34 ] [ "tom" 23 ] [ "tom" 1234 ] ]
note that i don't care the order between "tom" keys (1234 can be
before 23)
I have seen sort-by but
On 8 Lis, 08:11, pmf wrote:
> > Hmm, someone else has made another "closure" available :).
>
> >http://googlecode.blogspot.com/2009/11/introducing-closure-tools.html
>
> There's also Clozure Common Lisp [1], which is conceptually closer to
> Clojure.
There's also a web browser written in CL cal
24 matches
Mail list logo