Re: core.cache 0.6.2 is not available from Central

2012-08-08 Thread Andreas Kostler
> Given that regular Clojure users cannot submit a pull request.
Really? That's what I did...


On 9 August 2012 06:56, Michael Klishin  wrote:

> Meikel Brandmeyer:
>
> > This does not necessarily include a specific version.
> > “Instructions for including the library as a dependency in Maven /
> Leiningen”
>
> Arguing just for the sake of it? Clojure learning curve is already steep
> enough.
>
> Lets make it even steeper by asking people to figure out UIs of
> all those Maven search resources and which version is the last and whether
> using -SNAPSHOT
> versions is safe.
>
> "Don't make me think" is a good rule to live by for library maintainers.
>
> MK
>
> mich...@defprotocol.org
>
> --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Advice needed on primitive longs and trying to avoid autoboxing

2012-07-12 Thread Andreas Kostler
To answer your last question, I'd probably do it like this:
(def bitvector (reduce (fn [bm x] (conj bm (expt 2 x))) [] (range 63)))
;; Remember, vectors implement ifn.

Also, I believe using the bitshift operator (arguably) obscures your
intentions without much benefit over expt.

As to answering your other questions I'll leave that to someone more
qualified.

Cheers
Andreas


On 12 July 2012 17:38, john  wrote:

> Hello,
> I would like to avoid when possible  the promotion from a primitve long to
> an Long Object.
>
> I  have the following code: http://pastie.org/4242382 and am not sure if
> (Long) autoboxing is taking here place.
>
> In lines 24,28-30 I use "assoc" to replace a long in a defrecord.
>
> Since  "assoc" is a clojure function does autoboxing take place when
> "assoc" is called?
>
> Further if I in order to get rid of the repetitive "assoc" code replace
> lines 28-30 with the following s-expression
>
> board (reduce  (fn[b [k v]](assoc b k v)) board [[:white-pieces
> white-pieces]
>
>  [:black-pieces black-pieces]
>
>  [:all-pieces (bit-or white-pieces black-pieces)]])
>
> Does for example  autoboxing of the long  "black-pieces" take place?
>
> Is there a way,trick to check for autoboxing? (maybe using a debugger)?
>
>
> One further advice question :
> In line 1-4  I want to precompute an bitset therefore I have an aouter
> "let" around  "defn" . The code looks alittle unusual to me, but is it
> allright?
>
>
>
>
> --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Announcing dyscord

2012-07-02 Thread Andreas Kostler
Hi all,
A little exercise to get me started with clojurescript turned into
something people might actually find useful:

dyscord, a clojurescript library to bring emacs-like key sequences to
web-apps.

usage
=

A key sequence, is a sequence of keyboard key presses. Any element in such
a sequence can be a [chord](http://www.emacswiki.org/emacs/Chord) composed
of a non-modifier key and one or more modifier keys pressed at the same
time.

;; define a command for 'a'
(key-sequence! "a" (fn [] (js/alert "You pressed 'a' indeed!")))

;; let's do our first chord: 'C-x' by pressing 'ctrl' and 'x' at the same
time.
(key-sequence! "C-x" (fn [] (js/alert "Congrats; Your first chord. Now
let's get musical!")))

;; The chords 'C-x' and 'C-M-e' are typed in sequence
(key-sequence! "C-x C-M-e" (fn [] (js/alert "Sounds like music to me")))

'C-g' cancels a partially typed or accidental command. Dyscord does not
suppress browser shortcuts, yet. Maybe it never will.

Enjoy...
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Enfocus issues

2012-06-14 Thread Andreas Kostler
There you go...wrong on the example-page then.
Thanks David


On 15 June 2012 15:00, David Nolen  wrote:

> On Fri, Jun 15, 2012 at 1:23 AM, Andreas Kostler <
> andreas.koest...@leica-geosystems.com> wrote:
>
>> (set! (.onload js/window) start)
>
>
> Should be  (set! (.-onload js/window) start)
>
>  --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Enfocus issues

2012-06-14 Thread Andreas Kostler
Hi everyone,
I finally decided to give clojurescript a spin. Unfortunately, the momentum
died before I even got the ball running. I'm trying to replicate the
canonical example on the enfocus website using lein-cljsbuild [0.2.1] and
enfocus [0.9.1-SNAPSHOT]:


(ns my.namespace
  (:require [enfocus.core :as ef])
  (:require-macros [enfocus.macros :as em]))

(defn start []
  (em/at js/document
["body"] (em/content "Hello world!"))

(set! (.onload js/window) start)


lein cljsbuild once fails with the following error:

Compiling "resources/public/js/main.js" failed:
java.lang.AssertionError: Assert failed: set! target must be a field or a
symbol naming a var

Any clues?

Cheers
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Let over Lambda

2012-05-17 Thread Andreas Kostler
It treats reader macros in some detail which is not really applicable to
Clojure but it's a fun book :)

On 18 May 2012 11:53, P Martin  wrote:

> Hi everyone,
> I was perusing Amazon for some books on Clojure and Lisp and came across
> Let Over Lambda. From its reviews, it seems that this book may be useful
> for macro development in  Clojure. Has anyone else read this book? Do you
> think it would be a good book for Clojure work?
>
> 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 posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Compilation model

2012-02-23 Thread Andreas Kostler
Bump...I'm interested in this, too...

On 21 February 2012 12:29, T.Y Chew  wrote:

>
>
> Hi all,
>
> I had a question about clojure's compilation model, which my co-worker
> suggest to redirect here :-)
>
> I wonder what clojure does during compilation of a file? Can
> side-effects occur (definition of variables, functions, macros, etc in
> the compiler)? Does clojure have an EVAL-WHEN construct for specifying
> compile-time evaluations, or is there a convention for splitting code
> across different source files? And then, how does this tie in to a
> module system?
>
> Thanks in advance for any information or references :-)
>
> Yong
>
>
> --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en




-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Problem with amap over byte arrays

2012-02-16 Thread Andreas Kostler
How stupid of me.
Cheers


On 17 February 2012 12:12, dennis zhuang  wrote:

> Because bit-xor returns a integer,so you have to cast it to byte:
>
>
> (amap ^bytes an-array
>  idx
>  ret
>  (byte (bit-xor (byte 0)
> (aget ^bytes an-array idx
>
>
> 2012/2/17 Andreas Kostler 
>
>> Hi all,
>> I'm experiencing the following problem:
>>
>> (def an-array (byte-array 200 (byte 1)))
>> (amap ^bytes an-array
>>  idx
>>  ret
>>  (bit-xor (byte 0)
>> (aget ^bytes an-array idx)))
>>
>> Resulting in:
>>
>> No matching method found: aset
>>
>> Wheras this:
>>
>> (def another-array (int-array 200 (int 1)))
>> (amap ^ints an-array
>>  idx
>>  ret
>>  (bit-xor (int 0)
>> (aget ^ints another-array idx)))
>>
>> Works as expected. Does anyone know what's going on?
>> Clojure version is 1.3.0
>>
>> --
>> 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 are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>
>
>
>
> --
> 庄晓丹
> Email:killme2...@gmail.com xzhu...@avos.com
> Site:   http://fnil.net
> Twitter:  @killme2008
>
>
>
>
>  --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>



-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Problem with amap over byte arrays

2012-02-16 Thread Andreas Kostler
Hi all,
I'm experiencing the following problem:

(def an-array (byte-array 200 (byte 1)))
(amap ^bytes an-array
  idx
  ret
  (bit-xor (byte 0)
 (aget ^bytes an-array idx)))

Resulting in:

No matching method found: aset

Wheras this:

(def another-array (int-array 200 (int 1)))
(amap ^ints an-array
  idx
  ret
  (bit-xor (int 0)
 (aget ^ints another-array idx)))

Works as expected. Does anyone know what's going on?
Clojure version is 1.3.0

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Calling all Melbourne, Australia, Clojure users

2012-02-12 Thread Andreas Kostler
Hi all,
We have a similar group here in Adelaide "Forum for functional programming
practioners, from beginner to advanced. All languages, all welcome." @
http://www.meetup.com/acsafp/

It's nice to see groups like this are getting traction in Australia.
Cheers
Andreas



On 9 February 2012 22:29, James Sofra  wrote:

> Hi all,
>
> Good to see some interest!
>
> I have now started a meetup page http://www.meetup.com/clj-melb/
>
> Will organise more once we have some members.
>
> We have a place we should be able to meet in the CBD.
>
> Cheers,
> James Sofra
>
> --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Thin clojure wrapper for zeromq

2011-12-18 Thread Andreas Kostler
No worries :) Thanks for re-igniting my awareness of Storm.

On 19 December 2011 11:22, bjconlan  wrote:
> Sorry I should have read the full mail. For some reason I read it as a
> question for an alternative to clojure-zeromq. Ignore my previous
> email. It also doesn't support zmq.3x (only 2.x series).
>
> Sorry about that,
> B.
>
> On Dec 18, 6:10 pm, Andreas Kostler 
> wrote:
>> Hi All,
>> For a little hobby project I found myself looking for a clojure
>> wrapper for 0MQ. clojure-zeromq is stale and doesn't support zeromq >
>> 3.0.0 so I rolled my own:https://github.com/AndreasKostler/clj-0MQ
>>
>> It's in a very early stage of development but most of the
>> functionality is there. Furthermore, there are a bunch of working
>> examples for you to play with.
>>
>> Any feedback is very welcome.
>>
>> Cheers
>> Andreas
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Thin clojure wrapper for zeromq

2011-12-18 Thread Andreas Kostler
Hi All,
For a little hobby project I found myself looking for a clojure
wrapper for 0MQ. clojure-zeromq is stale and doesn't support zeromq >
3.0.0 so I rolled my own: https://github.com/AndreasKostler/clj-0MQ

It's in a very early stage of development but most of the
functionality is there. Furthermore, there are a bunch of working
examples for you to play with.

Any feedback is very welcome.

Cheers
Andreas


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Literate Programming in Emacs?

2011-11-22 Thread Andreas Kostler
It should work as expected if you follow
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html
and use the stand-alone version of swank-clojure (Section Connecting
with SLIME https://github.com/technomancy/swank-clojure).
Looking at ob-clojure.el http://kanis.fr/hg/lisp/org/ob-clojure.el
might give you some clues as well.
Hope that helps
Andreas

On 23 November 2011 09:04, Andrew  wrote:
> I should add that I am starting with a working setup (able to M-x
> clojure-jack-in and compile and execute stuff in the REPL as expected).
>
> --
> 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 are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772     Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Getting index of char from end

2011-11-13 Thread Andreas Kostler
How about using the clojure sequence functions?
(require '[clojure.contrib.seq-utils :as seq-utils])

(defn last-index-of [c string]
 (first (seq-utils/find-first (fn [[_ a]] (= a c)) (reverse
(seq-utils/indexed string)

P.S. Jong Won, how are you liking Clojure? I've met you in Parramatta
and joined the ADO team :) Nice to have you on the group here :)

Cheers
Andreas

On 13 November 2011 10:19, Tyler Perkins  wrote:
> Interesting. I never knew how to use areduce before. However, it
> always scans the entire array. If you had a very long string (or other
> collection), it might be better to scan backwards:
>
> user> (defn last-indexof [cs c]
>            (loop [n (dec (count cs))]
>               (if (and (<= 0 n) (not= c (nth cs n)))
>                   (recur (dec n))
>                   n)))
> #'user/last-indexof
> user> (last-indexof "aabbccd" \c)
> 5
> user> (last-indexof "aabbccd" \x)
> -1
>
>> areduce can be used too.
>>
>> (defn last-indexof [cs c]
>>   (areduce cs i lst-idx -1
>>     (if (= c (aget cs i)) i lst-idx)))
>>
>> (-> "aabbccd" to-array (last-indexof \c))
>>
>> Regards.
>> Jestan Nirojan
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Getting index of char from end

2011-11-13 Thread Andreas Kostler
How about using the clojure sequence functions?
(require '[clojure.contrib.seq-utils :as seq-utils])
(defn last-index-of [c string]
 (first (seq-utils/find-first (fn [[_ a]] (= a c)) (reverse
(seq-utils/indexed string)
P.S. Jong Won, how are you liking Clojure? I've met you in Parramatta
and joined the ADO team :) Nice to have you on the group here :)
Cheers
Andreas

On Nov 13, 6:54 pm, Andreas Kostler  wrote:
> How about using the clojure sequence functions?
> (require '[clojure.contrib.seq-utils :as seq-utils])
>
> (defn last-index-of [c string]
>  (first (seq-utils/find-first (fn [[_ a]] (= a c)) (reverse
> (seq-utils/indexed string)
>
> P.S. Jong Won, how are you liking Clojure? I've met you in Parramatta
> and joined the ADO team :) Nice to have you on the group here :)
>
> Cheers
> Andreas
>
> On 13 November 2011 10:19, Tyler Perkins  
> wrote:
>
>
>
>
>
>
>
> > Interesting. I never knew how to use areduce before. However, it
> > always scans the entire array. If you had a very long string (or other
> > collection), it might be better to scan backwards:
>
> > user> (defn last-indexof [cs c]
> >            (loop [n (dec (count cs))]
> >               (if (and (<= 0 n) (not= c (nth cs n)))
> >                   (recur (dec n))
> >                   n)))
> > #'user/last-indexof
> > user> (last-indexof "aabbccd" \c)
> > 5
> > user> (last-indexof "aabbccd" \x)
> > -1
>
> >> areduce can be used too.
>
> >> (defn last-indexof [cs c]
> >>   (areduce cs i lst-idx -1
> >>     (if (= c (aget cs i)) i lst-idx)))
>
> >> (-> "aabbccd" to-array (last-indexof \c))
>
> >> Regards.
> >> Jestan Nirojan
>
> > --
> > 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 are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Stanford Dabatabase Class Begins Tomorrow

2011-10-09 Thread Andreas Kostler
I am :)

On 10 October 2011 04:02, Harrison Maseko  wrote:
> The Stanford "Introduction to Databases" class officially starts
> tomorrow, October 10, 2011. I have enrolled and look forward to this
> nine-week online course. I was wondering if anyone on this list is
> taking it. It will be encouraging to know I am not the only Clojure
> programmer doing this!?
> -h.
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Does macros evaluates its arguments before?

2011-09-27 Thread Andreas Kostler
This is quite amusing since the first reply to the original post already
provided the correct answer :)
On Sep 28, 2011 6:05 AM, "Michał Marczyk"  wrote:
> Hi Ru,
>
> let's input your macro definition at the REPL:
>
> user> (defmacro infix [e] `(let [[x# f# y#] ~e] (f# x# y#)))
> #'user/infix
>
> So far so good. Now let's try use it in a function:
>
> user> (defn foo [] (infix (5 + 4)))
> #'user/foo
>
> Well now -- it compiled! So, there's no exception being thrown when
> the macro is expanded at compile time; otherwise foo would not have
> compiled.
>
> How about calling foo?
>
> user> (foo)
> ; Evaluation aborted.
> user> *e
> # cannot be cast to clojure.lang.IFn>
>
> There's your exception: at runtime. By this time there is no trace of
> your macro in the running code (you could undefine it -- by saying
> (ns-unmap 'user 'infix) -- and this would have no effect on foo).
>
>
> Once again: (5 + 4) *is not evaluated when the macro is expanded*. It
> is only evaluated at runtime -- and only then does it explode, as
> expected. The key point is that a macro is just a function called upon
> by the compiler to transform your program prior to it being compiled
> into JVM bytecode (in the case of Clojure, or perhaps native code in
> the case of some Common Lisp implementations and execution by the
> interpreter in interpreted Lisps); if it generates erroneous code
> (like this version of infix!), that erroneous code will be compiled by
> the compiler and eventually explode when you run it -- an unpleasant
> occurrence completely distinct from a macro-expansion-time exception.
>
> Sincerely,
> Michał
>
> --
> 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 are moderated - please be patient with
your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: suggestion for clojure development

2011-09-27 Thread Andreas Kostler
I'm with Phil on that one. Legacy support slows or even hinders innovation.
On Sep 28, 2011 6:06 AM, "Phil Hagelberg"  wrote:
> On Tue, Sep 27, 2011 at 11:57 AM, Arthur Edelstein
>  wrote:
>> So my request for Clojure's future development, is that backwards
>> compatibility not be broken. This means that Clojure code needs a way
>> of designating what Clojure version it is targeted for. Then, for
>> example, the Clojure 1.4 jar should be able to "drop down" into
>> backwards compatibility mode to compile and run 1.3-code, or invoke a
>> 1.3-script's vars from a 1.4 script. It would also be super-cool if
>> someone can figure out how to do this for existing 1.2 libraries.
>
> I'm all for breaking as little as possible, and it's worth pointing
> out that before the 1.3 release I have seen a total of two
> backwards-incompatible changes to Clojure since starting to use it in
> 2008, even going a fair ways before 1.0 was released. However, a full
> backwards-compatible emulation layer is asking an awful lot of the
> Clojure maintainers. I personally would rather see them spend their
> time on moving Clojure forward than legacy support.
>
>> I love that Clojure is being constantly improved and developed, and I
>> thank everyone who has been working so hard on it. In my opinion,
>> though, third-party libraries are as important as the core language.
>> Clojure 1.3 interoperates with java libraries very well -- so why not
>> with Clojure 1.2 libraries?
>
> You could do this with an independent classloader containing the old
> jars. It wouldn't be as seamless as regular method calls, but as long
> as the number of places where you cross the version boundary is fairly
> small it shouldn't be too heinous. I don't think this belongs in
> Clojure itself at all.
>
> -Phil
>
> --
> 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 are moderated - please be patient with
your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: small project to learn clojure

2011-09-18 Thread Andreas Kostler
If Robocode is fun to you, why not do that then:
http://nakkaya.com/2010/07/06/controlling-robocode-engine-from-clojure/
http://www.fatvat.co.uk/2009/05/clojure-and-robocode.html

There's also been a thread on this group about the same topic a while ago.
Hope this helps
Andreas

On 19 September 2011 10:39, Zack Maril  wrote:
> Confession:The best way I have found to learn a language is to pick a
> girl and make something that impresses her.
>
> When I was learning to use Node.js, I made a chat room for my
> girlfriend and I to talk in when we doing a long distance
> relationship. It had a sassy robot that pulled pictures of lolcats
> from reddit on command. Another weekend, I made a robot that would
> sext pickup lines if a girl messaged the right number. The simpler a
> project sounds, "a  flirty robot that I can sext!", the more
> complicated the implementation will be. Although it was easy to do in
> node, I imagine that making a sexting robot service with clojure would
> make you learn a great deal about state if you tried to go from simple
> pick up lines to a robot that could conduct multiple conversations at
> once with several different people/numbers.
>
> It's what has worked for me and will probably be the technique I use
> for the foreseeable future.  The idea is limited to topics that can be
> wrapped up into packages to impress women, but that is really just a
> exercise in imagination and creativity. Make friends with a math major
> and a whole field of abstract topics crop up that are fair game.
>
> Good luck!
> -Zack a.k.a American College Male
>
> P.S. I am extremely sorry if females feel left out by this advice.
> This is what has worked for me as a guy wishing to learn programming.
> I wish I had advice for you that would be more useful if you were
> trying to learn a language. If you generalized to make something you
> would want to show your friends, then it is probably still pretty
> applicable.
>
>>On Sep 17, 3:23 am, Thorsten Wilms  wrote:
>> On 09/16/2011 11:50 PM, Dennis Haupt wrote:
>>
>> > i feel compelled to do something more complex in clojure. not too big,
>> > but bigger than what fits in 100 lines and offers some chances to use
>> > macros.
>> > it should also be fun, maybe something like robocode.
>>
>> Something that is not primitive but may stay small or at least has
>> clearly defined boundaries right from start ... if you rule out pure
>> logic puzzles, this does point to games, I think.
>>
>> There are so many simple games, some of which must have been implemented
>> a million times. You could try to do one of those, but with a twist,
>> perhaps.
>>
>> Like a Pacman, but where you steer the ghosts (only one at a time,
>> changing the direction it heads to).
>>
>> Dungeonmaster-Sokoban, where you have to push boxes to create a path
>> that will lead to the hero's death, once he arrives. That without
>> trapping your own worker.
>>
>> OR, you look for an existing project, where you could implement a
>> missing feature. Ideally one where you could interact with the
>> author/contributors via IRC.http://www.webnoir.org/might be a
>> candidate, where a comment system or tagging come to mind (I'm not
>> affiliated and don't know if something like that is underway, already).
>>
>> --
>> Thorsten Wilms
>>
>> thorwil's design for free software:http://thorwil.wordpress.com/
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772     Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Thoughts on CUDA + Clojure

2011-09-08 Thread Andreas Kostler
Dissecting PyCuda might give you a headstart :)


On 9 September 2011 06:05, Michael Jaaka  wrote:
> Why not to translate to any lang? I though about translating clojure
> to php source code. It differs from jvm and crl (.net) approach that
> it is not translated to uni language to be run on one platform but
> translated to form/source understood by targeted hosting platform and
> ran on it.
>
> The clojurescript could be a base project, just put a layer of
> translators, which would differ along targeted hosting platforms.
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Documentation For Lisp Programming in Clojure.

2011-09-04 Thread Andreas Kostler
Sicp, the little schemer, seasoned schemer,norvigs paradigms of AI
programming. Seibels practical common lisp. Let over lambda. More Cl
specific is Sonja Kleenex PO programming in Cl or the metaobject protocol.
And there's more
 On Sep 4, 2011 4:48 AM, "octopusgrabbus"  wrote:
> I have seen the three current books on Clojure. They are all good general
> books that describe the whole language. I have not had a chance to see
Chas
> Emerick's new Clojure O'Reilly book, so cannot comment on that.
>
> Are there any books available or upcoming that concentrate more on Lisp
> programming in Clojure's dialect? If not, what is the closest Lisp dialect

> to Clojure and is the best book on teaching traversing trees, recursion,
and
> so on?
>
> Thanks.
> cmn
>
> --
> 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 are moderated - please be patient with
your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: clojure-based non-blocking webserver like Node.js

2011-09-03 Thread Andreas Kostler
Can someone explain please what class threads are?? And whether is threads
are expensive depends on the is

 On Sep 3, 2011 5:09 AM, "Raoul Duke"  wrote:
> On Fri, Sep 2, 2011 at 11:20 AM, billh2233  wrote:
>> I like Node.js's non-blocking IO for performance reasons, though it is
>> built around a single-threaded model whereas clojure is built around a
>> multi-core/concurrency model.  I wonder if the two concepts can be
>> combined somehow.
>
> * python lets you combine processes, pre-emptive threads, and
> coroutines. see the greenlet stuff.
>
> * class threads are heavy and context switches suck and that is one
> reason people don't like them vs. the node.js speeds. however, look at
> Erlang since it has very low context switching overhead, since it
> doesn't use OS threads.
> http://thatclevershark.org/benchmarks.html
>
> * theoretically, threads and event-driven styles are duals of each
> other, or maybe the same thing at some level.
> http://lamp.epfl.ch/~phaller/doc/haller07actorsunify.pdf
>
http://www.bluishcoder.co.nz/2006/04/unifying-events-and-threads-in-haskell.html
>
> sincerely.
>
> --
> 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 are moderated - please be patient with
your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: "Elegant tools deserve elegant solutions." -- L. E. Gant

2011-08-08 Thread Andreas Kostler
Hi Tuba,
I don't quite understand what you mean by "I’m having a hard time
thinking through the process of generating the
candidate suffix set using set forms" but I have created a porter
stemmer for English in the past.
I understand that's not what you're looking for but it is moreso a
framwork for building stemmers:

You specify rules of the like:
{:c? condition :s1 "abc" :s2 "efg" :a action}
reading if condition is met, replace s1 with s2 and execute action.
Where s1 could be a suffix etc. All you need to do is specify these rules.
Have a browse
https://github.com/AndreasKostler/Stout

Cheers
Andreas


On 8 August 2011 16:16, Tuba Lambanog  wrote:
>
> Hello,
>
> I’m doing a word stemmer for a non-English language. A stemmer parses
> a word into its word parts: prefixes, roots, suffixes. The input word
> is at least a root word (English example would be ‘cloud’), but can be
> any combination of  prefix(es) and a root (e.g., 'pre-nuptial'), or a
> root and suffix(es) (‘cloudy’), or all three ('unidirection'). A
> sequence of more than one prefix in a word is considered one
> occurrence of a prefix, and similarly for complex prefixes, thus,
> ‘directional’ is considered to have the ‘single’ suffix ‘ional’. The
> prefixes, roots, and suffixes are in their own set data structure.
>
> The approach I am pursuing is to create a set of potential suffixes
> that the input word contains. Asssume, for simplicity, that the suffix
> set consists of #{-or, -er, -al, -ion, -ional, able}. The input
> ‘directional’ would have the candidate suffix set #{-al –ional}. Now,
> drop the longest suffix (‘ional’) from the input then check the
> remaining string (‘direct’) if it is a root; if it is, done. If not,
> try the next suffix (‘-al’) in the potential suffix set.  Prefixes
> will be similarly processed. Input words with both prefixes and
> affixes will be fun to do ;)
>
> I’m having a hard time thinking through the process of generating the
> candidate suffix set using set forms, and I’m beginning to think I
> have selected an arduous path (for me).
>
> Thoughts?
>
> Thanks.
> Tuba
>
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
You're not discouraging...It's just mailing list 'etiquette' to check if some 
topic has been discussed before, I guess :)


On 19/07/2011, at 3:26 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 10:19 PM, Andreas Kostler
>  wrote:
>> I've posted the source as a suggested extension to:
>> https://github.com/pallet/thread-expr
>> As far as I'm concerned, that's the end of it :)
>> I'm sorry for reposting this topic...I should have checked the mailing list
>> history :(
> 
> No, please don't apologize. I'm sorry for discouraging you :(
> 
> I really hope thread-expr picks this up...
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
I've posted the source as a suggested extension to:
https://github.com/pallet/thread-expr

As far as I'm concerned, that's the end of it :)
I'm sorry for reposting this topic...I should have checked the mailing list 
history :(
Andreas

On 19/07/2011, at 3:12 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 9:57 PM, Andreas Kostler
>  wrote:
>> Hmm...I didn't get Chas' reply...Was that a private response?
> 
> No, it probably just hasn't gotten to everyone yet...? I see it on the web:
> 
> http://groups.google.com/group/clojure/browse_thread/thread/949abab9c206dc1a
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
I just realised I'm missing quite a few of the replies...including Kens.
I've gotta follow the web list more closely.
Andreas

On 19/07/2011, at 3:12 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 9:57 PM, Andreas Kostler
>  wrote:
>> Hmm...I didn't get Chas' reply...Was that a private response?
> 
> No, it probably just hasn't gotten to everyone yet...? I see it on the web:
> 
> http://groups.google.com/group/clojure/browse_thread/thread/949abab9c206dc1a
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
Hmm...I didn't get Chas' reply...Was that a private response? I sometimes feel 
I miss out on certain replies to the group.
Cheers
Andreas

On 19/07/2011, at 2:55 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 7:04 PM, Chas Emerick  wrote:
>> Just as a general comment: just because any of our idiosyncratic functions 
>> and macros aren't accepted for inclusion in Clojure proper does _not_ mean 
>> that they can't find a full and vigorous life in their own libraries.
> 
> Yeah, sorry, I kinda jumped on the negative instead of encouraging
> this to go into a community library :(
> 
>> In this particular case, I'll bet that someone has an arbitrary threading 
>> macro in a library somewhere you can use…or, you can create such a library.  
>> Given the number of times this has come up, I'm certain it would find some 
>> love.
> 
> This is the third(?) time so you are probably right. This might be a
> good place to start:
> 
> https://github.com/pallet/thread-expr
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: converting a string into a set

2011-07-18 Thread Andreas Kostler
In that case you don't need to convert to a symbol...
(set "abc") should be fine...

Using set intersection, something like this is probably what you're looking 
for...
(use 'clojure.set)
(if (empty? (intersection (set "abc") (set "cde"))) false true)) 

I'm sure there's other (better) ways though

On 19/07/2011, at 2:48 PM, Tuba Lambanog wrote:

> Hi,
> I'm clear on what I want ;) (something new to me), but I'm not clear on how 
> to get there. I'd like to compare str1 and str2, if at least one of the 
> letters in str1 is in str2. I'm thinking that if I can convert str1 and str2 
> to sets, then I can use the set intersection operation. It probably doesn't 
> matter here if the sets contain characters or symbols?
> Tuba
> 
> On Mon, Jul 18, 2011 at 10:31 PM, Benjamin Esham  wrote:
> Tuba Lambanog wrote:
> 
> > Tuba Lambanog wrote:
> >
> > > Hello, My apologies for this newbie question. I couldn't find a way to
> > > convert a string to a set, thus:
> > >
> > > "abc" => #{a b c}
> >
> > (set "abc") gives me #{\a \b \c}.  I'm expecting instead: #{a b c}
> 
> Hi Tuba,
> 
> Are you quite sure that #{\a \b \c} is not what you want? In Clojure's
> notation, a backslashed character [more or less] refers to a
> single-character string--something akin to the char type from C. Hence \a is
> the character a.  On the other hand #{a b c} is a set containing three
> Clojure symbols, which is probably not what you want.
> 
> (If you want to be using a, b, and c as some kind of identifiers, take a
> look at keywords.)
> 
> --
> Benjamin D. Esham  |  bdes...@gmail.com  |  www.bdesham.info
> How to Ask Questions the Smart Way, by Eric S. Raymond:
>  http://catb.org/~esr/faqs/smart-questions.html
> 
> --
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
Oh yeah, fair enough. 
I'm not convinced though. I don't see :? changing as such, as well as I think 
the syntactical representation below is just as confusing...
I'll rest this case :) It's not all that useful anyway.

On 19/07/2011, at 2:38 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 6:51 PM, Andreas Kostler
>  wrote:
>>> (-> "x"
>>>(#(str "y" % "z"))
>>>(#(str "a" % "b"))
>>>println)
>> Here, the meaning of % changes?!?
> 
> Not really, each #() is a scope for % as if it read:
> 
> (-> "x"
>((fn [x] (str "y" x "z")))
>((fn [c] (str "a" c "b"))
>println)
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: converting a string into a set

2011-07-18 Thread Andreas Kostler
I'm with Benjamin despite my last post...
On 19/07/2011, at 2:31 PM, Benjamin Esham wrote:

> Tuba Lambanog wrote:
> 
>> Tuba Lambanog wrote:
>> 
>>> Hello, My apologies for this newbie question. I couldn't find a way to
>>> convert a string to a set, thus:
>>> 
>>> "abc" => #{a b c}
>> 
>> (set "abc") gives me #{\a \b \c}.  I'm expecting instead: #{a b c}
> 
> Hi Tuba,
> 
> Are you quite sure that #{\a \b \c} is not what you want? In Clojure's
> notation, a backslashed character [more or less] refers to a
> single-character string--something akin to the char type from C. Hence \a is
> the character a.  On the other hand #{a b c} is a set containing three
> Clojure symbols, which is probably not what you want.
> 
> (If you want to be using a, b, and c as some kind of identifiers, take a
> look at keywords.)
> 
> -- 
> Benjamin D. Esham  |  bdes...@gmail.com  |  www.bdesham.info
> How to Ask Questions the Smart Way, by Eric S. Raymond:
>  http://catb.org/~esr/faqs/smart-questions.html
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: converting a string into a set

2011-07-18 Thread Andreas Kostler

On 19/07/2011, at 2:29 PM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 9:17 PM, Tuba Lambanog  
> wrote:
>> (set "abc")
>> gives me #{\a \b \c}.
>> I'm expecting instead: #{a b c}
> 
> (set (map "abc"))
> 
> (set (map str "Tuba Lambanog"))

This will produce #{"a" "b" "c"}

I think 
(set (map #(symbol (str %)) "abc"))
should do the trick

> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
]

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler

On 19/07/2011, at 11:47 AM, Sean Corfield wrote:

> On Mon, Jul 18, 2011 at 5:41 PM, Andreas Kostler
>  wrote:
>> Ups, I'm not aware of that thread...I just found a more general threading 
>> operator handy sometimes.
>> I do kinda agree that we shouldn't necessarily encourage threading in 
>> arbitrary positions.
>> However, I can't quite follow your second argument.
>> While it does mean two different things, I don't see the problem with that.
>> We could use _ instead of :? to indicate we don't care about the 'meaning'.
> 
> But _ means "don't care" by convention in Clojure, for values that are
> ignored...
> 
> The issue is about bindings and immutability: foo should mean the same
> value throughout an expression - that's kind of fundamental to Clojure
> (IMO). With your macro (and the previous examples introduced by
> others), some arbitrary symbol changes its meaning in each consecutive
> form without any marker for lexical or dynamic binding... so it's
> behaving like a mutable iterator or loop variable :(
I agree with that, however, :? or _ or whatever doesn't bind to anything. It 
merely gets replaced.
-> already does this in a hidden way...e.g. there's no symbol but the meaning 
of 'first argument' changes
in each consecutive form. 
> 
> With only a couple more characters you can already do what you need
> without a new macro:
> 
> (-> "x"
>(#(str "y" % "z"))
>(#(str "a" % "b"))
>println)
Here, the meaning of % changes?!?

> 
> There's also the possibility of mixing -> and ->> to splice in first
> arg / last arg threading. There was a great blog post about this
> recently but I can't find it (-> and ->> are remarkably hard to search
> for on Google!)...
I agree :) 
> -- 
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
> World Singles, LLC. -- http://worldsingles.com/
> Railo Technologies, Inc. -- http://www.getrailo.com/
> 
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Threading operator generalisation

2011-07-18 Thread Andreas Kostler
Ups, I'm not aware of that thread...I just found a more general threading 
operator handy sometimes.
I do kinda agree that we shouldn't necessarily encourage threading in arbitrary 
positions.
However, I can't quite follow your second argument.
While it does mean two different things, I don't see the problem with that.
We could use _ instead of :? to indicate we don't care about the 'meaning'.

Anyway, I'll delete this evil hack from my repository ;)


On 19/07/2011, at 10:33 AM, Sean Corfield wrote:

> Requests for a "more general" threading macro are usually met with a
> link to the thread where Rich says this is not needed and we should
> not encourage functions that need threading anywhere except the first
> or last position. I don't have the link handy (sorry).
> 
> The usual objection centers around the fact that whatever symbol is
> used for the binding position then becomes a "varying" thing within
> the expression:
> 
> (-newthread-> "x"
> (str "y" :? "z")
> (str "a" :? "b")
> println)
> 
> Here :? means two different things which seems counter to how Clojure
> works elsewhere...
> 
> Sean
> 
> On Mon, Jul 18, 2011 at 5:10 PM, Andreas Kostler
>  wrote:
>> Maybe you might find this useful
>> 
>> (defmacro ->
>>([x] x)
>>([x form] (if (seq? form)
>>  (with-meta (replace {:? x} form) (meta form))
>>  (list form x)))
>>([x form & more] `(-> (-> ~x ~form) ~@more)))
>> 
>> This allows for a more flexible threading operation:
>> 
>> user> (-> "c"
>>  (third-param "a" "b" :? "d")
>>  println)
>> first a second b third c fourth d
>> nil
>> 
>> Cheers
>> Andreas
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Threading operator generalisation

2011-07-18 Thread Andreas Kostler
Maybe you might find this useful

(defmacro ->
([x] x)
([x form] (if (seq? form)
  (with-meta (replace {:? x} form) (meta form))
  (list form x)))
([x form & more] `(-> (-> ~x ~form) ~@more)))

This allows for a more flexible threading operation:

user> (-> "c"
  (third-param "a" "b" :? "d")
  println)
first a second b third c fourth d
nil

Cheers
Andreas


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Recommendation for Clojure Enterprise Development toolkit

2011-07-09 Thread Andreas Kostler
What is generally considered "enterprise" then?

On 10/07/2011, at 9:07 AM, Sean Corfield wrote:

> In which case, apologies to Shree... but those lists don't really
> offer many companies that would generally be considered "enterprise"
> so I'm not sure how persuasive they would be (in either direction :)

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: rand-nth throwing an exception

2011-06-13 Thread Andreas Kostler
Hi Jarek,
Sometimes you want an exception to be thrown if an element in a collection
is not available, sometimes you want to deal with nil. I guess it depends on
your application of whether you'd go with get or nth. There's no wrong or
right here.
Andreas


On 13 June 2011 17:51, Jarek Siembida  wrote:

> > (nth [] 0) also throws an exception, so it is not so surprising.
>
> Thanks guys, just checked, rand-nth as a wrapper around
> nth inherits its semantics. So the question should rather be
> why nth throws an exception while get not.
> Out of curiosity I checked (peek []), returns nil too.
>
> jarek
>
> --
> In theory, there is no difference between theory and practice.
> But in practice, there is.
>
> --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>



-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: rand-nth throwing an exception

2011-06-12 Thread Andreas Kostler
Hi Jarek,
Have a look at the clojure documentation:

nth Returns the value at the index. get returns nil if index out of
bounds, nth throws an exception unless not-found is supplied. nth
also works for strings, Java arrays, regex Matchers and Lists, and,
in O(n) time, for sequences.

Unfortunately, you can't provide not-found for rand-nth, which probably is a 
bit inconsistent:
(nth [] 1)
=> OutOfBoundsException
(nth [] 1 0)
=> 0
(rand-nth [] 0) ;; Doesn't exist

On 13/06/2011, at 6:34 AM, jarek wrote:

> What am I missing here? Why is rand-nth throwing the oob exception
> instead of returning nil as I'd expect by analogy to other routines.
> 
> $ clojure
> Clojure 1.2.0
> user=> (rand-nth [1 2 3])
> 2
> user=> (rand-nth [])
> java.lang.IndexOutOfBoundsException (NO_SOURCE_FILE:0)
> user=> (get [1 2 3] 5)
> nil
> user=> (get [] 0)
> nil
> 
> 
> regards,
> 
> jarek
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Hierarchical Agglomerative Clustering

2011-06-06 Thread Andreas Kostler
Hi all, 
Please find below my take on the hac algorithm. I'd like to hear how I could 
improve on it. 
Especially the get-closest-pair function is ugly. I also don't like that I need 
transform the cluster to something vijual can draw. 
It would be much nicer to simply represent the tree as a nested vector (or 
list) but then I can't think of a way to do efficient removal of clusters.
Cheers
Andreas




(ns clj-sentiment.clustering.hac
  (:require [clj-sentiment.core :as core]))

;;; A bunch of sparse vector functions. Sparse vectors are represented as maps.

(defn div [v n]
  "Divide sparse vec v by n"
  (reduce (fn [m [k val]] (assoc m k (/ val n))) {} v))

(defn sum [a b]
  "Component wise sum of a and b"
  (merge-with + a b))

(defn average [& vecs]
  "Calculate the average over vecs."
  (let [n (count vecs)]
(reduce sum (map #(div % n) vecs

(defn diff-squared [a b]
  "Component wise difference of a and b"
  (merge-with (fn [a b] (let [diff (- a b)] (* diff diff))) a b))

(defn eucl-dist [v1 v2]
  (Math/sqrt (reduce + (vals  (diff-squared v1 v2)

;;; Enough sparse vector stuff ... Below is the actual algorighm...

;; "Uses memoization to remember distance calculations."
(def distance
  (memoize (fn [x y metric] (metric x y

(defn get-closest-pair [l metric]
  "Gets the closest vector pair according to metric."
  (first (sort-by peek
  (map (fn [[id1 vec1 id2 vec2]]
 [id1 id2 (distance vec1 vec2 metric)])
   (for [[id1 cl1 :as a] l [id2 cl2 :as b] (rest l) :when 
(not= a b)] [id1 (:vec cl1) id2 (:vec cl2)])

(defn create-cluster [{label :id :as document} id]
  (hash-map id {:label label :vec (core/get-feature-vec document) :left nil 
:right nil :dist nil}))

(defn create-initial-clusters [l]
  "Initially, there is one cluster per document. Clusters are stored in a map 
identified by their id for fast lookup."
  (apply merge (map create-cluster l (iterate inc 1

(defn hac [l metric]
  "Hierarchical agglomerative clustering algorithm."
  (loop [clust (create-initial-clusters l) id -1]
(if (<= (count clust) 1) clust
(let [[idi idj dist] (get-closest-pair clust metric)
  clusti (clust idi)
  clustj (clust idj)
  mergevec (average (:vec clusti) (:vec clustj))
  newclust {:left {idi clusti} :right {idj clustj} :dist dist :vec 
mergevec}]
  (recur (-> clust (dissoc idi) (dissoc idj) (assoc id newclust)) (dec 
id))

(defn tree-vis [[id {l :left r :right label :label} :as node] acc]
  (cond (nil? node) acc
(and (nil? l) (nil? r)) label
:else (conj acc (tree-vis (first r) acc) (tree-vis (first l) acc) '*)))

(vijual/draw-binary-tree (tree-vis (first (hac/hac l hac/eucl-dist)) ()))

 +---+
  |  * |
 +---+
 / \___  
/  \ 
   +---++---+
   | * || *   |
   +---++---+
  / \  / \  
 /   \/  \ 
+---+  +---+  +---+ +---+
| D ||  E |   | C |   | *  |
+---+  +---+  +---+ +---+
 / \  
/   \ 
   +---+  +---+
   | A  | | B |
   +---+   +---+

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Parsing HTML in clojure

2011-06-05 Thread Andreas Kostler
There's a Java library called HtmlCleaner. You might wanna give that a shot. 
Btw, I'm working on quite a similar project so if you like email me and we can 
maybe join forces.
Andreas

On 06/06/2011, at 11:01 AM, Base wrote:

> hi all,
> 
> I am working on an app that will parse web pages to do some NLP and
> statistics.  I am able to parse the HTML using several different tool
> ( enlive, HTML parser, etc).  However I would like to discard all the
> rest of the junk in the web page that is not pertinent (I.e. Ads).
> Does anyone have any experience doing this?  Any tips On how to do
> this - or even better, tools that you can recommend?   I have been
> digging around on this for a while now and am stuck!
> 
> Thanks!
> 
> Base
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Stout

2011-06-02 Thread Andreas Kostler
Yes, soon programming clojure will be like a night out in town...
On 02/06/2011, at 4:31 PM, David Jagoe wrote:

> Well I like the name!
> 
> On 2 June 2011 06:21, Andreas Kostler  
> wrote:
>> Hi All,
>> 
>> Stout is a porter stemmer implemention using a snowball-like syntax for 
>> defining rules.
>> Rules are of the form {:c? condition :s1 "abc" :s2 "efg" :a action}
>> reading if condition is met, replace s1 with s2 and execute action.
>> 
>> ## Usage
>> 
>> (use 'stout.porter-stemmer)
>> (map porter-stemmer coll)
>> 
>> Where coll is a collection of terms you intend to stem. Stemming output is a 
>> list of stemmed terms (stems).
>> 
>> 
>> You can find stout on my github: g...@github.com:AndreasKostler/Stout.git
>> 
>> Criticism is of all sorts is very welcome.
>> 
>> Kind Regards
>> Andreas
>> 
>> 
>> --
>> 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 are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Stout

2011-06-01 Thread Andreas Kostler
Hi All,

Stout is a porter stemmer implemention using a snowball-like syntax for 
defining rules. 
Rules are of the form {:c? condition :s1 "abc" :s2 "efg" :a action} 
reading if condition is met, replace s1 with s2 and execute action.

## Usage

(use 'stout.porter-stemmer)
(map porter-stemmer coll)

Where coll is a collection of terms you intend to stem. Stemming output is a 
list of stemmed terms (stems).


You can find stout on my github: g...@github.com:AndreasKostler/Stout.git

Criticism is of all sorts is very welcome.

Kind Regards
Andreas


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Idiomatic way to handle not existing map value

2011-05-31 Thread Andreas Kostler
Thanks Ken,
I should have known the (m :key 0) solution as I've used that before :(
Oh well :)
Andreas

On 01/06/2011, at 3:11 PM, Ken Wesson wrote:

> On Wed, Jun 1, 2011 at 1:05 AM, Andreas Kostler
>  wrote:
>> Hi all,
>> I find myself using the following pattern quite often:
>>  (assoc m :key (inc (or (:kay m) 0))
>> 
>> To increment or somehow transform a value in a map that I'm not sure it 
>> exists.
>> Is there an idiomatic way of doing this sort of thing in a short and concise 
>> way?
> 
> Well, these also work:
> 
> (assoc m :key (inc (m :key 0)))
> 
> (merge-with + m {:key 1})
> 
> (update-in m [:key] #(if % (inc %) 1))
> 
> The merge-with looks shortest and cleanest of the four to me, but
> that's just my opinion.
> 
> Incidentally, if you forget the brackets around :key in the update-in
> the error message you get is rather less specific than you'd hope:
> 
> => (update-in {:a 1} :key #(do (println %) (inc %)))
> # supported on this type: Keyword (NO_SOURCE_FILE:0)>
> 
> A :pre clause in update-in checking for coll? on the second argument
> could be added to produce an IAE with a more informative message
> instead of this somewhat vague UOE.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Idiomatic way to handle not existing map value

2011-05-31 Thread Andreas Kostler
Hi all,
I find myself using the following pattern quite often:
  (assoc m :key (inc (or (:kay m) 0))

To increment or somehow transform a value in a map that I'm not sure it exists.
Is there an idiomatic way of doing this sort of thing in a short and concise 
way?
Kind Regards
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Announcement: stockings clojure library for easy access to financial data

2011-05-31 Thread Andreas Kostler
I certainly will have a look. I'm working on a technical analysis library so 
you're lib will certainly be useful.
Andreas

On 01/06/2011, at 5:09 AM, fxt wrote:

> Hi everyone,
> 
> I just wanted to announce release 1.0 of my latest project: stockings.
> https://github.com/fxtlabs/stockings
> http://stockings.fxtlabs.com
> http://clojars.org/com.fxtlabs/stockings
> 
> I mentioned some of this work to some of you at the last Bonjure
> (Montreal Clojure User Group) meeting, so I thought someone might be
> interested.
> 
> Stockings is a Clojure library that gives you easy access to financial
> data such as current and historical stock quotes, current currency
> exchange rates, stock symbol suggestions, stock and company info by
> trading exchanges and industry sectors, and more.
> 
> It integrates information from different web services in a consistent
> way, doing all the error handling, JSON, XML, and CSV parsing, and all
> the other quirky data massaging for you.
> 
> I hope some of you will find it useful. Any feedback is welcome.
> 
> Thank you,
> 
> fxt
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Aw: Re: Aw: Protocol issues

2011-05-30 Thread Andreas Kostler
Meikel,
Adding import A to ns c did the trick! Thanks a lot.
Andreas



On 30/05/2011, at 10:42 PM, Meikel Brandmeyer wrote:

> Hi,
> 
> still works for me, although your c has a missing (:import a.A). Would you 
> mind posting the actual code with the true types stripped-down to the 
> minimum? Or some other minimal example, which verifyably fails for you?
> 
> Sincerely
> Meikel
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Aw: Protocol issues

2011-05-30 Thread Andreas Kostler
My bad, I'm calling foo in yet another namespace:

(ns c
  (:use b))

(def x (A. 1 2))
(bar x)

and that's when I get:

Throws: No single method: bar of interface: b.Foo found for function: bar of 
protocol: Foo
[Thrown class java.lang.IllegalArgumentException]

Cheers
Andreas
On 30/05/2011, at 10:23 PM, Meikel Brandmeyer wrote:

> Hi,
> 
> works for me in 1.2.0 and 1.3.0-alpha7. You might want to add a (:require a) 
> to the import, but I doubt that this is the cause of the problem.
> 
> Sincerely
> Meikel
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Protocol issues

2011-05-30 Thread Andreas Kostler
Hi all,
I have two clj files with two namespaces:

a.clj

(ns a)

(defrecord A [a b])

b.clj

(ns b
 (:import [a A]))

(defprotocol Foo
  (bar [s]))

(extend-type A
  Foo
  (bar [s] (println s)))

(def x (A. 1 2))
(bar x)

Throws: No single method: bar of interface: b.Foo found for function: bar of 
protocol: Foo
[Thrown class java.lang.IllegalArgumentException]


Has anyone a clue what's going on? :)

Cheers
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Matrix operation (a la numpy)

2011-05-28 Thread Andreas Kostler
I'm not 100% sure but I think Incanter has matrix ops.
Andreas

On 28/05/2011, at 7:15 PM, JuanManuel Gimeno Illa wrote:

> I'm looking for a clojure library to perfomr matrix manipulation a la numpy. 
> The best candidate I've found is infer.matrix but I wonder if there is a 
> hidden jewel to discover.
> 
> Anyone has other suggestions?
> 
> Thanks,
> 
> Juan Manuel
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Recur and primitives?!?

2011-05-26 Thread Andreas Kostler
The question is though, why doesn't this work to begin with and why does it 
work on 1.3.0-master-SNAPSHOT...?
Is it broken or am I doing something wrong? :)
Andreas


On 27/05/2011, at 1:28 PM, Ken Wesson wrote:

> On Thu, May 26, 2011 at 10:28 PM, Armando Blancas
>  wrote:
>> Coercing m to int somehow prevents h from being boxed:
>> 
>> user=> (defn bin-search [v k c]
>>  (loop [l 0
>> h (dec (count v))]
>>(if (> l h) false
>>(let [m (int (quot (+ l h) 2))
>>  m-v (v m)]
>>  (cond (> m-v k) (recur (inc m) h)
>>(> k m-v) (recur l (dec m))
>>:else m)
>> #'user/bin-search
>> user=>
> 
> I doubt it. Rather, m is now an int so (dec m) can be a valid recur for h.
> 
> The real question is why h was primitive to begin with, since there's
> no coercion of h to int in either version of the code.
> 
> To make this really fast you will want to use int throughout, though,
> and unchecked arithmetic:
> 
> (defn bin-search-fast [v k]
>  (loop [l (int 0)
> h (int (dec (count v)))]
>(if (> l h) false
>  (let [m (unchecked-divide (unchecked-add l h) 2)
>m-v (v m)]
>(cond
>  (< m-v k) (recur (unchecked-inc m) h)
>  (< k m-v) (recur l (unchecked-dec m))
>  :else m)
> 
> This works on ascending values:
> 
> => (bin-search-fast (vec (map #(* % %) (range 1000))) 4096)
> 64
> 
> And despite the proliferation of fast, wrapping unchecked-foo
> operations, it is perfectly safe.
> 
> The thing that would overflow and wrap first is the sum of l and h.
> The worst case occurs when the target's right at the end of the
> vector, and l ends up nearly equal to h, which stays one less than the
> length of the vector. Then we're adding length - 1 and length - 2 for
> 2*length - 3. This has to stay below 2147483647, so the maximum vector
> length this can support is 2147483650/2 or 1073741825.
> 
> Over a billion items; that takes up 4GB just for the object pointers
> in the vector. You cannot hit this limit on 32-bit hardware -- OOME
> would be thrown first -- and on 64-bit there'd be no penalty from
> changing the code to use long instead of int, which makes the maximum
> vector size enormously larger than you're likely to use in the
> foreseeable future even on 64-bit hardware.
> 
> The speed difference is about a factor of two:
> 
> => (defn bin-search-slow [v k]
> (loop [l 0
>h (Integer/valueOf (dec (count v)))]
>   (if (> l h) false
> (let [m (quot (+ l h) 2)
>   m-v (v m)]
>   (cond
> (< m-v k) (recur (inc m) h)
> (< k m-v) (recur l (dec m))
> :else m)
> #'user/bin-search-slow
> => (def squares (vec (map #(* % %) (range 1000
> #'user/squares
> => (time (dotimes [_ 1000] (bin-search-slow squares 4096)))
> "Elapsed time: 1.37656 msecs"
> => (time (dotimes [_ 1000] (bin-search-fast squares 4096)))
> "Elapsed time: 0.7608 msecs"
> 
> (Each timing is after several repetitions of the (time ...) line
> preceding it, once the numbers have settled down as the JIT has done
> its thing, on the hotspot server VM.)
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
That explains the good performance. Either way, the implementation is quite a 
bit clearer.

I've also compared some operations of sparse-vec vs. plain map. 
The inner product is slightly faster for vecs with < 10 elements, then map 
takes over.
norm and unit-vector operations are quite in favour of sparse-vecs (~ 4 times 
faster than map based implementations).

Obviously, assoc on a map is way faster than the sparse-vec implementation of 
assc below...

Kind Regards
Andreas


On 27/05/2011, at 11:11 AM, Ken Wesson wrote:

> On Thu, May 26, 2011 at 8:50 PM, Andreas Kostler
>  wrote:
>> Thanks Ken,
>> using this approach brings a ~1000 times speedup :)
>> 
>> (def a (sparse-vec (range 10) (range 10)))
>> 
>> (def b (time (assc-ken a 11 0)))
>> "Elapsed time: 0.249 msecs"
>> 
>> (def b (time (assc a 11 0)))
>> "Elapsed time: 252.06 msecs"
>> 
>> Very worthwhile and it's clearer as well.
> 
> You're welcome. Keep in mind that this is a best-case insert, right at
> the end, for the algo I posted. Inserts at the beginning won't be very
> much faster than before, and in the middle will be in the middle.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
Thanks Ken,
using this approach brings a ~1000 times speedup :)

(def a (sparse-vec (range 10) (range 10)))

(def b (time (assc-ken a 11 0)))
"Elapsed time: 0.249 msecs"

(def b (time (assc a 11 0)))
"Elapsed time: 252.06 msecs"

Very worthwhile and it's clearer as well.
Cheers
Andreas


On 26/05/2011, at 11:11 PM, Ken Wesson wrote:

> On Thu, May 26, 2011 at 8:19 AM, Andreas Kostler
>  wrote:
>>  (let [new-indices (sort (conj indices i))
>>new-idx (bin-search new-indices i)
>>[chunk1 chunk2] (split-at new-idx vals)]
>>(SparseVec. new-indices (into (conj (vec chunk1) o) chunk2))
>>  (ith-val [this i]
>>(get vals (bin-search indices i) 0)))
>> 
>> Can you guys think of ways of making this more idiomatic and/or performant?
> 
> Yes. Drop the sort and avoid split-at. Just use binary search to find
> the correct value for new-idx (the position of the next index higher
> than i, or else the indices vector's length) and then
> 
> (SparseVec.
>  (into (conj (subvec indices 0 new-idx) i) (subvec indices new-idx))
>  (into (conj (subvec vals 0 new-idx) o) (subvec vals new-idx)))
> 
> The binary search you're doing anyway, and subvec is cheap. There's
> one more into on vectors, but the sort would have been n log2 n and
> the into is n log32 n, indeed k log32 k where k is the length of the
> tail. The latter logarithmic factors are much smaller at a given
> length of vector.
> 
> Tune this, then test its performance against a naive solution using a
> plain-jane hash map.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Recur and primitives?!?

2011-05-26 Thread Andreas Kostler
Hi guys,
I'm kinda lost as to what's going on here...With clojure-1.2.0 

(defn bin-search [v k c]
  (loop [l 0
 h (dec (count v))]
(if (> l h) false
(let [m (quot (+ l h) 2)
  m-v (v m)]
  (cond (> m-v k) (recur (inc m) h)
(> k m-v) (recur l (dec m))
:else m)

This bombs out with:
java.lang.IllegalArgumentException: recur arg for primitive local: h must be 
matching primitive

With 1.3.0-master-SNAPSHOT it works fine. Any ideas what I'm doing wrong?
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficient sparse vector representation...

2011-05-26 Thread Andreas Kostler
This is what I've come up with so far...it should give a bit of an idea of what 
I'm using it for:

(defprotocol PSparseVec
  (norm [this])
  (cnt [this])
  (ith-val [this i])
  (unit-vec [this])
  (assc [this i o]))

(defrecord SparseVec [indices vals]
  PSparseVec
  (cnt [this] (count indices))
  (norm [this] (Math/sqrt (reduce + (map #(* % %) vals
  (unit-vec [this] (let [l-inv (/ 1 (norm this))] (SparseVec. indices (vec (map 
#(* l-inv %) vals)
  (assc [this i o]
(let [idx (bin-search indices i)
  val (get vals idx nil)]
  (if val (SparseVec. indices (assoc vals idx o))
  (let [new-indices (sort (conj indices i))
new-idx (bin-search new-indices i)
[chunk1 chunk2] (split-at new-idx vals)]
(SparseVec. new-indices (into (conj (vec chunk1) o) chunk2))
  (ith-val [this i]
(get vals (bin-search indices i) 0)))

Can you guys think of ways of making this more idiomatic and/or performant?

Cheers
Andreas

On 26/05/2011, at 1:12 PM, Ken Wesson wrote:

> On Wed, May 25, 2011 at 10:22 PM, Andreas Kostler
>  wrote:
>> Yes and no. I need efficient two way lookup.
>> 
>> So, I need to do something like
>> For every key in {12 "a" 23 "aa" 234 ""}
>> Get the token in a map that is organised like this:
>> {token1 id1 token2 id2 token2 id3}
>> 
>> Naively, I could have two maps with the reverse lookups.
>> l1 = {token1 id1 token2 id2 token3 id3}
>> reverse = {id1 token1 id2 token2 ...}
>> 
>> Given that there will be many, many tokens this seems a bit too much 
>> overhead.
>> 
>> You could basically do a binarySearch on a sorted hash map (sorted by vals 
>> (e.g. ids)) but I thought
>> doing the search on a vec of vectors would be more efficient and the vec of 
>> vecs representation would
>> be more compact.
>> 
>> I guess that's what I'm trying to figure out.
>> 
>> Andreas
>> 
>> P.S. Lookup by token is more frequent than lookup by id, hence the bin 
>> search on id.
> 
> If the token and id sets are disjoint (no single object can ever
> appear as each -- only one of those at most) then you can use a single
> map with a function put defined as:
> 
> (defn put [m k v]
>  (assoc (assoc m k v) v k))
> 
> which adds mappings in both directions. Then just use (m k) or (m v)
> to perform lookups in either direction. The overhead may be less than
> with two separate hashmaps, and the code is certainly simpler.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: finding a key which does not exist in the map

2011-05-26 Thread Andreas Kostler
If you have control over the creation of the map, you could use something like 
a global counter to provide the next valid key.
You could also use a sorted map and just increment to last (biggest) key in the 
map.
Or you could use a random number. If the range is big enough, the probability 
of collisions will be low. In case of a collision you just draw again. 

On 26/05/2011, at 8:43 PM, Sunil S Nandihalli wrote:

> Hello everybody,
>  I was wondering if there is a way to find a key which does not exist in a 
> map in an efficient way. you can assume that all the keys are integers. 
> I currently do something like 
> 
> (defn non-existent-key [mp]
> (first (filter (comp not mp) (range
> 
> 
> Is there a possibly more efficient way of doing this?
> Thanks,
> Sunil.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Efficient sparse vector representation...

2011-05-25 Thread Andreas Kostler
On that note, 
is there an easy way of measuring memory usage?
Andreas

On 26/05/2011, at 1:12 PM, Ken Wesson wrote:

> On Wed, May 25, 2011 at 10:22 PM, Andreas Kostler
>  wrote:
>> Yes and no. I need efficient two way lookup.
>> 
>> So, I need to do something like
>> For every key in {12 "a" 23 "aa" 234 ""}
>> Get the token in a map that is organised like this:
>> {token1 id1 token2 id2 token2 id3}
>> 
>> Naively, I could have two maps with the reverse lookups.
>> l1 = {token1 id1 token2 id2 token3 id3}
>> reverse = {id1 token1 id2 token2 ...}
>> 
>> Given that there will be many, many tokens this seems a bit too much 
>> overhead.
>> 
>> You could basically do a binarySearch on a sorted hash map (sorted by vals 
>> (e.g. ids)) but I thought
>> doing the search on a vec of vectors would be more efficient and the vec of 
>> vecs representation would
>> be more compact.
>> 
>> I guess that's what I'm trying to figure out.
>> 
>> Andreas
>> 
>> P.S. Lookup by token is more frequent than lookup by id, hence the bin 
>> search on id.
> 
> If the token and id sets are disjoint (no single object can ever
> appear as each -- only one of those at most) then you can use a single
> map with a function put defined as:
> 
> (defn put [m k v]
>  (assoc (assoc m k v) v k))
> 
> which adds mappings in both directions. Then just use (m k) or (m v)
> to perform lookups in either direction. The overhead may be less than
> with two separate hashmaps, and the code is certainly simpler.
> 
> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficient sparse vector representation...

2011-05-25 Thread Andreas Kostler

On 26/05/2011, at 1:12 PM, Ken Wesson wrote:

> On Wed, May 25, 2011 at 10:22 PM, Andreas Kostler
>  wrote:
>> Yes and no. I need efficient two way lookup.
>> 
>> So, I need to do something like
>> For every key in {12 "a" 23 "aa" 234 ""}
>> Get the token in a map that is organised like this:
>> {token1 id1 token2 id2 token2 id3}
>> 
>> Naively, I could have two maps with the reverse lookups.
>> l1 = {token1 id1 token2 id2 token3 id3}
>> reverse = {id1 token1 id2 token2 ...}
>> 
>> Given that there will be many, many tokens this seems a bit too much 
>> overhead.
>> 
>> You could basically do a binarySearch on a sorted hash map (sorted by vals 
>> (e.g. ids)) but I thought
>> doing the search on a vec of vectors would be more efficient and the vec of 
>> vecs representation would
>> be more compact.
>> 
>> I guess that's what I'm trying to figure out.
>> 
>> Andreas
>> 
>> P.S. Lookup by token is more frequent than lookup by id, hence the bin 
>> search on id.
> 
> If the token and id sets are disjoint (no single object can ever
> appear as each -- only one of those at most) then you can use a single
> map with a function put defined as:
> 
> (defn put [m k v]
>  (assoc (assoc m k v) v k))
> 
> which adds mappings in both directions. Then just use (m k) or (m v)
> to perform lookups in either direction. The overhead may be less than
> with two separate hashmaps, and the code is certainly simpler.
> 
Hi Ken,
That indeed could be useful. What are your thoughts on the proposed solution of 
representing
sparse vectors as maps (id-> val)? Having a vec of vector or a map with ids and 
vals vectors
{:ids [vec of ids] :vals [vec of val]} is just a lot easier to deal with for 
calculations. E.g normalisation 

;; For a sparse vector as map
(defn normalise-m [m]
(let [vals (vals m)
 keys (keys m)
 l (Math/sqrt (reduce + (map #(* % %) vals)))]
 (zipmap keys (map #(/ % l) vals

;; For a map of id/val vecs
(defn normalise [sv]
(let [l (Math/sqrt (reduce + (map #(* % %) (:vals sv]
 {:i (:i sv) :vals (map #(/ % l) (:vals sv))}))

The latter outperforms the former by more than a factor of 10. 

Has anyone used sparse vectors or think of a reasonable implementation?




> -- 
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Efficient sparse vector representation...

2011-05-25 Thread Andreas Kostler
Yes and no. I need efficient two way lookup. 

So, I need to do something like
For every key in {12 "a" 23 "aa" 234 ""}
Get the token in a map that is organised like this:
{token1 id1 token2 id2 token2 id3}

Naively, I could have two maps with the reverse lookups.
l1 = {token1 id1 token2 id2 token3 id3}
reverse = {id1 token1 id2 token2 ...}

Given that there will be many, many tokens this seems a bit too much overhead.

You could basically do a binarySearch on a sorted hash map (sorted by vals 
(e.g. ids)) but I thought
doing the search on a vec of vectors would be more efficient and the vec of 
vecs representation would
be more compact.

I guess that's what I'm trying to figure out.

Andreas

P.S. Lookup by token is more frequent than lookup by id, hence the bin search 
on id.




The sparse vec will be [id val] pairs.
There is a big map of token-> id. So I can get to the id of a word vial 
(token-map token)
If I now have a map of 
{id1 token1 id1 token2 ... } 
On 26/05/2011, at 12:00 PM, Alan Malloy wrote:

> I think you've reinvented hashmaps:
> 
> {12 "a" 23 "aa" 25 "aaa" 234 ""}
> 
> On May 25, 6:51 pm, Andreas Kostler 
> wrote:
>> Hi all,
>> has anyone spent some thought on how to efficiently represent sparse vectors 
>> in Clojure?
>> A naive scheme I came up with is using a vector of [idx val] pairs, e.g.:
>> (def sparse-vec [[12 "a"][23 "aa"][25 "aaa"][234 ""]])
>> 
>> Accessing a value at an idx can be done so:
>> (get-nth sparse-vec 25)
>> => "aaa"
>> 
>> with:
>> 
>> (defn get-nth [sparse-vec n]
>> (let [indices (map (fn [[i _]] i) sparse-vec)
>>  idx (java.util.Collections/binarySearch indices n)
>>  [_ v] (nth sparse-vec idx)]
>> v))
>> 
>> For this to work the indices have to be in order. Can anyone think of more 
>> efficient (algorithmically and implementation wise)
>> ways of doing this?
>> 
>> Kind Regards
>> Andreas
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Efficient sparse vector representation...

2011-05-25 Thread Andreas Kostler
Hi all,
has anyone spent some thought on how to efficiently represent sparse vectors in 
Clojure?
A naive scheme I came up with is using a vector of [idx val] pairs, e.g.:
(def sparse-vec [[12 "a"][23 "aa"][25 "aaa"][234 ""]])

Accessing a value at an idx can be done so:
(get-nth sparse-vec 25)
=> "aaa"

with:

(defn get-nth [sparse-vec n]
(let [indices (map (fn [[i _]] i) sparse-vec)
 idx (java.util.Collections/binarySearch indices n)
 [_ v] (nth sparse-vec idx)]
v)) 

For this to work the indices have to be in order. Can anyone think of more 
efficient (algorithmically and implementation wise)
ways of doing this?

Kind Regards
Andreas


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: List comprehension and sets

2011-05-24 Thread Andreas Kostler
Hi, 
try 

(set (for [x (range 4)] (* x 4)))

Cheers
Andreas

On 24/05/2011, at 8:40 PM, MarisO wrote:

> Is it possible to use list comprehension to generate a set ?
> For example in scala I can do:
> 
> for (i <- (2 to 8).toSet[Int]) yield p(i)
> 
> In clojure this
> 
> (for [ x (set (range 4))] (* 4 x))
> 
> generates a list.
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: lein and private locally installed classes

2011-05-24 Thread Andreas Kostler
lein install
or
mvn
 mvn install:install-file -DgroupId=blub -DartifactId=blub -Dversion=1 
-Dpackaging=jar -Dfile=/path/to/file

On 24/05/2011, at 5:55 PM, Eric S Fraga wrote:

> Hello,
> 
> I've trawled the 'net etc. but have not been able to find the answer to
> a simple question: how can I tell lein that I want to access classes
> from a Java package installed locally on my system but not publicly
> available?
> 
> If I use "lein repl" from outside a lein project, the class path set up
> seems to be what I have specified in the CLASSPATH environment variable.
> However, as soon as I try this from within a lein project, the class
> path is now defined by the project.clj file.  This makes sense.
> 
> Therefore, I want to tell lein that, for a given project, I have Java
> packages in, say, ${HOME}/share/classes that I wish to access from
> within that project.  Can any body point me in the right direction?  I
> assume I need to add something to the project.clj file but have not been
> able to determine what this should be.  Apologies if this is a n00b
> question.
> 
> I currently have clojure 1.2.1 and lein 1.5.2 installed.  I am happy to
> upgrade if necessary, of course.
> 
> Thanks,
> eric
> 
> -- 
> : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 + No Gnus v0.18
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure example code snippets

2011-05-19 Thread Andreas Kostler
Hi Armando,
I'm working on a Clojurej library for sentiment analysis which doesn't contain 
everything you'd want for nlp but quite a nice subset of input modules (plain 
text corpora, rss feeds, html, etc...),
tokenising/normalising filters (noise removal, porter stemmer, etc), 
distance/similarity metrics (euclidean, cosine, peasrsons, Jaccard/Tanimoto), 
b-o-w vector representation, clustering (hierarchical, k-means), classification 
(NN, Bayes, knn), and some other little tidbits to tie up loose ends. There 
will be a first release in about 2-3 weeks time. If you're planning on doing 
work in that direction, maybe we could join forces :)
Kind Regards
Andreas
 
On 20/05/2011, at 5:12 AM, Armando Blancas wrote:

> Just in case I'll mention that Meikel's use of (with-open) will
> automatically close the reader.
> 
> On May 19, 11:40 am, dokondr  wrote:
>> On May 19, 6:52 pm, Meikel Brandmeyer  wrote:
>> 
>>> Hi,
>> 
>>> something like the following should work.
>> 
>>> (with-open [rdr (java.io.FileReader. "file.txt")]
>>>   (doseq [line (line-seq rdr)
>>>   word (.split line "\\s")]
>>> (when (.endsWith word "ing")
>>>   (println word
>> 
>>> Sincerely
>>> Meikel
>> 
>> Thanks everybody! The short one from Meikel (above) looks nice to
>> me :)
>> 
>> And the one from ClojureDocs too:
>> 
>> (defn read-lines
>>   "Like clojure.core/line-seq but opens f with reader.  Automatically
>>   closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE."
>>   [f]
>>   (let [read-line (fn this [^BufferedReader rdr]
>> (lazy-seq
>>  (if-let [line (.readLine rdr)]
>>(cons line (this rdr))
>>(.close rdr]
>> (read-line (reader f
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Efficient moving average

2011-05-09 Thread Andreas Kostler
Hi all,
I'm trying to calculate the moving average of a certain window size.
One straight forward approach is:
(defn lazy-avg [coll]
  (let [[sum cnt] (reduce
   (fn [[v c] val] [(+ val v) (inc c)])
   [0 0]
   coll)]
(if (zero? cnt) 0 (/ sum cnt

(let [window-size 5
  n 100]
  (map lazy-avg (partition window-size 1 (range 0 n)))

This takes about 2 seconds for 10^6 elements on my box. How can I
improve the runtime?
A slightly more performant (not much) approach keeping a rolling sum
would be:

(defn partialsums [start lst]
  (lazy-seq
(if-let [lst (seq lst)]
  (cons start (partialsums (+ start (first lst)) (rest lst)))
  (list start

(defn sliding-window-moving-average [window lst]
  (map #(/ % window)
   (let [start   (apply + (take window lst))
 diffseq (map - (drop window lst) lst)]
 (partialsums start diffseq

However, this causes the jvm to run out of heap space for n > 10^6

Is ~ 2 seconds the best I can do?

Cheers
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Request for feedback: Tradui

2011-05-08 Thread Andreas Kostler
Hi all,
I've started development on tradui, a translator for the Creole markup
language. It is not finished or in any deployable shape or form yet,
however it's progressed enough to gather some feedback on the approach
taken.
Please feel free to clone https://github.com/AndreasKostler/tradui.git
and comment away.
Kind Regards
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Where's incanter chrono?

2011-05-08 Thread Andreas Kostler
Cheers :)

On 08/05/2011, at 8:17 PM, Edmund Jackson wrote:

> I think the code has been under development and is now here: 
> https://github.com/getwoven/clj-time as clj-time.
> 
> On 8 May 2011, at 05:53, Andreas Kostler wrote:
> 
>> Hello all,
>> Has incanter.chrono disappeared?
>> (use '(incanter core chrono))
>> results in
>> Could not locate incanter/chrono__init.class or incanter/chrono.clj on
>> classpath:
>> [Thrown class java.io.FileNotFoundException]
>> 
>> For both incanter 1.2.3 and incanter 1.2.2
>> 
>> Cheers
>> Andreas
>> 
>> -- 
>> 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 are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Where's incanter chrono?

2011-05-07 Thread Andreas Kostler
Hello all,
Has incanter.chrono disappeared?
(use '(incanter core chrono))
results in
Could not locate incanter/chrono__init.class or incanter/chrono.clj on
classpath:
  [Thrown class java.io.FileNotFoundException]

For both incanter 1.2.3 and incanter 1.2.2

Cheers
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Request for feedback: Tradui

2011-05-07 Thread Andreas Kostler
Hi all,
I've started development on tradui, a translator for the Creole markup 
language. It is not finished or in any deployable shape or form yet, however 
it's progressed enough to gather some feedback on the approach taken.
Please feel free to clone https://github.com/AndreasKostler/tradui.git and 
comment away. 
Kind Regards
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Adding key values in a list of maps

2011-04-14 Thread Andreas Kostler
Or: (reduce #(+ %1 (:b %2)) 0 p)

:)
On Apr 15, 10:51 am, Andreas Kostler  wrote:
> (reduce + (map :b p))
> Cheers
> Andreas
>
> On 15 April 2011 10:43, Bhinderwala, Shoeb 
> wrote:
>
>
>
>
>
>
>
>
>
> >  I am a beginner in Clojure.
>
> > I have a list of maps:
>
> > (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
>
> > How do I add up all the :b values in the map? Result should be 9 (=2+3+4)
>
> > I know I should be using one of the higher level functions like apply,
> > reduce and combine it with a custom filter function. But not sure how to
> > write it.
>
> > ***-- Shoeb*
>
> >  --
> > 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 are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
>
> --
> **
> Andreas Koestler, Software Engineer
> Leica Geosystems Pty Ltd
> 270 Gladstone Road, Dutton Park QLD 4102
> Main: +61 7 3891 9772     Direct: +61 7 3117 8808
> Fax: +61 7 3891 9336
> Email: andreas.koest...@leica-geosystems.com
>
> www.leica-geosystems.com*
>
> when it has to be right, Leica Geosystems
>
> Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Adding key values in a list of maps

2011-04-14 Thread Andreas Kostler
(reduce + (map :b p))
Cheers
Andreas


On 15 April 2011 10:43, Bhinderwala, Shoeb wrote:

>  I am a beginner in Clojure.
>
> I have a list of maps:
>
> (def p '({:a 1 :b 2 :c 4}, {:a 2 :b 3 :c 5}, {:a 3 :b 4 :c 6}))
>
> How do I add up all the :b values in the map? Result should be 9 (=2+3+4)
>
> I know I should be using one of the higher level functions like apply,
> reduce and combine it with a custom filter function. But not sure how to
> write it.
>
> ***-- Shoeb*
>
>  --
> 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 are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en




-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Erlangs Bin for Clojure

2011-04-13 Thread Andreas Kostler
I'm quite impressed with Erlang's Bin datatype and binary pattern matching. 
I've tried to replicate some of the coolness in Clojure..
So, what can you do with it? 

Create a bin: 
  user> (<< 1 17 42)
  (1 17 42)
 
  user> (<< [0xf0f0 16] 1 17)
  (240 240 1 17)

  user> (<< "abc")
  (97 98 99)

More interesting is probably constructing a bin from a set of bound variables:
  user> (let [A 1
 B 17
 C 42
 bin (<< A B [C 16])] bin)
  (1 17 0 42)

A bin can also be used for matching: 
  user> (bin-let [[D 16 E 8 F 8] (1 17 00 42)] 
  [D E F])
  [273 0 42]

That's pretty much the gist of it. Please feel free to look at the code at
g...@github.com:AndreasKostler/Binj.git

I've only put it up this morning so please don't expect polished code or 
comments ;)

I'm VERY interested in your feedback...about functionality, style, idiomatic 
usage of the language, etc.
Be as anal as possible, I'm still learning.

Cheers
Andreas


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-03 Thread Andreas Kostler
There you go, symmetry and simplicity :)

On 04/04/2011, at 6:35 AM, Alan wrote:

> Isn't all this just a special case of partition-by?
> 
> (defn drop-by [f coll]
>  (apply concat (rest (partition-by f coll
> 
> (defn take-by [f coll]
>  (first (partition-by f coll)))
> 
> user> (drop-by (partial + 2) [2 2 2 3 3 4])
> (3 3 4)
> user> (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42])
> (1 4 1 7 34 16 10)
> 
> On Apr 3, 6:34 am, Meikel Brandmeyer  wrote:
>> Hi,
>> 
>> On 3 Apr., 13:18, Ken Wesson  wrote:
>> 
>>> "Less" involved?
>> 
>> Your solution combines 5 sequences with drop-while-first-map-second
>> magic which I personally don't find very self-explaining at first
>> sight. My solution does one step with only local impact and then
>> delegates to a single well-known library function.
>> 
>> For laziness there is some cost involved, I agree.
>> 
>> Sincerely
>> Meikel
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-03 Thread Andreas Kostler
Hi Stefan,
I am overwhelmed by the 'freedom of choice' Clojure gives you, too. In that 
respect it's more like ruby than python.
Nevertheless, I think if you can come up with an algorithm using the built in 
functions over sequences like map, reduce, filter, etc. 
you should do so. 
Either way, it doesn't really matter which way you do it, just do it right and 
then refine as you go (and gain more experience). 
Just be aware that you have to explicitly loop-recur for tail recursive 
processes, recursive processes might blow up your call stack pretty quickly.
 
So that would cover 1)
For 2)
I can think of a straight forward tail-recursive process to do what you want:

 (defn drop-by [f coll]
(loop [coll coll]
   (let [x (first coll)
y (second coll)]
(if (and x y (= (f x) (f y)))
(recur (rest coll))
(rest coll)

Maybe someone on this list can think of an implementation in terms of sequence 
functions. 

Cheers
Andreas
P.s. The most powerful tool that comes with Clojure is this community. Use it!

On 03/04/2011, at 5:23 PM, Stefan Rohlfing wrote:

> @ Ken, Andreas
> 
> Thank you for your nice implementations!
> 
> As far as I can see, there are two main methods of comparing adjacent items 
> of a list:
> 
> 1) Take the first item of a coll. Compare the remaining items with an offset 
> of 1:
> (map f coll (rest coll))
> ;; apply some sort of filter
> 
> 2) Take the first and the second item of a coll. Test if both items exists 
> and then compare: 
> (let [x (first coll), y (second coll)]
>(and x y (= (f x) (f y 
> 
> The first method works for take-by, but not for drop-while (or so I think).
> 
> Using the second method take-by can be changed into drop-by by only changing 
> the last two lines:
> 
> (defn drop-by2 [f coll]
>   (lazy-seq
> (when-let [s (seq coll)]
>   (let [x (first s)
> y (second s)]
> (if (and x y (= (f x) (f y)))
>   (drop 2 s)
>   (drop 1 s))
> 
> 
> I am curious to know if one of these methods is the preferred way of doing a 
> comparison in Clojure (aka Python's one way of doing things). The sheer 
> number of possible solutions to the same problem sometimes overwhelms me a 
> bit, so that I'm looking for some orientation ;-) 
> 
> Best regards,
> 
> Stefan
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-03 Thread Andreas Kostler
I can't answer that Ken,
I guess I wasn't thinking of vec when I wrote it :)
On 03/04/2011, at 5:17 PM, Ken Wesson wrote:

> On Sun, Apr 3, 2011 at 1:04 AM, Andreas Kostler
>  wrote:
>>   (map (fn [x y] [x y]) coll (rest coll))
> 
> What's your reason for using (fn [x y] [x y]) here instead of just
> vector? Is it more efficient because it isn't variable-arity?
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.core/some expected behaviour

2011-04-02 Thread Andreas Kostler
Thanks Daniel,
I should have worked that out myself ;)
Andreas

On 03/04/2011, at 3:47 PM, Daniel Janus wrote:

> On 3 Kwi, 07:37, Andreas Kostler 
> wrote:
> 
>> Hi Daniel,
>> Thanks for your reply. I know how to get to :fred.
>> I'm just wondering why some wouldn't work on maps.
> 
> Well, `some' finds an element in a seq that satisfies the given
> predicate, and seq'ing a map will get you a sequence of key/value
> pairs. So, using a set as a predicate, you could test whether a given
> key/value pair exists in a map:
> 
>  (some #{[:barney "rubble"]} {:fred "flinstone" :barney "rubble"})
> 
> So it does work on maps, albeit not in the way you'd expect it to.
> 
> Daniel
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.core/some expected behaviour

2011-04-02 Thread Andreas Kostler
Hi Daniel,
Thanks for your reply. I know how to get to :fred.
I'm just wondering why some wouldn't work on maps.
Cheers
Andreas

On 03/04/2011, at 3:32 PM, Daniel Janus wrote:

> Hi Andreas,
> 
>> (some #{:fred} [:fred :barney])
>> => :fred
>> This expected.
>> Would one be write to expect
>> (some #{:fred} {:fred "flinstone" :barney "rubble"})
>> to return
>> => :fred
>> as well?
> 
> (some #{:fred} (keys {:fred "flinstone" :barney "rubble"}))
> 
> will get you what you need.
> 
> Best,
> Daniel
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


clojure.core/some expected behaviour

2011-04-02 Thread Andreas Kostler
Hi All,

(some #{:fred} [:fred :barney])
=> :fred
This expected.
Would one be write to expect
(some #{:fred} {:fred "flinstone" :barney "rubble"})
to return
=> :fred 
as well? This is not the case, it return nil
What's the (easy) explanation for this?
Cheers
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-02 Thread Andreas Kostler
Another way to skin the cat:

(defn take-by [f coll]
(cons (first coll)
  (for [[x y]
   (map (fn [x y] [x y]) coll (rest coll))
   :while (= (f x) (f y))] x)))

Cheers
Andreas


On 03/04/2011, at 2:21 PM, Ken Wesson wrote:

> On Sun, Apr 3, 2011 at 12:16 AM, Ken Wesson  wrote:
>> On Sat, Apr 2, 2011 at 11:38 PM, Stefan Rohlfing
>>  wrote:
>>> I am sure there is a standard functional way of comparing adjacent items in
>>> a coll and would be glad if someone could point me to it.
>> 
>> (defvar- sentinel (Object.))
>> 
>> (defn take-by [f coll]
>>  (let [fs (map f coll)
>>ps (map = fs (rest fs))
>>zs (map #(if %1 %2 sentinel) ps coll)]
>>(take-while (partial not= sentinel) zs))
>> 
>> user=> (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42])
>> (1 4 1 7 34 16)
> 
> Actually, this should include the 10 after the 16. It needs to be
> 
> (defn take-by [f coll]
>  (let [fs (map f coll)
>ps (map = fs (rest fs))
>zs (map #(if %1 %2 sentinel) ps (rest coll))]
>(cons (first coll) (take-while (partial not= sentinel) zs
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-02 Thread Andreas Kostler
Without bugs this time:
(defn take-by [f coll]
(lazy-seq
  (when-let [s (seq coll)]
(let [x (first s)
 y (second s)]
 (if (and x y (= (f x) (f y)))
 (cons x (take-by f (rest s)))
 (list x))

On 03/04/2011, at 2:21 PM, Ken Wesson wrote:

> On Sun, Apr 3, 2011 at 12:16 AM, Ken Wesson  wrote:
>> On Sat, Apr 2, 2011 at 11:38 PM, Stefan Rohlfing
>>  wrote:
>>> I am sure there is a standard functional way of comparing adjacent items in
>>> a coll and would be glad if someone could point me to it.
>> 
>> (defvar- sentinel (Object.))
>> 
>> (defn take-by [f coll]
>>  (let [fs (map f coll)
>>ps (map = fs (rest fs))
>>zs (map #(if %1 %2 sentinel) ps coll)]
>>(take-while (partial not= sentinel) zs))
>> 
>> user=> (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42])
>> (1 4 1 7 34 16)
> 
> Actually, this should include the 10 after the 16. It needs to be
> 
> (defn take-by [f coll]
>  (let [fs (map f coll)
>ps (map = fs (rest fs))
>zs (map #(if %1 %2 sentinel) ps (rest coll))]
>(cons (first coll) (take-while (partial not= sentinel) zs
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (take-by f coll), (drop-by f coll): Problem Comparing Adjacent Items Of A Collection

2011-04-02 Thread Andreas Kostler
Or more in line with the implementation of take-while:

(defn take-by [f coll]
(lazy-seq
  (when-let [s (seq coll)]
(let [x (first s)
 y (second s)]
 (if (= (f x) (f y))
(cons x (take-by f (rest s)))
(list x))

Kind Regards
Andreas

On 03/04/2011, at 2:16 PM, Ken Wesson wrote:

> On Sat, Apr 2, 2011 at 11:38 PM, Stefan Rohlfing
>  wrote:
>> I am sure there is a standard functional way of comparing adjacent items in
>> a coll and would be glad if someone could point me to it.
> 
> (defvar- sentinel (Object.))
> 
> (defn take-by [f coll]
>  (let [fs (map f coll)
>ps (map = fs (rest fs))
>zs (map #(if %1 %2 sentinel) ps coll)]
>(take-while (partial not= sentinel) zs))
> 
> user=> (take-by #(mod % 3) [1 4 1 7 34 16 10 2 99 103 42])
> (1 4 1 7 34 16)
> 
> I leave drop-by as an exercise for the reader, but the punch line here
> is (map foo s (rest s)). :)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Can I add the contents of seq to a collection without wrapping?

2011-03-28 Thread Andreas Kostler
Colin,
PersistenQueue doesn't have direct Reader support. However:

user> (def source-queue (ref clojure.lang.PersistentQueue/EMPTY))
#'user/source-queue

user> (for [x (load-sources 1 2 3)]
   x)
(1 2 3)

with
(defn load-sources [& sources]
(dosync 
 (alter source-queue into sources)))

Maybe I still don't get your problem but it seems to work for me :)
Andreas


On 29/03/2011, at 10:49 AM, colint wrote:

> orry perhaps I should have said my queue is a ref'ed PersistentQueue
> and so concat doesnt work as it works it returns a LazySeq.

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: (memoize) and recursive functions (Clojure 1.2)

2011-03-28 Thread Andreas Kostler
Hi Ben,
it seems like this has been broken in Clojure 1.2:
http://groups.google.com/group/clojure/browse_thread/thread/d7141efd4958a7e5/4d847865a9d5fb8b?lnk=gst&q=memoize+fib#4d847865a9d5fb8b

One solution is
(def f (memoize fn [n]...

will do what you want.
Cheers
Andreas

On 29/03/2011, at 10:47 AM, Benny Tsai wrote:

> (defn f [n]
>   (println "f called with" n)
>   (if (zero? n)
> 0
> (min (f (dec n))
>  (f (dec n)
> 
> (def f (memoize f))

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Can I add the contents of seq to a collection without wrapping?

2011-03-28 Thread Andreas Kostler
Hi Colin,
Can you be a bit more specific? The code you posted actually works without 
vec...

On 29/03/2011, at 6:52 AM, colint wrote:

> Hi, is there a function to add the contents of seq to a collection
> without using vec and into combo?
> 
> (defn load-sources [&sources]
>  (dosync
>(alter source-queue into (vec (sources)
> 
> cheers
> Colin
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: DDJ for Clojure/Lisp/FP

2011-03-21 Thread Andreas Kostler

> 1) A tour of the Java / JVM ecosystem for clojure programmers with little or 
> no Java background.  What are the libraries, frameworks, and tools every 
> clojure programmer should know about, even if he or she never writes a line 
> of java?  How do we use them from clojure?  Actually this might make for a 
> nice series or even a regular column.
I agree. I'm an old style C/C++ and recently Objective-C expert kinda 
developer. I've never written but the simplest JAVA program. It seems intimate 
JAVA knowledge
is essential to excel in Clojure.

> 2) Articles about how to arrange your development environment, tailored to 
> begininning, intermediate, and advanced programmers, and exploring a few 
> different styles of workflow.  For example, emacs/swank vs other IDE's, 
> leiningen vs other building techniques, git vs hg vs whatever, etc.  
> Obviously some of this is orthogonal to language choice, so a straight git vs 
> hg article probably doesn't make sense.
That would  be very helpful. It took me a while to get everything wired up and 
I can image many people are turned off by the effort it is to get something up 
and running.
> 
> 3) You mentioned code walkthroughs -- I'd love to see this for some key, 
> important, popular, clojure libraries or apps.  Not sure what to suggest, but 
>  reading good code is one of the best ways for me to learn a new language.
> 

> On Mon, Mar 21, 2011 at 12:17 AM, Gregg Williams  
> wrote:
> I'm writing again to report on the community's interest in my previous
> post. Two people expressed an interest in providing modest amounts of
> time to make a community-supported Clojure magazine (or magazine-like
> entity) happen; one of them has significant technical editing skills
> himself. So we've got the editorial requirements covered. The only
> question is, who's interested in contributing some content? Remember,
> I did say "community-supported."
> 
> One of these guys said it very well: "I'd find it very rewarding to
> get something up and running that serves as an accepted, community-
> reviewed publication platform." That would be a great thing for the
> Clojure community to have. Among other benefits, it would increase the
> overall skill of the community (leading to better software), and it
> would increase the stature of Clojure itself to the larger community
> of programmers.
> 
> "But why bother?" you may ask. "People already publish on their own
> blogs, and anyone can find them."
> 
> True enough--but most bloggers are jotting something down quickly
> before they get back to what they really want to do, which is coding.
> As a result, they assume that the reader will be like them: in
> programming expertise, in Clojure-specific knowledge (what, you don't
> know the ring-session-riak API by heart?), or both. This makes some
> readers frustrated, and frustrated readers find something easier to
> read.
> 
> On the other hand, articles that have been improved through the
> interventions of an editor (who accepts some articles but not others,
> asks the author for clarifications, rewrites existing text to increase
> clarity, adds missing info or tutorial information, etc.), are far
> more useful, and to more readers.
> 
> An editor will work with you to make your article easier to read and
> understand. An editor can help you 'open up' your article to maximize
> the chance that the reader, who is as intelligent as you but perhaps
> less well-informed about your subject material, will stick with your
> article to the end, learn from your greater expertise, and become a
> more skillful member of the Clojure community. In other words, an
> editor will help you improve your article and get more recognition for
> your skill and hard work."
> 
> 
> 
> # THE BOTTOM LINE #
> 
> I want to hear from you if you'd be interested in reading
> professionally-edited content about Clojure. This would be free to all
> and would be (unless somebody comes up with a better idea) published
> at the Getting Clojure website, http://www.GettingClojure.com. (As an
> example, you can read my article on Clojure proxies, at
> http://www.gettingclojure.com/articles:extending-java-classes-using-proxy.)
> 
> If you do write, please tell me what you'd find interesting enough to
> be worth *your* time. Here are some possibilities:
> 
> * articles, with working code
> * short, interesting tidbits, suitable for infograzing
> * interviews with Clojurians of note
> * opinion pieces
> * code walkthroughs
> * overviews of selected Clojure frameworks/libraries
> * NEW! and IMPROVED! versions of existing Clojure blog entries
> * tutorials (at different levels of expertise)
> * collections of Clojure programming tips and techniques
> * Clojure jokes
> * a live webcam feed of Rich Hickey's hammock
> 
> Better yet, suggest something that Seems Like a Good Idea to you.
> 
> This is electronic publishing--we have access to blogs, wikis, code
> repositories, cloud-based program execution ... ! With a 

Re: Not quite getting for (newb question)

2011-03-20 Thread Andreas Kostler
No worries, always a pleasure :)
On 21/03/2011, at 12:43 PM, Brett Morgan wrote:

> Ahh, got it. Thank you Andreas.
> 
> On Sun, Mar 20, 2011 at 6:55 PM, Andreas Kostler 
>  wrote:
> Hi Brett,
> A :while clause continues the evaluation ONLY while it's expression is true
> 
> (for [x (range 10) y (range 10) :while (< x y)] [x y]) will terminate as soon 
> as (< x y) is false. Since (< 0 0) is the first expr to evaluate, evaluation 
> stops right there. 
> 
> What you want is
> (for [x (range 10) y (range 10) :when (< x y)] [x y])
> 
> Cheers
> Andreas
> 
> what you want is for ... :when
> On 21/03/2011, at 11:43 AM, Brett Morgan wrote:
> 
>> Hey all,
>> 
>> I'm not understanding why the following examples don't line up. In my mind 
>> they should be identical. What am i not getting?
>> 
>> (user=> (filter (fn [[x y]] (< x y)) (for [x (range 10) y (range 10)] [x y]))
>> ([0 1] [0 2] [0 3] [0 4] [0 5] [0 6] [0 7] [0 8] [0 9] [1 2] [1 3] [1 4] [1 
>> 5] [1 6] [1 7] [1 8] [1 9] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9] [3 4] 
>> [3 5] [3 6] [3 7] [3 8] [3 9] [4 5] [4 6] [4 7] [4 8] [4 9] [5 6] [5 7] [5 
>> 8] [5 9] [6 7] [6 8] [6 9] [7 8] [7 9] [8 9])
>> user=> (for [x (range 10) y (range 10) :while (< x y)] [x y])
>> ()
>> 
>> user=> (filter (fn [[x y]] (> x y)) (for [x (range 10) y (range 10)] [x y]))
>> ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] [5 0] [5 1] [5 
>> 2] [5 3] [5 4] [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [7 0] [7 1] [7 2] [7 3] 
>> [7 4] [7 5] [7 6] [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [9 0] [9 
>> 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8])
>> user=> (for [x (range 10) y (range 10) :while (> x y)] [x y])
>> ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] [5 0] [5 1] [5 
>> 2] [5 3] [5 4] [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [7 0] [7 1] [7 2] [7 3] 
>> [7 4] [7 5] [7 6] [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [9 0] [9 
>> 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8])
>> user=> 
>> 
>> -- 
>> 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 are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
> 
> --
> "Test-driven Dentistry (TDD!) - Not everything should be test driven"
> - Michael Fogus
> -- 
> **
> Andreas Koestler, Software Engineer
> Leica Geosystems Pty Ltd
> 270 Gladstone Road, Dutton Park QLD 4102
> Main: +61 7 3891 9772 Direct: +61 7 3117 8808
> Fax: +61 7 3891 9336
> Email: andreas.koest...@leica-geosystems.com
> 
> www.leica-geosystems.com*
> 
> when it has to be right, Leica Geosystems
> 
> Please  consider the environment before printing this email.
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Not quite getting for (newb question)

2011-03-20 Thread Andreas Kostler
Hi Brett,
A :while clause continues the evaluation ONLY while it's expression is true

(for [x (range 10) y (range 10) :while (< x y)] [x y]) will terminate as soon 
as (< x y) is false. Since (< 0 0) is the first expr to evaluate, evaluation 
stops right there. 

What you want is
(for [x (range 10) y (range 10) :when (< x y)] [x y])

Cheers
Andreas

what you want is for ... :when
On 21/03/2011, at 11:43 AM, Brett Morgan wrote:

> Hey all,
> 
> I'm not understanding why the following examples don't line up. In my mind 
> they should be identical. What am i not getting?
> 
> (user=> (filter (fn [[x y]] (< x y)) (for [x (range 10) y (range 10)] [x y]))
> ([0 1] [0 2] [0 3] [0 4] [0 5] [0 6] [0 7] [0 8] [0 9] [1 2] [1 3] [1 4] [1 
> 5] [1 6] [1 7] [1 8] [1 9] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9] [3 4] [3 
> 5] [3 6] [3 7] [3 8] [3 9] [4 5] [4 6] [4 7] [4 8] [4 9] [5 6] [5 7] [5 8] [5 
> 9] [6 7] [6 8] [6 9] [7 8] [7 9] [8 9])
> user=> (for [x (range 10) y (range 10) :while (< x y)] [x y])
> ()
> 
> user=> (filter (fn [[x y]] (> x y)) (for [x (range 10) y (range 10)] [x y]))
> ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] [5 0] [5 1] [5 
> 2] [5 3] [5 4] [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [7 0] [7 1] [7 2] [7 3] [7 
> 4] [7 5] [7 6] [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [9 0] [9 1] [9 
> 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8])
> user=> (for [x (range 10) y (range 10) :while (> x y)] [x y])
> ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] [5 0] [5 1] [5 
> 2] [5 3] [5 4] [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [7 0] [7 1] [7 2] [7 3] [7 
> 4] [7 5] [7 6] [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [9 0] [9 1] [9 
> 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8])
> user=> 
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Beginning Clojure

2011-03-20 Thread Andreas Kostler
Hi,
Depending on your level of Lisp expertise, I'd suggest digging into Clojure 
frameworks like Ring or Compojure.
You might find the books on Clojure interesting ("Practical Clojure", 
"Programming Clojure", "The Joy of Clojure", "Clojure in Action").
The latter two are work in progress (however, "The Joy of Clojure" is complete 
and will be shipped end of March). 
The classic Lisp texts (I love "Practical Common Lisp") are pretty good value. 
There's blogs as well with tutorial material: 
(http://www.bestinclass.dk/index.clj/2011/01/building-a-social-media-site.html) 

Hope that helps :)
Andreas

On 21/03/2011, at 9:08 AM, Ent SaaS wrote:

> 
> Hi, 
> 
> I would like to learn Clojure from a practical project approach.  Where can I 
> find resources? 
> 
> 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 posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
,

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Throwing an Exception with get

2011-03-20 Thread Andreas Kostler
Well, get-with-exception attempts to model a restriction on a relation (e.g. 
select in sql) so I believe a missing key indeed indicates an error.

On 21/03/2011, at 9:25 AM, Daniel Werner wrote:

> On 20 March 2011 22:02, Andreas Kostler
>  wrote:
>> Would that be flow control though? I see this exception as a rather 
>> exceptional circumstance for this application...
> 
> If a missing key signifies an error, then yes, it should probably
> throw an exception. It seems reading your code wrongly reminded me of
> how in Python, it is idiomatic to catch KeyError if a key isn't
> present, which can lead to unneccessarily nested and hard-to-read
> logic. (Of course, there's also .get() in Python, with an identical
> signature to Clojure's get)
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to Sum a Sequence?

2011-03-20 Thread Andreas Kostler

>> Do you have any resources or books that help with such things? (Taking
>> a problem and solving it the way you did)
> 
> I think, my suggestions are not specific to clojure, but they apply to
> any functional language.  All of them have functions for filtering
> sequences, applying a function to each item, reducing, and so on.  Once
> you know these basic functions, most computation can be expressed by
> composing these in some way.
I can only speak for me personally, but I found it useful going through the 
excellent books
the CLisp and Scheme community provide. Peter Seibels Practical Common Lisp and
The Little Schemer, The Seasoned Schemer, and of course SICP not only teach you
how to use a Lisp which is 'simpler' than Clojure (not in terms of syntax) - 
this is especially
true for Scheme (not so much CLisp) but they also teach you how to recognise 
certain patterns that occur in 
functional programs. 
Once you know how those patterns match to the sequence functions you can start 
replacing them and
writing more concise code. That was my path anyway and I'm still learning :)
It's fun though, don't get frustrated :) This community is very helpful so 
don't hesitate and ask. There's no dumb
questions, you know the saying. 
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Throwing an Exception with get

2011-03-20 Thread Andreas Kostler
Would that be flow control though? I see this exception as a rather exceptional 
circumstance for this application...
On 20/03/2011, at 10:53 PM, Daniel Werner wrote:

> On Mar 20, 10:50 am, Andreas Kostler
>  wrote:
>> I would like to throw an exception when I'm trying to retrieve a value in a 
>> map for a key that doesn't exist.
> 
> Another concise solution (thanks, Conj Labs):
> 
> (defn get-o r-exc [map key]
>  (if-l et [[_ v] (find  map key)]
>v
>(thro w (Exce ption. "miss ing"
> 
> I'm not too fond of using exceptions for flow control, though.
> 
> Daniel
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Throwing an Exception with get

2011-03-20 Thread Andreas Kostler
Hi Ambrose,
No java interop. I do a selection based on map keys. Suppose I have a set of 
maps:
(def rel #{{:a "a" :b "b"}{:a "c" :b "d"}{:a "e" :b "f"}})
And I do a select-like query
(select rel [[:a :eq "a"]])
=> #{{:a "a" :b "b"}}

Now, I want to distinguish between a value that doesn't match and a 
non-existing key.
Hence,
(select rel [[:bogus "b"]]) should not return an empty set but somehow signal 
that the key does not exist.
In relational terms, the key is not an attribute of the relation. 
Does that make sense?
Andreas
 
On 20/03/2011, at 9:10 PM, Ambrose Bonnaire-Sergeant wrote:

> curious, why do you want to do this? Are you working with Java interop


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to Sum a Sequence?

2011-03-20 Thread Andreas Kostler

On 20/03/2011, at 8:25 PM, Christian wrote:

> Hello Andreas!
> 
> Thanks for your swift reply. I'll try to explain the reasoning behind
> my code.
> 
> In the Clojure Reference I found the function into, which is described
> like so:
> 
> Usage: (into to from)
> "Returns a new coll consisting of to-coll with all of the items of
> from-coll conjoined."
This is exactly what's happening:
(def v [1 2 3])
(into v (pop v))
=> [1 2 3 1 2]

However, 
v
=> [1 2 3]

It does not mutate the original vector. The same applies for conj.


> I'm currently reading the book "Programming Clojure". In it, the
> author has a chapter on binding which states that vectors are indeed
> immutable. I'm not sure if this is a problem of scope, but I thought
> that I could coerce fib-vec into receiving a new vec and throwing the
> old one away (making the old one available for deletion from the GC).
> That is why I used 'into fib-vec'. I thought it would re-bind fib-vec
> to itself, but with one element less. I used the same idea with
> ansVec.
See above. into doesn't rebind it's arguments. Rather it returns a sequence 
which contain the second argument added to the elements of the  first.
It doesn't physically alter the first argument.
> 
> Could you perhaps tell me why it cannot do that? Rather, is this
> behavior possible in Clojure?
> 
> PS:  Thanks for the book-tipp! I'll be sure to check it out.
> 
All this is intrinsic Clojure behaviour. Clojure is unique in this way. You 
will find that other flavours of Lisp allow mutable data (e.g. setf in common 
lisp).

Thassilo provided a more idiomatic solution to your problem.

Andreas

> On Mar 20, 10:48 am, Andreas Kostler
>  wrote:
>> Hi Christian,
>> What you're trying to do is to build up a vector with the last element of 
>> the vector being the answer to your problem:
>> (last answer)
>> => 4613732
>> You're trying to use cons (conj) to build up that list.
>> 
>> Now, your function below never terminates because you're:
>> a) Not actually building up the ans-vec
>> b) Not actually changing fib-vec to be closer to termination
>> 
>> Clojure datastructures are immutable. conj returns a new seq with the second 
>> argument conj(s)ed onto the old sequence without changing the old seq e.g.:
>> 
>> (def v [1 2 3])
>> (conj v 4)
>> => [1 2 3 4]
>> 
>> but:
>> v
>> => [1 2 3]
>> 
>> The same applies to into.
>> The closest I can think of you're trying to achieve is:
>> 
>> (defn answer []
>> (loop [ans-vec [0] fib-v fib-vec]
>>(if (empty? fib-v)
>>ans-vec
>>(recur (conj ans-vec (+ (last ans-vec) (last fib-v))) (pop 
>> fib-v)
>> 
>> Now you're actually building up ans-vec in a tail-recursive fashion while 
>> changing fib-v to be closer to termination.
>> 
>> Having said that, what you really want is (reduce + fib-vec) ;)
>> 
>> Andreas
>> P.S. To get your head around basic recursion dig into "The little Schemer" 
>> by Friedman and Felleisen
>> 
>>  On 20/03/2011, at 7:22 PM, Christian wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> I've tried Project Euler 2 now.
>> 
>>> For those unfamiliar, Project Euler Problem 2 states:  find the sum of
>>> all even-valued fibonacci terms that are less than four million.
>> 
>>> Let's assume that I have the code to fill the vector:
>> 
>>> (def fib-seq
>>>  ((fn rfib [a b]
>>> (lazy-seq (cons a (rfib b (+ a b)
>>>   0 1))
>> 
>>> (def fib-vec
>>>  (into [] (filter even? (take 35 fib-seq
>> 
>>> Many people reading the Clojure Samples will be familiar with the
>>> first sample. My own implementation did not want the 'take' function
>>> to work. However, that is a question for another day. Assume that the
>>> magic number 35 in the second function does indeed give me all even-
>>> valued fibonacci terms under four million. (I did not know how to
>>> specify a predicate depending on the value of (fib-seq) to check if
>>> the value is under 4 million.)
>> 
>>> With the function '(reduce + (fib-vec))' I effortlessly summed up all
>>> values in the vector. This is peculiar, because I first wanted to
>>> write a function that does this for me, but to no avail.
>> 
>>> (defn answer []
>>>  (let [ansVec [0]]
>>> 

Throwing an Exception with get

2011-03-20 Thread Andreas Kostler
Hi all,
I would like to throw an exception when I'm trying to retrieve a value in a map 
for a key that doesn't exist.
The obvious first shot was:
(get {:foo "bar"} :foo (throw (new Exception "Oh no!"))) 
However, this doesn't work because the exception always throws since get 
apparently eagerly evaluates it's arguments.
One way to work around this could be:

(defn get-with-exception [map key]
(let [res (get map key (new Exception "my-exception"))]
 (if (= (class res) java.lang.Exception)
 (throw res)
 res)))

I was wondering, is there another more concise/idiomatic way?

Cheers
Andreas

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to Sum a Sequence?

2011-03-20 Thread Andreas Kostler
Hi Christian,
What you're trying to do is to build up a vector with the last element of the 
vector being the answer to your problem:
(last answer) 
=> 4613732
You're trying to use cons (conj) to build up that list. 

Now, your function below never terminates because you're:
a) Not actually building up the ans-vec
b) Not actually changing fib-vec to be closer to termination

Clojure datastructures are immutable. conj returns a new seq with the second 
argument conj(s)ed onto the old sequence without changing the old seq e.g.:

(def v [1 2 3])
(conj v 4)
=> [1 2 3 4]

but:
v
=> [1 2 3]

The same applies to into. 
The closest I can think of you're trying to achieve is:

(defn answer []
(loop [ans-vec [0] fib-v fib-vec]
   (if (empty? fib-v)
   ans-vec
   (recur (conj ans-vec (+ (last ans-vec) (last fib-v))) (pop 
fib-v)

Now you're actually building up ans-vec in a tail-recursive fashion while 
changing fib-v to be closer to termination.

Having said that, what you really want is (reduce + fib-vec) ;)

Andreas
P.S. To get your head around basic recursion dig into "The little Schemer" by 
Friedman and Felleisen

 On 20/03/2011, at 7:22 PM, Christian wrote:

> I've tried Project Euler 2 now.
> 
> For those unfamiliar, Project Euler Problem 2 states:  find the sum of
> all even-valued fibonacci terms that are less than four million.
> 
> Let's assume that I have the code to fill the vector:
> 
> (def fib-seq
>  ((fn rfib [a b]
> (lazy-seq (cons a (rfib b (+ a b)
>   0 1))
> 
> (def fib-vec
>  (into [] (filter even? (take 35 fib-seq
> 
> Many people reading the Clojure Samples will be familiar with the
> first sample. My own implementation did not want the 'take' function
> to work. However, that is a question for another day. Assume that the
> magic number 35 in the second function does indeed give me all even-
> valued fibonacci terms under four million. (I did not know how to
> specify a predicate depending on the value of (fib-seq) to check if
> the value is under 4 million.)
> 
> With the function '(reduce + (fib-vec))' I effortlessly summed up all
> values in the vector. This is peculiar, because I first wanted to
> write a function that does this for me, but to no avail.
> 
> (defn answer []
>  (let [ansVec [0]]
>  (while (not-empty fib-vec)
>(conj ansVec (+ (last ansVec) (last fib-vec)))
>(into fib-vec (pop fib-vec)
> 
> This function never terminates. Why not? Where am I thinking wrong?
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: DDJ for Clojure/Lisp/FP

2011-03-14 Thread Andreas Kostler
I am :) That's why I started this discussion.

On 15/03/2011, at 2:30 PM, Gregg Williams wrote:

> Let me introduce myself. I was senior editor at BYTE magazine from
> 1979 to 1988, where I wrote many cover-story articles, developed/
> edited innumerable articles, and was responsible for a number of issue
> themes (including the IBM PC, FORTH, and Lisp (Feb. 1988)). From
> there, I went to Apple (1988-1998), where I did a similar job for
> Apple publications to its third-party developer base (in a magazine
> named _Apple Direct_, which was later renamed _Apple Directions_).
> 
> I recently got a Clojure article published in the November 2010 issue
> of _PragPub_ magazine (see http://pragprog.com/magazines/2010-11/content).
> 
> I also started the website http://www.GettingClojure.com, which I
> meant to be a congregating place for Clojure beginners like myself.
> Apart from significant contributions to a Clojure Cookbook by David
> Sletten (see http://www.gettingclojure.com/cookbook:clojure-cookbook)
> and a reprint of my _PragPub_ article, the site hasn't been used.
> 
> But that can change.
> 
> I'd love to edit *or* help edit a magazine again. I'm tan, fit, and
> rested, and I've got the chops to do the job. We could re-brand
> GettingClojure.com to be for the entire Clojure community.
> 
> I'd be glad to share the decisionmaking with anybody willing to do the
> work. Once something is up and running, I'd be glad to turn the
> website or the domain over to anyone or any group who has already been
> making the site happen.
> 
> You can reach me through this group, either publicly or via "Reply to
> author".
> 
> To start, I'd need authors, reviewers, people with ideas for content--
> and maybe an administrator/logistics person. Who's interested?
> 
> 
> Best wishes,
> 
> Gregg Williams
> 
> 
> On Mar 13, 5:30 pm, Andreas Kostler 
> wrote:
>> Hi there,
>> Is there something like Doctor Dobbs Journal for Clojure/Lisp or even 
>> functional programming related topics? - A (peer reviewed) place
>> collecting contributions from developers all over the world working in 
>> Clojure/Lisp environments sharing their insights and solutions
>> to problems developers encounter daily.
>> 
>> If there isn't, is it worthwhile starting an effort into this direction?
>> 
>> Kind Regards
>> Andreas
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: DDJ for Clojure/Lisp/FP

2011-03-14 Thread Andreas Kostler
Something along those lines. The key would be to have low publication latency 
e.g. articles undergo a initial review in a matter of hours so it
still has the blog vibe to it but undergo stricter quality control.

On 14/03/2011, at 8:57 PM, Nick Zbinden wrote:

> This sounds very good. It would have to be start up with one topic
> (lisp or FP) and if the system worked you could add more topics.
> 
> The length could be like steve yeggy blogposts or like the ibm ähh
> articals (http://www.ibm.com/developerworks/java/library/j-clojure-
> protocols/).
> 
> On Mar 14, 11:12 am, Andreas Kostler
>  wrote:
>> On 14/03/2011, at 8:00 PM, Saul Hazledine wrote:
>> 
>> 
>> 
>>> On Mar 14, 3:41 am, Andreas Kostler 
>>> wrote:
>> 
>>>> Maybe this group could finally get the ball rolling...Surely a collection 
>>>> of highly talented individuals could initiate a forum for
>>>> technical exchange at the level Peter suggests (somewhere between a blog 
>>>> and a book) - basically the level DDJ is operating
>>>> at these days.
>> 
>>> The level you mention suggests some sort of review (possibly
>>> anonymous?).
>> 
>>> One possibility is to base it around a web application to make things
>>> relatively low maintenance. Just an idea for discussion - somebody
>>> could submit a text in the style of a blog post which is then passed
>>> to relevant reviewers who come back with comments. If the post isn't
>>> accepted the author doesn't loose much as they can then post it as a
>>> normal blog.
>> 
>> That's exactly what I mean. I was thinking of some sort of exponential
>> review process...at first it gets submitted to 4 people, if 3 give their 
>> thumbs
>> up it gets published and submitted to 16 people and so on. The more people
>> give their thumbs up, the higher it will appear on the main page. Something 
>> along those lines.
>> One could also introduce elements like stackoverflow does (medals etc) to 
>> encourage
>> people a) to publish and b) to review.
>> Ranking the post in terms of positive reviews boosts 'good' posts :)
>> This is just a first thought and certainly could use some refinement.
>> 
>> Having said that, I'd like to see the quality and extent of the posts to be
>> somewhere between research papers and blogposts.
>> 
>> 
>> 
>>> The reviewing is work but if its kept in the style of a blog post
>>> rather than an academic paper the overhead shouldn't be too high. The
>>> use of an application would reduce the need for an editor.
>> 
>>> Saul
>> 
>>> --
>>> 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 are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: DDJ for Clojure/Lisp/FP

2011-03-14 Thread Andreas Kostler

On 14/03/2011, at 8:00 PM, Saul Hazledine wrote:

> On Mar 14, 3:41 am, Andreas Kostler 
> wrote:
>> 
>> Maybe this group could finally get the ball rolling...Surely a collection of 
>> highly talented individuals could initiate a forum for
>> technical exchange at the level Peter suggests (somewhere between a blog and 
>> a book) - basically the level DDJ is operating
>> at these days.
>> 
> 
> The level you mention suggests some sort of review (possibly
> anonymous?).
> 
> One possibility is to base it around a web application to make things
> relatively low maintenance. Just an idea for discussion - somebody
> could submit a text in the style of a blog post which is then passed
> to relevant reviewers who come back with comments. If the post isn't
> accepted the author doesn't loose much as they can then post it as a
> normal blog.
That's exactly what I mean. I was thinking of some sort of exponential 
review process...at first it gets submitted to 4 people, if 3 give their thumbs
up it gets published and submitted to 16 people and so on. The more people
give their thumbs up, the higher it will appear on the main page. Something 
along those lines.
One could also introduce elements like stackoverflow does (medals etc) to 
encourage
people a) to publish and b) to review. 
Ranking the post in terms of positive reviews boosts 'good' posts :)
This is just a first thought and certainly could use some refinement.

Having said that, I'd like to see the quality and extent of the posts to be 
somewhere between research papers and blogposts.

> 
> The reviewing is work but if its kept in the style of a blog post
> rather than an academic paper the overhead shouldn't be too high. The
> use of an application would reduce the need for an editor.
> 
> Saul
> 
> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: DDJ for Clojure/Lisp/FP

2011-03-13 Thread Andreas Kostler
> Well, it was announced two or three years ago, but has never actually been 
> produced, so I wouldn't get your hopes up :) 
> 
Maybe this group could finally get the ball rolling...Surely a collection of 
highly talented individuals could initiate a forum for
technical exchange at the level Peter suggests (somewhere between a blog and a 
book) - basically the level DDJ is operating
at these days.

> -- 
> 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 are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: DDJ for Clojure/Lisp/FP

2011-03-13 Thread Andreas Kostler

On 14/03/2011, at 12:05 PM, Alan Dipert wrote:

> Hi Andreas,
> 
>> Is there something like Doctor Dobbs Journal for Clojure/Lisp or even
>> functional programming related topics?
> 
> To my knowledge, not yet.  Peter Seibel's yet-to-be-published "Code
> Quarterly" sounds similar to what you're looking for:
> http://www.codequarterly.com/
This certainly sounds/reads interesting. It is to be seen how much Clojure/Lisp 
content there will be
and how many every-day problems it will address. How long hast this been around?
> 
>> If there isn't, is it worthwhile starting an effort into this direction?
> 
> I don't see why not!
> 
> Alan
> clojure.com

--
"Test-driven Dentistry (TDD!) - Not everything should be test driven"
- Michael Fogus
-- 
**
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772 Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

www.leica-geosystems.com*

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


DDJ for Clojure/Lisp/FP

2011-03-13 Thread Andreas Kostler
Hi there,
Is there something like Doctor Dobbs Journal for Clojure/Lisp or even 
functional programming related topics? - A (peer reviewed) place
collecting contributions from developers all over the world working in 
Clojure/Lisp environments sharing their insights and solutions
to problems developers encounter daily.

If there isn't, is it worthwhile starting an effort into this direction?

Kind Regards
Andreas

-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Macros, macros, macros

2011-03-08 Thread Andreas Kostler

On 09/03/2011, at 4:24 PM, Alan wrote:

> On Mar 8, 9:14 pm, Andreas Kostler 
> wrote:
>> Hi Daniel,
>> Thanks for your reply.
>> On 09/03/2011, at 11:57 AM, Daniel Solano Gomez wrote:
>>> On Wed Mar  9 11:16 2011, Andreas Kostler wrote:
>>>> Hi all,
>> 
>>>> I need a macro to basically outputs this:
>> 
>>>> (macroexpand '(chain-field-queries record "location" "name" "country"))
>>>> (. (. (. record (field "location")) (field "name")) (field "country"))
>> 
>>>> Which chains method calls on a java object. e.g. 
>>>> record.field("location").field("name").field("country"). etc...
>>>> so far so good. I though I could modify the .. macro for this:
>> 
>>>> (defmacro chain-field-queries
>>>>  ([x form]  `(. ~x (field ~form)))
>>>>([x form & more] `(chain (. ~x (field ~form)) ~@more)))
>> 
>>>> However, this results in
>>>> (macroexpand '(chain-field-queries record "location" "name" "country"))
>>>> (. (. (. record (user/field "location")) (user/field "name")) (user/field 
>>>> "country"))
>> 
>>> You could quote the field as a symbol:
>> 
>>> (defmacro chain-field-queries
>>>  ([x form] `(. ~x (~'field ~form)))
>>>  ([x form & more] `(chain-field-queries (. ~x (~'field ~form)) ~@more)))
>> 
>> Yes, I don't know why I wasn't thinking of doing that...
>> 
>>> Is a macro really required?  You can do this as a function:
>> 
>> I think it is required. I'm trying to compose a query of the form
>> 
>> (defn make-native-query [db str foo]
>> (. (proxy [ONativeSynchQuery]
>>[db str foo]
>>(filter [rec]
>> (.. rec (field "location") (eq "Madrid") go))) run 
>> objs))
>> 
>> Unfortunately, I'm bound to this style of query composition by the java api 
>> I'm working with. So ideally, I'd like to be able to do something like
>> 
>> (select (where [[location eq "Madrid"]
>> and [name eq "Dhali"]])
>> 
>> And this would expand to
>> 
>> (defn make-native-query [db str foo]
>> (. (proxy [ONativeSynchQuery]
>>[db str foo]
>>(filter [rec]
>> (.. rec (field "location") (eq "Madrid") and (field 
>> "name") (eq "Dhali") go))) run objs))
>> 
>> So, technically, I want something along the lines
>> 
>> (defn make-native-query [db str foo]
>> (. (proxy [ONativeSynchQuery]
>>[db str foo]
>>(filter [rec]
>> (.. rec (create-query [[location eq "Madrid"]
>> and
>> [name eq 
>> "Dhali"]]) go))) run objs))
>> 
>> However, this doesn't seem to be possible. dot-dot doesn't evaluate the 
>> create-query macro.
>> I must be missing something. If anyone could point me in the right direction 
>> :)
>> 
>> Andreas
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> (defn chain-field-queries
>>>  [record & fields]
>>>  (let [query (fn [r f] (. r (field f)))]
>>>(reduce query record fields)))
>> 
>>> Sincerely,
>> 
>>> Daniel Solano Gómez
> 
> You seem to be missing Daniel's point. There's no reason you need to
> expand into exactly (.. foo (field "test") (field "more")); you could
> just as well expand into (let [data1 foo, data2 (.field data1 "test"),
> data3 (.field data2 "more")] data3), which is basically what the ..
> shorthand expands to eventually.
> 
> And because the latter result is exactly the sort of thing reduce is
> good at, you don't need a macro at all.

Well, I don't want the symbols location, name, etc to be evaluated...e.g. I 
couldn't use location if not in a macro, right?
Secondly, the structure isn't quite as uniform. Like in the example above 
(.. rec (create-query [[location eq "Madrid"] and [name eq "Dhali"]])) should 
expand to something like

(.. rec (f

Re: Macros, macros, macros

2011-03-08 Thread Andreas Kostler
Hi Daniel,
Thanks for your reply.
On 09/03/2011, at 11:57 AM, Daniel Solano Gomez wrote:

> On Wed Mar  9 11:16 2011, Andreas Kostler wrote:
>> Hi all,
>> 
>> I need a macro to basically outputs this:
>> 
>> (macroexpand '(chain-field-queries record "location" "name" "country"))
>> (. (. (. record (field "location")) (field "name")) (field "country"))
>> 
>> Which chains method calls on a java object. e.g. 
>> record.field("location").field("name").field("country"). etc...
>> so far so good. I though I could modify the .. macro for this:
>> 
>> (defmacro chain-field-queries
>>  ([x form]  `(. ~x (field ~form)))
>>([x form & more] `(chain (. ~x (field ~form)) ~@more)))
>> 
>> However, this results in 
>> (macroexpand '(chain-field-queries record "location" "name" "country"))
>> (. (. (. record (user/field "location")) (user/field "name")) (user/field 
>> "country"))
> 
> You could quote the field as a symbol:
> 
> (defmacro chain-field-queries
>  ([x form] `(. ~x (~'field ~form)))
>  ([x form & more] `(chain-field-queries (. ~x (~'field ~form)) ~@more)))
Yes, I don't know why I wasn't thinking of doing that...
> Is a macro really required?  You can do this as a function:

I think it is required. I'm trying to compose a query of the form

(defn make-native-query [db str foo]
(. (proxy [ONativeSynchQuery]
   [db str foo]
   (filter [rec] 
(.. rec (field "location") (eq "Madrid") go))) run 
objs))

Unfortunately, I'm bound to this style of query composition by the java api I'm 
working with. So ideally, I'd like to be able to do something like

(select (where [[location eq "Madrid"]
and [name eq "Dhali"]])

And this would expand to

(defn make-native-query [db str foo]
(. (proxy [ONativeSynchQuery]
   [db str foo]
   (filter [rec] 
(.. rec (field "location") (eq "Madrid") and (field 
"name") (eq "Dhali") go))) run objs))

So, technically, I want something along the lines

(defn make-native-query [db str foo]
(. (proxy [ONativeSynchQuery]
   [db str foo]
   (filter [rec] 
(.. rec (create-query [[location eq "Madrid"] 
and
[name eq 
"Dhali"]]) go))) run objs))


However, this doesn't seem to be possible. dot-dot doesn't evaluate the 
create-query macro. 
I must be missing something. If anyone could point me in the right direction :)

Andreas



> (defn chain-field-queries
>  [record & fields]
>  (let [query (fn [r f] (. r (field f)))]
>(reduce query record fields)))
> 
> Sincerely,
> 
> Daniel Solano Gómez


-- 
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 are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


  1   2   >