Re: About a networked REPL...

2011-03-20 Thread Gary Schiltz
On Mar 19, 7:30 pm, Martin Blais bl...@furius.ca wrote: (*) Please note: I am aware that only Emacs supports the     Swank protocol right now but I don't see why other IDEs     couldn't support it too--it's just made up of LISP forms     after all; in other words, if someone wants to

Re: About a networked REPL...

2011-03-20 Thread Kevin Downey
nrepl's protocol is also very line reader centric, which is a drag, and the integer that prefixes messages is really just a variable length string and is not useful for allocating buffers to receive data in a client because it is a lines / 2 instead of a byte count. this makes writing a client

How to Sum a Sequence?

2011-03-20 Thread Christian
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)

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

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

Re: How to Sum a Sequence?

2011-03-20 Thread Tassilo Horn
Christian soulbea...@gmail.com writes: Hi Christian, For those unfamiliar, Project Euler Problem 2 states: find the sum of all Sounds like (reduce + ...). even-valued fibonacci terms Sounds like (filter even? ...) that are less than four million. Hm, that's a bit more challenging. I

Re: clj-ldap - Clojure LDAP client

2011-03-20 Thread Saul Hazledine
On Mar 16, 9:30 am, Ray Miller r...@1729.org.uk wrote: On 15 March 2011 08:46, Saul Hazledine shaz...@gmail.com wrote: On Mar 15, 1:30 am, Paul Dorman paul.dor...@gmail.com wrote: One thought though is that it may be quicker simply do a lookup on the directory server, obtain the password

Re: Throwing an Exception with get

2011-03-20 Thread Ambrose Bonnaire-Sergeant
This is slower but is a bit clearer. (defn get-with-exception [map key] (if (contains? map key) (get map key) (throw (Exception. oops Curious, why do you want to do this? Are you working with Java interop? Ambrose On Sun, Mar 20, 2011 at 5:50 PM, Andreas Kostler

Re: Throwing an Exception with get

2011-03-20 Thread Ambrose Bonnaire-Sergeant
Maybe something along these lines: (def ^{:private true} EMPTY (reify)) (defn get-with-empty-check [map key] (get map key EMPTY)) (defn key-exists? [value] (not= EMPTY value)) = (def res (get-with-empty-check {:asdf 1} :ss)) EMPTY = (key-exists? res) false The basic idea being that it's

Re: Throwing an Exception with get

2011-03-20 Thread Daniel Werner
On Mar 20, 10:50 am, Andreas Kostler andreas.koestler.le...@gmail.com 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

Re: clj-ldap - Clojure LDAP client

2011-03-20 Thread Paul Dorman
Thanks for the latest changes, Saul. Your implementation is a little different from mine: (defn bind-connection Change the identity of an existing connection. [connection bind-dn password] (let [bind-result (.bind connection (bind-request {:bind-dn bind- dn :password password}))] (if (=

Re: How to Sum a Sequence?

2011-03-20 Thread Christian
Hello Tassilo! I've tested your code and looked at the Clojure Documentation for 'for'. Given that, I have written (reduce +(filter even? (for [fib (fib-seq) :while ( fib 400)] fib))) This gives me the error 'clojure.lang.LazySeq cannot be cast to clojure.lang.IFn'. I think this is because

Re: About a networked REPL...

2011-03-20 Thread Chas Emerick
Martin, Thank you for the pushback. :-) On Mar 19, 2011, at 8:30 PM, Martin Blais wrote: Hi, After Rich's suggestion at the recent NYC meetup, I had a detailed look at inferior-lisp vs. Slime, and nREPL, read Chas' document, wrote a bit of code, tried to figure out the issues for

Re: About a networked REPL...

2011-03-20 Thread Chas Emerick
On Mar 20, 2011, at 3:13 AM, Kevin Downey wrote: nrepl's protocol is also very line reader centric, which is a drag, and the integer that prefixes messages is really just a variable length string and is not useful for allocating buffers to receive data in a client because it is a lines / 2

Re: How to Sum a Sequence?

2011-03-20 Thread Michael Wood
Hi On 20 March 2011 17:47, Christian soulbea...@gmail.com wrote: Hello Tassilo! I've tested your code and looked at the Clojure Documentation for 'for'. Given that, I have written (reduce +(filter even? (for [fib (fib-seq) :while ( fib 400)] fib))) Or using Daniel's suggestion:

Re: How to Sum a Sequence?

2011-03-20 Thread Tassilo Horn
Christian soulbea...@gmail.com writes: Hi Christian, I would like to thank you for this suggestion and the way you translated the problem statement into code! Thanks for the compliment. :-) Do you have any resources or books that help with such things? (Taking a problem and solving it the

Re: Dynamic scoping issue

2011-03-20 Thread Ken Wesson
On Sun, Mar 20, 2011 at 4:16 PM, Tassilo Horn tass...@member.fsf.org wrote: the println prints {Locality localities.Locality}, which is correct. However, my resolving function errors because there is no class Locality.  In the error message, I also print the value of *schema-imports*, and in

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 andreas.koestler.le...@gmail.com wrote: I would like to throw an exception when I'm trying

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

Re: Dynamic scoping issue

2011-03-20 Thread Tassilo Horn
Ken Wesson kwess...@gmail.com writes: the println prints {Locality localities.Locality}, which is correct. However, my resolving function errors because there is no class Locality.  In the error message, I also print the value of *schema-imports*, and in fact, it is {}. Does the resolving

Re: Dynamic scoping issue

2011-03-20 Thread Ken Wesson
On Sun, Mar 20, 2011 at 5:17 PM, Tassilo Horn tass...@member.fsf.org wrote: Ken Wesson kwess...@gmail.com writes: the println prints {Locality localities.Locality}, which is correct. However, my resolving function errors because there is no class Locality.  In the error message, I also print

Re: About a networked REPL...

2011-03-20 Thread Kevin Downey
My objection has nothing to do with string vs. byte. Messages used in wire protocols exist on a continuum between fixed width and variable width. The happy medium there, which almost all protocols follow is a fixed width header that also provides the bye count of the following variable width

Re: Dynamic scoping issue

2011-03-20 Thread Tassilo Horn
Ken Wesson kwess...@gmail.com writes: Hi Ken, Does the resolving function run on, or use, another thread? No, it runs in the same thread.  But some functions like `vseq' in the example produce LazySeqs.  So if LazySeq-realization computations are run in a different thread by default, that

Re: Dynamic scoping issue

2011-03-20 Thread Ken Wesson
On Sun, Mar 20, 2011 at 5:41 PM, Tassilo Horn tass...@member.fsf.org wrote: Ken Wesson kwess...@gmail.com writes: Hi Ken, Does the resolving function run on, or use, another thread? No, it runs in the same thread.  But some functions like `vseq' in the example produce LazySeqs.  So if

Re: Throwing an Exception with get

2011-03-20 Thread Daniel Werner
On 20 March 2011 22:02, Andreas Kostler andreas.koestler.le...@gmail.com 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

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 andreas.koestler.le...@gmail.com wrote: Would that be flow

Beginning Clojure

2011-03-20 Thread Ent SaaS
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

Re: Dynamic scoping issue

2011-03-20 Thread Meikel Brandmeyer
Hi, Am 20.03.2011 um 22:41 schrieb Tassilo Horn: Oh, yes. That was the exact issue. But clearly forcing realization is not a good solution. Is there some better way to do what I want? Maybe my macro should expand to something like that? ((fn [] (binding [...as before...] body)))

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

Re: About a networked REPL...

2011-03-20 Thread Chas Emerick
On Mar 20, 2011, at 12:47 PM, Kevin Downey wrote: I am no python programmer, but if you look at http://docs.python.org/library/socket.html you see it passes in the number of bytes you wish to receive on a call to the receiv method on a socket. With that in mind parsing nrepl messages becomes

Re: About a networked REPL...

2011-03-20 Thread Chas Emerick
The number indicates the number of entries in the following message; and yes, you're right that a sentinel would have been sufficient to terminate each message, though I wasn't attempting to follow in other protocols' footsteps. I'm sure the protocol is lacking in a variety of ways; as I said,

Re: About a networked REPL...

2011-03-20 Thread James Reeves
On 21 March 2011 00:18, Chas Emerick cemer...@snowtide.com wrote: In any case, my objective with nREPL was to get something working well that had what I thought were the right semantics for the use cases I was concerned with (i.e. point-to-point Clojure tooling backends).  Lifting those

Not quite getting for (newb question)

2011-03-20 Thread Brett Morgan
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

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)

Re: Not quite getting for (newb question)

2011-03-20 Thread Brett Morgan
Ahh, got it. Thank you Andreas. On Sun, Mar 20, 2011 at 6:55 PM, Andreas Kostler andreas.koestler.le...@gmail.com 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

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 andreas.koestler.le...@gmail.com wrote: Hi Brett, A :while clause continues the evaluation ONLY while it's expression is true

Re: About a networked REPL...

2011-03-20 Thread blais
On Mar 20, 12:16 pm, Chas Emerick cemer...@snowtide.com wrote: Martin, Thank you for the pushback.  :-) I'm not pushing back, I'm really just trying to understand... On Mar 19, 2011, at 8:30 PM, Martin Blais wrote:  I think this is wrong, because every single IDE client  will have to

Re: About a networked REPL...

2011-03-20 Thread blais
On Mar 20, 10:48 pm, blais martin.bl...@gmail.com wrote: really valuable, because it is unlikely to break between versions, and it's already good enough for a lot of users via stdin/stdout pipes (i.e., inferior lisp). Like being able to just telnet to a running VM and type (+ 2 2) and see 4