Re: seq and vector

2008-11-23 Thread [EMAIL PROTECTED]
On Nov 24, 12:41 am, "Kevin Downey" <[EMAIL PROTECTED]> wrote: > I don't think you understand. clojure data structures are IMMUTABLE. > every call to conj, or anyother function returns a "new" object. To > optimize there is sharing of structure. In the particular case at hand, i.e. calling vec on

Exception reporting

2008-11-23 Thread Timothy Pratley
If you put the following into a file and run it: (defn new-listener [port] (try (java.net.ServerSocket. port) (println "Listening on " port) (catch Exception e (println "Failed to listen on port " port ": " (.getMessage e) (println "Server started") (let [listen

Re: mutability

2008-11-23 Thread Timothy Pratley
I've implement a basic chat server application (as a stepping stone to bigger things). Simply run up the server eg: clj server.clj then use telnet to connect: telnet localhost connect from another window, and start typing messages to yourself... You'll see it relays the chat messages ar

Re: Clojure Box, alpha

2008-11-23 Thread Dmitry Neverov
Great work! Thanks! 2008/11/24 Shawn Hoover <[EMAIL PROTECTED]>: > Here's a first pass at a Windows installer for a Clojure environment in > Emacs: http://clojure.bighugh.com/clojure-box-r1109-setup.exe. > > The general idea is that of the Lispbox: you simply install and run this one > thing, and

Re: one way to write a factorial function

2008-11-23 Thread Stuart Sierra
That "for" should be equivalent to just "range" by itself. It can be even shorter: (defn factorial [n] (apply * (range 2 (inc n You can replace "apply" with "reduce" and it's just as fast, at least for n up to 10,000. I don't have the patience to wait for 100,000. -Stuart Sierra On No

Re: No complex numbers?

2008-11-23 Thread Mark H.
On Nov 23, 7:29 am, Rock <[EMAIL PROTECTED]> wrote: > Any plans to include them in future versions? If not, I guess I'll use > the Apache.Commons.Math library or possibly JScience. BTW which one do you prefer? I'm scared to try random numerical libraries since people find bugs in them all the ti

Re: Stubbing macro for isolated unit tests

2008-11-23 Thread James Reeves
On Nov 23, 11:58 pm, Justin Giancola <[EMAIL PROTECTED]> wrote: > Neat. I noticed that you're forcing the arg lists into vectors in both > make-maps and in stubfn. Since they're not being manipulated at all, > you could just as easily leave them as seqs and everything will still > work. The reduc

Re: multi-method dispatch for structs

2008-11-23 Thread wlr
On Nov 23, 4:03 am, Meikel Brandmeyer <[EMAIL PROTECTED]> wrote: > Hi, > > Am 23.11.2008 um 02:29 schrieb James Reeves: > > >> (defn make-person [name age] > >>   (assoc (struct person name age person) :type person)) > > > Maybe you could roll this into a macro: > > > (defmacro struct* > > [type

Re: assert with message [patch]

2008-11-23 Thread Stephen C. Gilardi
On Nov 23, 2008, at 7:52 PM, Bradbev wrote: > Here is a small change to assert that allows it to take an optional > message that will part of the exception that is thrown. I like that. In case folks haven't seen them, there are some more functions that make throwing an exception with a messag

Re: one way to write a factorial function

2008-11-23 Thread Craig Andera
Clever! Help me understand why this isn't written (defn factorial [n] (apply * (range 1 (+ n 1))) instead. That is, I don't get the purpose of the for statement. On Sun, Nov 23, 2008 at 4:08 PM, prhlava <[EMAIL PROTECTED]> wrote: > > > Hello folks, > > While learning, it occured to me that f

assert with message [patch]

2008-11-23 Thread Bradbev
Here is a small change to assert that allows it to take an optional message that will part of the exception that is thrown. Cheers Brad Index: src/clj/clojure/core.clj === --- src/clj/clojure/core.clj(revision 1102) +++ src/clj/

Re: Monads in Clojure

2008-11-23 Thread Adam Jones
On Nov 23, 1:15 pm, Konrad Hinsen <[EMAIL PROTECTED]> wrote: > On 21.11.2008, at 20:10, Adam Jones wrote: > > >> The file contains the macro definitions, the definitions of three > >> popular monads (maybe, list, state), and some illustrations of their > >> use. Comments are welcome! > > > Since

Clojure Box, alpha

2008-11-23 Thread Shawn Hoover
Here's a first pass at a Windows installer for a Clojure environment in Emacs: http://clojure.bighugh.com/clojure-box-r1109-setup.exe. The general idea is that of the Lispbox: you simply install and run this one thing, and you get a REPL and all the syntax and editing goodies from clojure-mode and

Re: Stubbing macro for isolated unit tests

2008-11-23 Thread Justin Giancola
Neat. I noticed that you're forcing the arg lists into vectors in both make-maps and in stubfn. Since they're not being manipulated at all, you could just as easily leave them as seqs and everything will still work. It might be a bit clearer to use reduce instead of map and merge to generate the

Re: seq and vector

2008-11-23 Thread Kevin Downey
I don't think you understand. clojure data structures are IMMUTABLE. every call to conj, or anyother function returns a "new" object. To optimize there is sharing of structure. On Sun, Nov 23, 2008 at 4:38 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > On Nov 23, 1:23 am, Rich Hickey <[EMAI

Testing Clojure - progress & sign up

2008-11-23 Thread Frantisek Sodomka
Hello all! I started writing some unit tests for Clojure. This is what I got so far: http://intricatevisions.com/source/clojure/fs_test_clojure.clj I am almost done with 'first' and 'rest'. I will do ffirst, frest, rfirst, rrest, second. Since I did 'if', I would also like to do 'and' and 'or'

Re: one way to write a factorial function

2008-11-23 Thread Randall R Schulz
On Sunday 23 November 2008 14:46, prhlava wrote: > Wow, the apply version above is faster (but not much) than the > version on: Usually a 10% running time reduction is nothing to sneeze at. (I interpreted your notation as decimal minutes. If it's minutes and seconds, then speed-up is about 10.7

Re: Patch: universal main() with repl/script/compile

2008-11-23 Thread Perry
I wanted to say thanks to Stuart & Stephen for taking this on. I think it'll make the point of entry into Clojure that much easier ("Just call the jar -- to get the REPL, to run a script, etc.") & I'm looking forward to it. Something that came up on another thread was what kind of AOT compilation

Re: one way to write a factorial function

2008-11-23 Thread prhlava
Wow, the apply version above is faster (but not much) than the version on: http://clojure.org/special_forms the "apply" version run 8.55 [minutes] the special_forms version run 9.50 [minutes] (this was for n=10 on and old P3) Beginners luck I suppose... Vlad PS: Displaying the number ta

Re: French translation of the Clojure rationale

2008-11-23 Thread Luc Prefontaine
Ha ! Ha ! Ha ! Je sens jean-François que nous nous entendrions pas mal tous les deux :))) Disons que je suis habituellement plus raide dans mes emails mais je n'osais pas : Ici au Québec on a un organisme qui se pense supérieur à l'Académie Française et qui s'appelle l'OLF (Office de la Lang

Re: Dynamically name a var

2008-11-23 Thread Ralf Bensmann
Sure, but I plan to have many maps. So one map with many maps as values... hm Anyway, I just play around... -Ralf On Sun, Nov 23, 2008 at 8:43 PM, Stuart Sierra <[EMAIL PROTECTED]>wrote: > > On Nov 23, 12:37 pm, "Ralf Bensmann" <[EMAIL PROTECTED]> > wrote: > > Hi all, > > > > how can I create

Re: Monads in Clojure

2008-11-23 Thread Konrad Hinsen
On 21.11.2008, at 20:10, Adam Jones wrote: >> The file contains the macro definitions, the definitions of three >> popular monads (maybe, list, state), and some illustrations of their >> use. Comments are welcome! > > Since they support mzero and mplus, aren't these equivalent to > Haskell's Mona

one way to write a factorial function

2008-11-23 Thread prhlava
Hello folks, While learning, it occured to me that factorial function can be written as: (defn factorial [n] (apply * (for [x (range 1 (+ n 1))] x))) I know that it has big argument list for large numbers, but it seems to scale nicely (at least in clojure). I am sure this was discussed

Re: seq and vector

2008-11-23 Thread Matthias Hölzl
On Sun, Nov 23, 2008 at 2:34 PM, André Thieme <[EMAIL PROTECTED]>wrote: > > On 23 Nov., 13:38, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > I have agents whose state is a vector (used as a buffer) of messages. > > There are a couple of transformation functions, e.g. tagging messages, > >

Re: File Copy

2008-11-23 Thread Parth Malwankar
On Nov 24, 12:34 am, Stuart Sierra <[EMAIL PROTECTED]> wrote: > Honestly, for this kind of low-level stuff I always use the Apache > Commons libraries, , esp. the Lang and IO > components.  They've got every imaginable stream function, all > carefully and efficiently

Re: Patch: universal main() with repl/script/compile

2008-11-23 Thread Meikel Brandmeyer
Hi, Am 23.11.2008 um 20:30 schrieb Stuart Sierra: Hmm, you mean write the REPL in Clojure? I hadn't though of that. Intriguing idea. It would be neat if the REPL were just a function, so you could start it from within a program using arbitrary input/ output streams. Something to think about..

Re: Dynamically name a var

2008-11-23 Thread Stuart Sierra
On Nov 23, 12:37 pm, "Ralf Bensmann" <[EMAIL PROTECTED]> wrote: > Hi all, > > how can I create a var with a "dynamic name for a symbol" using the def > special form? This works: user=> (defmacro defsym [symbol & body] `(def ~(eval symbol) [EMAIL PROTECTED])) nil user=> (

Re: Patch: universal main() with repl/script/compile

2008-11-23 Thread Matt Revelle
On Nov 23, 2008, at 2:30 PM, Stuart Sierra wrote: > > On Nov 22, 3:57 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: >> But... what are we thinking? Along the lines of Rich's suggestion the >> other day... I'm thinking we should stick to the very simple >> Compile.java to solve the bootstra

Re: File Copy

2008-11-23 Thread Stuart Sierra
Honestly, for this kind of low-level stuff I always use the Apache Commons libraries, , esp. the Lang and IO components. They've got every imaginable stream function, all carefully and efficiently implemented. But if you're determined to do it in Clojure, loop/recur i

Re: Patch: universal main() with repl/script/compile

2008-11-23 Thread Stuart Sierra
On Nov 22, 3:57 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > But... what are we thinking? Along the lines of Rich's suggestion the   > other day... I'm thinking we should stick to the very simple   > Compile.java to solve the bootstrap problem and then write Main in   > Clojure where it's

Re: macroexpand-1 does not expand?

2008-11-23 Thread Michael Wood
On Sun, Nov 23, 2008 at 7:50 PM, Ralf Bensmann <[EMAIL PROTECTED]> wrote: > Sorry! Yes I missed the backqoute... > > user=> (macroexpand-1 `(t "c" 0)) > (def *c* 0) No need for a back tick. A normal quote works fine: user=> (macroexpand-1 '(t "c" 0)) (def *c* 0) -- Michael Wood <[EMAIL PROTEC

Re: seq and vector

2008-11-23 Thread Stuart Sierra
On Nov 23, 1:23 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > I still don't understand your expectation here. If the filter does any > filtering, it won't return everything in the vector, so the new result > will have fewer items. Do you want a vector with fewer items? Then > you'll have a new vect

Re: File Copy

2008-11-23 Thread James Reeves
On Nov 23, 6:35 pm, Parth Malwankar <[EMAIL PROTECTED]> wrote: > I am trying to translate the following Java > snippet into a file copy routine in Clojure. > >   public static void copy(InputStream in, OutputStream out)    throws > IOException { >     byte[] buffer = new byte[1024]; >     while

expectation framework

2008-11-23 Thread Allen Rohner
I've been working on a small library to assert that functions are called during a unit test. The syntax looks like: (calls [[user/foo :times 2 :returns 3] [user/bar :returns 42]] (fn-being-tested)) This will assert that foo is called exactly twice, and bar is called exactly once

File Copy

2008-11-23 Thread Parth Malwankar
Hello, I am trying to translate the following Java snippet into a file copy routine in Clojure. public static void copy(InputStream in, OutputStream out)throws IOException { byte[] buffer = new byte[1024]; while (true) { int bytesRead = in.read(buffer); if (bytesRead ==

Re: macroexpand-1 does not expand?

2008-11-23 Thread Ralf Bensmann
Sorry! Yes I missed the backqoute... user=> (macroexpand-1 `(t "c" 0)) (def *c* 0) On Sun, Nov 23, 2008 at 6:48 PM, Ralf Bensmann <[EMAIL PROTECTED]>wrote: > Just saw that macroexpand-1 doesn't work: > > user=> (defmacro t [n v] `(def ~(symbol (str "*" n "*")) ~v)) > nil > user=> (t "bb" 0) > #'

macroexpand-1 does not expand?

2008-11-23 Thread Ralf Bensmann
Just saw that macroexpand-1 doesn't work: user=> (defmacro t [n v] `(def ~(symbol (str "*" n "*")) ~v)) nil user=> (t "bb" 0) #'user/*bb* user=> *bb* 0 user=> (macroexpand-1 (t "c" 0)) #'user/*c* Or am I missing something? -Ralf --~--~-~--~~~---~--~~ You received

Dynamically name a var

2008-11-23 Thread Ralf Bensmann
Hi all, how can I create a var with a "dynamic name for a symbol" using the def special form? I tried: user=> (def (symbol "user" "a") 0) java.lang.Exception: Second argument to def must be a Symbol (NO_SOURCE_FILE:44) Thanks, -Ralf --~--~-~--~~~---~--~~ You rece

Re: number boxing issue in prime number sieve?

2008-11-23 Thread harrison clarke
found the problem: sorted-set doesn't play nice with longs. the "fix" to my specific problem is to not square the primes when adding new counters. any way to change the comparator on a sorted set? i'd also like to use lazy seq's as counters, and it doesn't liek that either. --~--~-~--~--

number boxing issue in prime number sieve?

2008-11-23 Thread harrison clarke
i made a lazy prime number seive, and it seems to work for a while: (defn natural [] (iterate #(+ % 1) 1)) (def primes ;;takes a sorted set of counters and a seq of numbers to filter ((fn sieve [in-counters checked] ;;first part of the cons is the first in said seq. hurray!

Stubbing macro for isolated unit tests

2008-11-23 Thread James Reeves
In case anyone's interested, I've created a macro for stubbing existing functions. I created it for my Fact unit testing library, but it could be used with any unit testing framework, such as the test-is library in clojure.contrib. Since stubbing is an important part of isolating functions for the

Re: Newbie: Adding metadata to a method

2008-11-23 Thread Michael Wood
On Sun, Nov 23, 2008 at 5:39 PM, samppi <[EMAIL PROTECTED]> wrote: > > The answer to your question at the end, by the way, is that you're not > var-quoting the x. 'defn attaches metadata to the variable object you > define, not the function object itself. (meta x) is the metadata of > the _value_

Re: Clojure HTML Documentation

2008-11-23 Thread Mark McGranaghan
I've added the license notices to the bottom of each var's documentation per the discussion in #clojure - sorry about the ommision. - Mark On Sun, Nov 23, 2008 at 9:10 AM, Rich Hickey <[EMAIL PROTECTED]> wrote: > > > > On Nov 21, 3:17 am, Mark McGranaghan <[EMAIL PROTECTED]> wrote: >> I've creat

Re: Newbie: Adding metadata to a method

2008-11-23 Thread samppi
The answer to your question at the end, by the way, is that you're not var-quoting the x. 'defn attaches metadata to the variable object you define, not the function object itself. (meta x) is the metadata of the _value_ of x, which is just the function with no metadata. To get the variable's meta

Re: No complex numbers?

2008-11-23 Thread Rich Hickey
On Nov 23, 10:28 am, Rock <[EMAIL PROTECTED]> wrote: > I think the best bet would be implementing them in Clojure itself. I'm > saying this because otherwise it would really get harder given the > constraints regarding immutability. Furthermore, the implementation > should, I think, be generic,

Re: No complex numbers?

2008-11-23 Thread Rock
I think the best bet would be implementing them in Clojure itself. I'm saying this because otherwise it would really get harder given the constraints regarding immutability. Furthermore, the implementation should, I think, be generic, that is, we should be capable of creating complex numbers, the

Re: No complex numbers?

2008-11-23 Thread Rich Hickey
On Nov 23, 8:56 am, Rock <[EMAIL PROTECTED]> wrote: > On Nov 23, 2:37 pm, André Thieme <[EMAIL PROTECTED]> wrote: > > > On 23 Nov., 13:29, Rock <[EMAIL PROTECTED]> wrote: > > > > I've just noticed there is no support for complex numbers in Clojure. > > > There are a few posts on the issue here,

Re: Clojure HTML Documentation

2008-11-23 Thread Rich Hickey
On Nov 21, 3:17 am, Mark McGranaghan <[EMAIL PROTECTED]> wrote: > I've created some experimental HTML docs for Clojure. You can see them > on S3:http://clj-doc.s3.amazonaws.com/tmp/doc-1116/index.html > > Or, just for kicks, on Amazon's new Cloud Front > CDN:http://d2nbqsesuabw8o.cloudfront.net

Re: Keyword constraints not enforced

2008-11-23 Thread James Reeves
On Nov 23, 11:38 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > According tohttp://clojure.org/reader: > > > Keywords are like symbols, except: > > >          o They can and must begin with a colon, e.g. :fred. > >          o They cannot contain '.' or name classes. > > Shouldn't t

Re: No complex numbers?

2008-11-23 Thread Rock
On Nov 23, 2:37 pm, André Thieme <[EMAIL PROTECTED]> wrote: > On 23 Nov., 13:29, Rock <[EMAIL PROTECTED]> wrote: > > > I've just noticed there is no support for complex numbers in Clojure. > > There are a few posts on the issue here, but no rationale. I'm a > > mathematician, and complex numbers p

[Bug?] Keyword constraints not enforced

2008-11-23 Thread [EMAIL PROTECTED]
Hi, According to http://clojure.org/reader: > Keywords are like symbols, except: > > o They can and must begin with a colon, e.g. :fred. > o They cannot contain '.' or name classes. This is what I get using the latest SVN revision (1211): user=> (keyword? :String) true user=>

Re: jEdit Mode for Clojure

2008-11-23 Thread Patrick Wright
FYI, another developer has been working on an edit mode for clojure. You can download it from http://sourceforge.net/tracker/?func=detail&atid=300588&aid=2201893&group_id=588 See also this thread http://www.nabble.com/Edit-mode-for-Clojure-ts20168077.html#a20168077 Note that the version in the j

Re: Clojure HTML Documentation

2008-11-23 Thread Patrick Wright
Nice. Just as input and for ideas--the JavaFX Script compiler team is working on a new documentation format instead of using the legacy JavaDoc HTML format. Basically their documentation parser produces clean XML, which they run through XSLT to produce the final, browsable HTML. The current versi

Re: No complex numbers?

2008-11-23 Thread André Thieme
On 23 Nov., 13:29, Rock <[EMAIL PROTECTED]> wrote: > I've just noticed there is no support for complex numbers in Clojure. > There are a few posts on the issue here, but no rationale. I'm a > mathematician, and complex numbers pop up all over the place. CL and > Scheme have always had native suppo

Re: seq and vector

2008-11-23 Thread André Thieme
On 23 Nov., 13:38, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have agents whose state is a vector (used as a buffer) of messages. > There are a couple of transformation functions, e.g. tagging messages, > removing messages from the vector etc. which are implemented with map > and filter.

Re: seq and vector

2008-11-23 Thread [EMAIL PROTECTED]
On Nov 23, 1:23 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > I still don't understand your expectation here. If the filter does any > filtering, it won't return everything in the vector, so the new result > will have fewer items. Do you want a vector with fewer items? Then > you'll have a new vect

No complex numbers?

2008-11-23 Thread Rock
I've just noticed there is no support for complex numbers in Clojure. There are a few posts on the issue here, but no rationale. I'm a mathematician, and complex numbers pop up all over the place. CL and Scheme have always had native support for them. I took it for granted they were there until I

Re: French translation of the Clojure rationale

2008-11-23 Thread verec
> Cela dit, au cours des derniers mois je me suis tenu dans des groupes > de discussions de programmation francophones et j'ai découvert qu'un > nombre assez important de gens sont soit très mal à l'aise en anglais > ou y sont carrément hostiles. Ne pas vouloir utiliser l'Anglais pour l'informati

Re: multi-method dispatch for structs

2008-11-23 Thread Meikel Brandmeyer
Hi, Am 23.11.2008 um 02:29 schrieb James Reeves: (defn make-person [name age] (assoc (struct person name age person) :type person)) Maybe you could roll this into a macro: (defmacro struct* [type & params] `(assoc (struct ~type [EMAIL PROTECTED]) :type ~type)) Why? A function does the sam