Re: Prefix dot in protocol method

2012-07-23 Thread Tassilo Horn
Warren Lynn wrn.l...@gmail.com writes:

Hi Warren,

 I found that if I define a protocol like this:

 (defprotocol IProc
   (procMethod [this] some method))

 I can invoke it on a type either
 (procMethod object)
 or 
 (.procMethod object)

 Note the prefix dot in the second case. 

 I like this dot version because that means I can replace a record field 
 with a method with the same name and things will work as usual, like 
 property in Python. However, I think someone mentioned that the dot 
 version is just a JVM implementation detail that got exposed so it seems I 
 cannot rely on it as part of the language. Is that the case?

Yes.  Defining a protocol on the JVM also creates an interface with the
same name in the current package, and records and types satisfying that
protocol implement this interface.  So this works:

--8---cut here---start-8---
(defprotocol Fooable
  (foo [this]))

(defrecord FooRec []
  Fooable
  (foo [this] this))

(foo (-FooRec))
#user.FooRec{}
user (.foo (-FooRec))
Reflection warning, NO_SOURCE_FILE:1 - reference to field foo can't be resolved.
#user.FooRec{}
--8---cut here---end---8---

Note that you get a reflection warning in the dot-case which you can
avoid by type-hinting with the implicitly generated interface.

--8---cut here---start-8---
user (.foo ^user.Fooable (-FooRec))
#user.FooRec{}
--8---cut here---end---8---

However, the dot-syntax won't work if you extend your protocol
dynamically to existing types.

--8---cut here---start-8---
(extend-protocol Fooable
  java.util.Date
  (foo [this] this))

user (foo (java.util.Date.))
#inst 2012-07-23T06:07:51.130-00:00
user (.foo (java.util.Date.))
Reflection warning, NO_SOURCE_FILE:1 - reference to field foo can't be resolved.
No matching field found: foo for class java.util.Date
  [Thrown class java.lang.IllegalArgumentException]
--8---cut here---end---8---

Bye,
Tassilo

-- 
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


Lamina and channels-driven concurrency with Clojure

2012-07-23 Thread Alexey Kachayev
Hi, everybody!

Rob Pike gave an interesting talk on latest Google I/O Go Concurrency
Patterns with excellent examples of how to write simple but powerful
concurrency code using goroutines and channels (his talk on youtube:
http://www.youtube.com/watch?v=f6kdp27TYZsfeature=youtu.be). My idea was
to implement the same examples with Clojure and Lamina library which
provides event-driven workflow for Clojure (on github:
https://github.com/ztellman/lamina/). As the result for this I have two
gists:

1. Golang examples from talk - https://gist.github.com/3124594
2. Clojure analog - https://gist.github.com/3146759

Several things was implemented using different approach from origin, cause
of different paradigms and workflows. But I think, that in general, this
code blocks can act both as basic for article about channels-driven
concurrency with Clojure (which I plan to write in nearest future) and good
addition to Lamina-project's documentation.  Unfortunately I didn't find
enough documentation for Lamina project (in general library is great, but
some things are not straightforward and hard to use without
examples/clarifications).

I didn't use such approach for concurrency programming yet, so I want to
ask community to check/review/update code in terms of best practices. I
know that there are some problems, which possible can be resolved in more
efficient/beautiful way (there are several TODOs in comments). I would
greatly appreciate any comments/ideas/suggestions on how to make this code
better.

P.S. Please, note that main (and most powerful) example is Google
Search - https://gist.github.com/3146759#file_clojure_channels_7_search.clj(for
both gists). Other examples are just preparing to main one :)

-- 
Kind regards,
Alexey S. Kachayev, CTO at KitApps, Inc.
--
Twitter: @kachayev
Github: https://github.com/kachayev
Skype: kachayev
Tel: +380-996692092

-- 
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: Clojurians in the midlands (UK)

2012-07-23 Thread Colin Yates
I was musing about starting a regular meet-up, but it doesn't sound like 
there are enough people to justify it.

On Friday, 20 July 2012 13:03:03 UTC+1, Jim foo.bar wrote:

 There are a few in Manchester (including me) Do you have anything 
 particular in mind?

 Jim

 On Wed, Jul 18, 2012 at 9:53 AM, Philip Potter 
 philip.g.pot...@gmail.comwrote:

 There are a few in Cambridge, but it's a stretch to call that the 
 Midlands:

 http://groups.google.com/group/camclj
 On Jul 17, 2012 9:06 AM, Colin Yates colin.ya...@gmail.com wrote:

 I know there are a few in London, but are there any around the midlands 
 in the UK (Coventry, Leicester, Birmingham, Derby etc.)? 

 -- 
 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: is their a Clojure framework for handling form validation?

2012-07-23 Thread Pierre-Henry Perret
See [1].

This is a web framework which has a form validation included.


[1] http://www.clojurescriptone.com

Le lundi 23 juillet 2012 01:46:52 UTC+2, larry google groups a écrit :

 Since 2000 I've been doing web development, first with PHP and then with 
 Ruby On Rails. In the world of PHP, there are some frameworks, such as 
 Symfony, that have classes for managing forms, both generating the HTML for 
 the forms, and also handling the validation of the forms. In the world of 
 Python, the Django framework also has facilities for generating and 
 validating forms. These frameworks offer certain time saving conveniences. 
 For instance, with the Symfony framework, if you have a database table that 
 has a foreign key, then you can get that other table (the target of the 
 foreign key) to appear in a form as a pre-populated select box, 
 automatically (after filling out some config files).

 I'm now trying to make Clojure my primary development language for 
 everything, including web development. I'm curious, are there any libraries 
 in the land of Clojure that offer similar conveniences for forms? 


-- 
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: Any downside of record compared to map

2012-07-23 Thread Bronsa
there's also the reader literal
user= (defrecord foo [bar baz])
user.foo
user= #user.foo{:baz 1 :bar 2}
#user.foo{:bar 2, :baz 1}



2012/7/23 Takahiro Hozumi fat...@googlemail.com

 Baishampayan
 I didn't know `map-Foo`. Thank you for the infomation!


 On Monday, July 23, 2012 2:11:45 PM UTC+9, Baishampayan Ghose wrote:

 On Mon, Jul 23, 2012 at 10:37 AM, Takahiro Hozumi fat...@googlemail.com
 wrote:
  2. The construction of record depends on an order of arguments.
  Sometimes, I feel that a lack of construction with key-value style is
 not
  convenient.

 (defrecord Foo ...

 will give you `-Foo`  `map-Foo` for free. The second one accepts a
 map as input.

 Regards,
 BG

 --
 Baishampayan Ghose
 b.ghose at gmail.com


 On Monday, July 23, 2012 2:11:45 PM UTC+9, Baishampayan Ghose wrote:

 On Mon, Jul 23, 2012 at 10:37 AM, Takahiro Hozumi fat...@googlemail.com
 wrote:
  2. The construction of record depends on an order of arguments.
  Sometimes, I feel that a lack of construction with key-value style is
 not
  convenient.

 (defrecord Foo ...

 will give you `-Foo`  `map-Foo` for free. The second one accepts a
 map as input.

 Regards,
 BG

 --
 Baishampayan Ghose
 b.ghose at gmail.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


-- 
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: Any downside of record compared to map

2012-07-23 Thread Lee Spector

Considering that maps do have upsides compared to records in some cases (as 
indicated, e.g., by Chas's flowchart), and that struct-maps add a couple of 
handy features in the context of some uses of maps, can anybody say why 
struct-maps are deprecated?

 -Lee


On Jul 23, 2012, at 1:07 AM, Takahiro Hozumi wrote:

 I think defrecord has 5 downsides compared to regular map.
 
 1. The literal of regular map is eye-friendly and portable.
 However I still don't know how helpful instant literals added in clojure 1.4 
 is for records.
 
 2. The construction of record depends on an order of arguments.
 Sometimes, I feel that a lack of construction with key-value style is not 
 convenient.
 
 3. Replacing all regular maps to records simply make code volume increase.
 
 4. Records easily loose their type.
 (merge {:c 3 :d 4} (Foo. 1 2))
 ;= {:a 1, :b 2, :c 3, :d 4}
 
 5. Regular map is a persistent data structure, which has internally efficient 
 tree data structure, but record is compiled into class with fields as 
 something like POJO.
 I suspect efficiency of record when repeated assoc/dissoc.
 
 But I could be 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


XML parsing with namespace prefixes

2012-07-23 Thread Marcel Möhring

Hi,

I am trying to parse an xpdl file. The problem for me is, that every tag 
is prefixed with xpdl namespace. The lookup from clojure.data.zip.xml 
always returns nil.

(the same code works for non-prefixed XMLs)

zipper:
[{:tag :xpdl:Package,
  :attrs
  {:xmlns:xpdl http://www.wfmc.org/2008/XPDL2.1;,
   :xmlns http://www.wfmc.org/2008/XPDL2.1;,
   :xmlns:xsi http://www.w3.org/2001/XMLSchema-instance;,
   :Id testPackage,
   :Name Test-Package,
   :xsi:schemaLocation
   http://www.wfmc.org/2008/XPDL2.1 
http://www.wfmc.org/standards/docs/bpmnxpdl_31.xsd},

...

code:
(ns test.core
  (:require [clojure.zip :as zip]
[clojure.xml :as xml]
[clojure.data.zip.xml :as cdzip]))

(def zipper (zip/xml-zip (xml/parse res/testPackage.xpdl)))

(cdzip/xml- zipper :xpdl:Package)
returns nil

(cdzip/xml- zipper (keyword xpdl:Package))
also returns nil

Does anybody know how to handle lookups in such XMLs?

--
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


contrib change suggestion, and volunteering

2012-07-23 Thread pjm
Hello, everyone. I am a newbie, and have been trying to follow along on Clojure 
Notes http://clojure-notes.rubylearning.org/#es, but it has been 
difficult due to the major change that in the way clojure.contrib works 
recently. I think I have a workaround to clojure.contrib.server-socket not 
being available atm (just read it in as source; tell me if I'm on the wrong 
track here, please), but this was not something that came to me in a quick 
search. 

My suggestion is: can we minimize major changes like this. It looks like 
the contrib change was done for a good reason (but I'm not qualified to 
judge), but it does make following along in a a tutorial challenging.

Also, it looks like you are calling for people to take care of individual 
modules in clojure.contrib on github, so I'm (reluctantly) volunteering, 
although if there are any problems, I'm not sure what I can do.

Just my two cents.

Cheers,
Peter

-- 
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: is their a Clojure framework for handling form validation?

2012-07-23 Thread Paweł Rozynek
noir framework got something for it:

http://webnoir.org/autodoc/1.3.0/noir.validation.html

never saw standalone lib just for that purpose tho.

regards
PR

-- 
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: Clojurians in the midlands (UK)

2012-07-23 Thread Christian Bryan
Just started Clojure and I'm from Walsall/Black Country. I agree, its going 
be difficult finding fellow Clojurians around here.
 
Christian
On Monday, 23 July 2012 09:21:49 UTC+1, Colin Yates wrote:

 I was musing about starting a regular meet-up, but it doesn't sound like 
 there are enough people to justify it.

 On Friday, 20 July 2012 13:03:03 UTC+1, Jim foo.bar wrote:

 There are a few in Manchester (including me) Do you have anything 
 particular in mind?

 Jim

 On Wed, Jul 18, 2012 at 9:53 AM, Philip Potter philip.g.pot...@gmail.com
  wrote:

 There are a few in Cambridge, but it's a stretch to call that the 
 Midlands:

 http://groups.google.com/group/camclj
 On Jul 17, 2012 9:06 AM, Colin Yates colin.ya...@gmail.com wrote:

 I know there are a few in London, but are there any around the midlands 
 in the UK (Coventry, Leicester, Birmingham, Derby etc.)? 

 -- 
 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: Clojurians in the midlands (UK)

2012-07-23 Thread David Powell
On Tue, Jul 17, 2012 at 9:06 AM, Colin Yates colin.ya...@gmail.com wrote:

 I know there are a few in London, but are there any around the midlands in
 the UK (Coventry, Leicester, Birmingham, Derby etc.)?


I'm from Staffordshire.

-- 
Dave

-- 
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: is their a Clojure framework for handling form validation?

2012-07-23 Thread Michael Klishin
Paweł Rozynek:

 never saw standalone lib just for that purpose tho.

https://github.com/michaelklishin/validateur

Validateur is not specific to Web forms, works for any kind of data validation 
and very extensible.

MK

mich...@defprotocol.org



signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: contrib change suggestion, and volunteering

2012-07-23 Thread Softaddicts
Hi Peter,

Contrib has been sliced in separate modules since version 1.3.
The tutorial you are referring to is based on 1.2
What can be expected from outdated documentation ? Spontaneous  update ? :)

Did you had a look at this to see if you can find were the stuff you need
was migrated (if still supported) ?

http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go

That change was a huge one but it's been for the best, individual libs
are not tied anymore to a common release mechanism. They can change at their 
own pace.

There's also a monolithic contrib somewhere 1.3 compatible but I would
suggest getting yourself acquainted with the new stuff.

Have a nice learning curve,

Luc


 Hello, everyone. I am a newbie, and have been trying to follow along on 
 Clojure 
 Notes http://clojure-notes.rubylearning.org/#es, but it has been 
 difficult due to the major change that in the way clojure.contrib works 
 recently. I think I have a workaround to clojure.contrib.server-socket not 
 being available atm (just read it in as source; tell me if I'm on the wrong 
 track here, please), but this was not something that came to me in a quick 
 search. 
 
 My suggestion is: can we minimize major changes like this. It looks like 
 the contrib change was done for a good reason (but I'm not qualified to 
 judge), but it does make following along in a a tutorial challenging.
 
 Also, it looks like you are calling for people to take care of individual 
 modules in clojure.contrib on github, so I'm (reluctantly) volunteering, 
 although if there are any problems, I'm not sure what I can do.
 
 Just my two cents.
 
 Cheers,
 Peter
 
 -- 
 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
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
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: reduction to tail recursion

2012-07-23 Thread Mimmo Cosenza
hi Merek and thanks for the link. But it does not answer my question. 
I was looking for a demonstration of the reducibility of (not tail) 
recursion to tail recursion. Or there is a demonstration of that, or nobody 
could say that a (not tail) recursion definition is always reducible to a 
tail recursion definition.

From P.Graham -  On Lisp 

A function which isn’t tail-recursive can often be transformed into one 
that is
by embedding in it a local function which uses an *accumulator.*  

He say can often he does not say can always. So, I'm still in dubt.

mimmo




On Saturday, July 21, 2012 1:04:20 PM UTC+2, mnicky wrote:

 Discussion about this is in the penultimate paragraph of 
 http://c2.com/cgi/wiki?TailCallOptimization

 and btw, there's difference between:
  - tail recursion - function calls itself
  - tail call - function calls whatever


 Marek.

 On Saturday, July 21, 2012 11:15:33 AM UTC+2, Mimmo Cosenza wrote:

 Hi,
 a very basic question. Any not tail recursion code can be reduced to 
 tail recursion code? 

 Thanks

 Mimmo


On Saturday, July 21, 2012 1:04:20 PM UTC+2, mnicky wrote:

 Discussion about this is in the penultimate paragraph of 
 http://c2.com/cgi/wiki?TailCallOptimization

 and btw, there's difference between:
  - tail recursion - function calls itself
  - tail call - function calls whatever


 Marek.

 On Saturday, July 21, 2012 11:15:33 AM UTC+2, Mimmo Cosenza wrote:

 Hi,
 a very basic question. Any not tail recursion code can be reduced to 
 tail recursion code? 

 Thanks

 Mimmo


On Saturday, July 21, 2012 1:04:20 PM UTC+2, mnicky wrote:

 Discussion about this is in the penultimate paragraph of 
 http://c2.com/cgi/wiki?TailCallOptimization

 and btw, there's difference between:
  - tail recursion - function calls itself
  - tail call - function calls whatever


 Marek.

 On Saturday, July 21, 2012 11:15:33 AM UTC+2, Mimmo Cosenza wrote:

 Hi,
 a very basic question. Any not tail recursion code can be reduced to 
 tail recursion code? 

 Thanks

 Mimmo


On Saturday, July 21, 2012 1:04:20 PM UTC+2, mnicky wrote:

 Discussion about this is in the penultimate paragraph of 
 http://c2.com/cgi/wiki?TailCallOptimization

 and btw, there's difference between:
  - tail recursion - function calls itself
  - tail call - function calls whatever


 Marek.

 On Saturday, July 21, 2012 11:15:33 AM UTC+2, Mimmo Cosenza wrote:

 Hi,
 a very basic question. Any not tail recursion code can be reduced to 
 tail recursion code? 

 Thanks

 Mimmo



-- 
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: reduction to tail recursion

2012-07-23 Thread nicolas.o...@gmail.com
Yes.

For example, you can have a look at CPS transformation.

If you want tail recursion and not tail calls, you can add
trampolining to the mix.

-- 
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: Casting SPELs in Clojure

2012-07-23 Thread Joe Hughes
All,

I figured it out.  Still trying to get Functional Programming ideas in 
my head.

Regards,
Joe

On Friday, June 29, 2012 11:11:56 AM UTC-5, Joe Hughes wrote:

 All,

 I've been playing with Clojure and found this website, 
 http://www.lisperati.com/clojure-spels/casting.html.  Typed the code into 
 Clojure 1.4.0 and got the issue below.  Here is the code in question.


 (defmacro defspel [ rest] `(defmacro ~@rest))


 (defspel game-action [command subj obj place  args]
   `(defspel ~command [subject# object#]
  `(spel-print (cond (and (= location '~'~place)
  (= '~subject# '~'~subj)
  (= '~object# '~'~obj)
  (have? '~'~subj))
 ~@'~args
 :else '(i cannot ~'~command like that -)

 (game-action weld chain bucket attic
(cond (and (have? 'bucket) (def chain-welded true))
   '(the chain is now securely welded to the bucket -)
  :else '(you do not have a bucket -)))


 When I do


 (weld chain bucket)


 instead of getting


 (you do not have a chain -)


 I get


 (i cannot weld like that -)


 From what I'm reading (defspel game-action..., something isn't correct and 
 the result is the :else instead of the if.  This was written using Clojure 
 1.1, so if anyone has a solution about why this works in 1.1 and not 1.4 I 
 would like to hear it.


 TIA,
 Joe 


-- 
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: Casting SPELs in Clojure

2012-07-23 Thread Denis Labaye
Hi,

On Mon, Jul 23, 2012 at 5:38 PM, Joe Hughes jwhughe...@gmail.com wrote:

 All,

 I figured it out.  Still trying to get Functional Programming ideas in
 my head.


The macro defspel is not functional programming, it's dark Lisp's macro
Voodoo.

I would not advise starting Clojure with macros, you should start with
something with a smoother learning curve like: http://www.4clojure.com/.

That said, I red The Land Of Lisp before learning Clojure, and it's a
great book.
Transposing Common LISP to Clojure may not be a good idea though.

My advice would be: If you want to learn Common Lisp before Clojure it's a
great idea (you will enjoy Clojure much more :), but take the time to learn
the language.
If you want to directly learn Clojure, then take a good book (Clojure
Programming - 2012, Practial Clojure - 2010 or Joy Of Clojure - 2011) +
some practical work like 4clojure.com.

Cheers,

Denis



 Regards,
 Joe


 On Friday, June 29, 2012 11:11:56 AM UTC-5, Joe Hughes wrote:

 All,

 I've been playing with Clojure and found this website,
 http://www.lisperati.**com/clojure-spels/casting.htmlhttp://www.lisperati.com/clojure-spels/casting.html
 **.  Typed the code into Clojure 1.4.0 and got the issue below.  Here is
 the code in question.


 (defmacro defspel [ rest] `(defmacro ~@rest))


 (defspel game-action [command subj obj place  args]
   `(defspel ~command [subject# object#]
  `(spel-print (cond (and (= location '~'~place)
  (= '~subject# '~'~subj)
  (= '~object# '~'~obj)
  (have? '~'~subj))
 ~@'~args
 :else '(i cannot ~'~command like that -)

 (game-action weld chain bucket attic
(cond (and (have? 'bucket) (def chain-welded true))
   '(the chain is now securely welded to the bucket -)
  :else '(you do not have a bucket -)))


 When I do


 (weld chain bucket)


 instead of getting


 (you do not have a chain -)


 I get


 (i cannot weld like that -)


 From what I'm reading (defspel game-action..., something isn't correct
 and the result is the :else instead of the if.  This was written using
 Clojure 1.1, so if anyone has a solution about why this works in 1.1 and
 not 1.4 I would like to hear it.


 TIA,
 Joe

  --
 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

How do you determine terminal/console width in `lein repl`?

2012-07-23 Thread Gabriel Horner
Hi,

For a clojar I'm writing http://github.com/cldwalker/table, I'd like to 
know a user's terminal width so I can resize output appropriately. All the 
following techniques, which work fine in a ruby repl, don't work in 
leiningen2:

$ lein repl
user= (System/getenv COLUMNS)
nil

user= (clojure.java.shell/sh tput cols)
{:exit 0, :out 80\n, :err }
; This is incorrect as my terminal width is 238

user= (clojure.java.shell/sh stty size)
{:exit 1, :out , :err stty: stdin isn't a terminal\n}

The only thing that does work is if I `export COLUMNS`, something I don't 
have to do for a ruby repl. Thoughts on why none of these approaches work 
and what a correct one would be?

Thanks,
Gabriel

-- 
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: Casting SPELs in Clojure

2012-07-23 Thread Joe Hughes
Denis:

   Thanks for the link.  Looks interesting.  Between it and the Euler 
Project, I should continue learning Clojure.

Regards,
Joe

On Monday, July 23, 2012 10:53:56 AM UTC-5, Denis Labaye wrote:

 Hi, 

 On Mon, Jul 23, 2012 at 5:38 PM, Joe Hughes jwhughe...@gmail.com wrote:

 All,

 I figured it out.  Still trying to get Functional Programming ideas 
 in my head.


 The macro defspel is not functional programming, it's dark Lisp's macro 
 Voodoo.

 I would not advise starting Clojure with macros, you should start with 
 something with a smoother learning curve like: http://www.4clojure.com/.

 That said, I red The Land Of Lisp before learning Clojure, and it's a 
 great book.
 Transposing Common LISP to Clojure may not be a good idea though.

 My advice would be: If you want to learn Common Lisp before Clojure it's a 
 great idea (you will enjoy Clojure much more :), but take the time to learn 
 the language. 
 If you want to directly learn Clojure, then take a good book (Clojure 
 Programming - 2012, Practial Clojure - 2010 or Joy Of Clojure - 2011) + 
 some practical work like 4clojure.com.

 Cheers,

 Denis
  


 Regards,
 Joe


 On Friday, June 29, 2012 11:11:56 AM UTC-5, Joe Hughes wrote:

 All,

 I've been playing with Clojure and found this website, 
 http://www.lisperati.**com/clojure-spels/casting.htmlhttp://www.lisperati.com/clojure-spels/casting.html
 **.  Typed the code into Clojure 1.4.0 and got the issue below.  Here 
 is the code in question.


 (defmacro defspel [ rest] `(defmacro ~@rest))


 (defspel game-action [command subj obj place  args]
   `(defspel ~command [subject# object#]
  `(spel-print (cond (and (= location '~'~place)
  (= '~subject# '~'~subj)
  (= '~object# '~'~obj)
  (have? '~'~subj))
 ~@'~args
 :else '(i cannot ~'~command like that -)

 (game-action weld chain bucket attic
(cond (and (have? 'bucket) (def chain-welded true))
   '(the chain is now securely welded to the bucket -)
  :else '(you do not have a bucket -)))


 When I do


 (weld chain bucket)


 instead of getting


 (you do not have a chain -)


 I get


 (i cannot weld like that -)


 From what I'm reading (defspel game-action..., something isn't correct 
 and the result is the :else instead of the if.  This was written using 
 Clojure 1.1, so if anyone has a solution about why this works in 1.1 and 
 not 1.4 I would like to hear it.


 TIA,
 Joe 

  -- 
 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: Casting SPELs in Clojure

2012-07-23 Thread Denis Labaye
On Mon, Jul 23, 2012 at 6:11 PM, Joe Hughes jwhughe...@gmail.com wrote:

 Denis:

Thanks for the link.  Looks interesting.  Between it and the Euler
 Project, I should continue learning Clojure.


Euler is also great, but 4clojure is specifically oriented towards Clojure,
and the creators of 4clojure really tried to provide a path to learning
Clojure:
* First the basics: how to write expressions, what is Truthy, what is
Falsey. ...
* Then the datastructures, lists, maps, ...
* Then the essential functions (map, reduce, ...): You often even have to
re-implement them
* And more advanced programming challenges: graph traversal, ..
* And the killer feature: You can follow people and compare your solutions
to theirs, sometimes it's frustrating: when comparing your solution to
Christophe Grands's (or other Clojure guru), on the other hand if you can
find a mate to compete with, this is a very cool emulation. (For example
me[denlab] and my friend [ardumont], in http://www.4clojure.com/users, I'm
in the top 79, he is in the top 88, booh! :-)

Have fun!

Denis



 Regards,
 Joe


 On Monday, July 23, 2012 10:53:56 AM UTC-5, Denis Labaye wrote:

 Hi,

 On Mon, Jul 23, 2012 at 5:38 PM, Joe Hughes jwhughe...@gmail.com wrote:

 All,

 I figured it out.  Still trying to get Functional Programming ideas
 in my head.


 The macro defspel is not functional programming, it's dark Lisp's macro
 Voodoo.

 I would not advise starting Clojure with macros, you should start with
 something with a smoother learning curve like: http://www.4clojure.com/**
 .

 That said, I red The Land Of Lisp before learning Clojure, and it's a
 great book.
 Transposing Common LISP to Clojure may not be a good idea though.

 My advice would be: If you want to learn Common Lisp before Clojure it's
 a great idea (you will enjoy Clojure much more :), but take the time to
 learn the language.
 If you want to directly learn Clojure, then take a good book (Clojure
 Programming - 2012, Practial Clojure - 2010 or Joy Of Clojure - 2011) +
 some practical work like 4clojure.com.

 Cheers,

 Denis



 Regards,
 Joe


 On Friday, June 29, 2012 11:11:56 AM UTC-5, Joe Hughes wrote:

 All,

 I've been playing with Clojure and found this website,
 http://www.lisperati.com/clojure-spels/casting.htmlhttp://www.lisperati.com/clojure-spels/casting.html
 .  Typed the code into Clojure 1.4.0 and got the issue below.
  Here is the code in question.


 (defmacro defspel [ rest] `(defmacro ~@rest))


 (defspel game-action [command subj obj place  args]
   `(defspel ~command [subject# object#]
  `(spel-print (cond (and (= location '~'~place)
  (= '~subject# '~'~subj)
  (= '~object# '~'~obj)
  (have? '~'~subj))
 ~@'~args
 :else '(i cannot ~'~command like that -)

 (game-action weld chain bucket attic
(cond (and (have? 'bucket) (def chain-welded true))
   '(the chain is now securely welded to the bucket -)
  :else '(you do not have a bucket -)))


 When I do


 (weld chain bucket)


 instead of getting


 (you do not have a chain -)


 I get


 (i cannot weld like that -)


 From what I'm reading (defspel game-action..., something isn't correct
 and the result is the :else instead of the if.  This was written using
 Clojure 1.1, so if anyone has a solution about why this works in 1.1 and
 not 1.4 I would like to hear it.


 TIA,
 Joe

  --
 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://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: contrib change suggestion, and volunteering

2012-07-23 Thread Sean Corfield
On Mon, Jul 23, 2012 at 12:06 AM, pjm pjm...@gmail.com wrote:
 Hello, everyone. I am a newbie, and have been trying to follow along on
 Clojure Notes, but it has been difficult due to the major change that in the
 way clojure.contrib works recently.

Yup, there are still a lot of outdated tutorials and material out
there which has not been updated from Clojure 1.2. It certainly didn't
help that Manning Books went ahead and released Clojure in Action -
based on Clojure 1.2 and the old monolithic contrib library - after
Clojure 1.3 was already released. The best we can do is keep asking
people who wrote old material to either update it or take it down.
Sounds like emails to satishtalim [at] gmail [dot] com are in order
for Clojure Notes since it even has links to the very old richhickey
github repo :(

 My suggestion is: can we minimize major changes like this.

This was a one-off change that was done early enough in Clojure's
evolution that the vast majority of Clojure developers - present and
future - wouldn't have to deal with it. Modulo getting outdated
tutorials updated, of course :)

 Also, it looks like you are calling for people to take care of individual
 modules in clojure.contrib on github, so I'm (reluctantly) volunteering,
 although if there are any problems, I'm not sure what I can do.

http://clojure.org/contributing is the first step.

Some of the justification for the reorg of contrib is here - but this
whole section of the wiki is good reading around contrib library care
and feeding:

http://dev.clojure.org/display/design/Better+infrastructure+for+contributed+libs
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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


Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Hello.

I did a naive simple benchmark of Haskell and Scala recently and now i 
decided to add Clojure to the picture. Here is the idea 
http://blog.worldcognition.com/2012/06/folding-tree-to-list-benchmark-scala-vs.html

So, I wrote the following functions:

(defn generate-tree [[h  t :as coll]]
  (if (seq coll)
(let [lr (generate-tree t)] [h lr lr])
nil))

(defn to-list [[v l r :as node]]
  (if-not (nil? node)
(concat
 (to-list l)
 (lazy-seq (cons v (to-list r
[]))

Now I get these results:

(def tree (generate-tree (range 1 21)))

(do (time (doall (to-list tree))) :done)
Elapsed time: 1681.75 msecs
:done

If I remove the 'lazy-seq' wrapping second 'concat' argument, things become 
worst:

(do (time (doall (to-list tree))) :done)
Elapsed time: 19716.222 msecs

Why is this so? Both results are kind of disappointing for me cause Scala 
gives me ~270ms time using functional code and 5x faster using the mutable 
one (on much slower machine).

-- 
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: Any downside of record compared to map

2012-07-23 Thread Ben Mabey

On 7/22/12 5:42 PM, Warren Lynn wrote:
I plan to change all my major data structures to records instead of 
plain maps. Since record has everything a map provides, I figure there 
won't be any harm. But is that really so? Would appreciate the 
opinions from people who know better.



Another downside I have ran into that hasn't been mentioned is with 
(Java) serialization.  If you are using records and defining protocols 
inline you can serialize the record just fine, however if you change the 
implementation then all of your old serialized records are incompatible 
even if the change was superficial.  The Java solution to this problem 
is to define a 'static final long serialVersionUID' however AFAIK there 
is no way to define this on a Clojure record.  (If someone knows better 
please let me know since loosing data after every protocol change is 
very annoying...) If you use multi-methods instead of protocols you 
won't run into this issue.


-Ben

--
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: Little becnhmark (need insight)

2012-07-23 Thread Sergey Didenko
Hi,

lazy seqs are slow for number crunching, you can try to remove them.

Then you can check that you make (set! *warn-on-reflection* true). And
that your code does not have the warnings.

Then may be use native (Java) data structures or even arrays.

Then you can change defn for definline for sensitive code.

Also see the thread can Clojure 1.3 code always be made as fast as
Java for numeric computations?

Sergey

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
I would guess you'd get closer to Scala's perf if you use records to
represent your trees, rather than vectors.

-- 
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: Any downside of record compared to map

2012-07-23 Thread Aravindh Johendran

On Monday, July 23, 2012 8:20:40 AM UTC-4, Lee wrote: 


 Considering that maps do have upsides compared to records in some cases 
 (as indicated, e.g., by Chas's flowchart), and that struct-maps add a 
 couple of handy features in the context of some uses of maps, can anybody 
 say why struct-maps are deprecated? 

  -Lee 

 
Are struct-maps really deprecated? I don't see a deprecation warning 
anywhere (clojure website, source, api, etc.). All I see is the following 
line in clojure website.
*--- Note: Most uses of StructMaps would now be better served by 
**records*http://clojure.org/datatypes
*.*
Is the use of struct-maps officially being discouraged? Is that the same as 
being almost deprecated? Will struct-maps go away in a future release?
 
 
 

-- 
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: Any downside of record compared to map

2012-07-23 Thread Phil Hagelberg
On Mon, Jul 23, 2012 at 11:59 AM, Ben Mabey b...@benmabey.com wrote:
 Another downside I have ran into that hasn't been mentioned is with (Java)
 serialization.  If you are using records and defining protocols inline you
 can serialize the record just fine, however if you change the implementation
 then all of your old serialized records are incompatible even if the change
 was superficial.

Another related downside is that during development, you'll reload
your defrecord forms, and each time you do so it creates a new class
that is visually indistinguishable from the last. Witness:

user (defrecord x [a b c])
user (def x1 (x. 1 2 3))
user (defrecord x [a b c])
user (def x2 (x. 1 2 3))
user (= x1 x2)
false

-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


Re: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Just tried it out: results are a little worse comparing to vectors (1.75s 
vs 1.68s).

On Monday, July 23, 2012 10:56:01 PM UTC+3, puzzler wrote:

 I would guess you'd get closer to Scala's perf if you use records to 
 represent your trees, rather than vectors.


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Thanks. But I don't do any number crunching here - just a huge structure 
creation in memory. I can't get why removing the 'lazy-seq' wrapper from 
the second 'concat' argument make things 10x times slower.

On Monday, July 23, 2012 10:40:51 PM UTC+3, Sergey Didenko wrote:

 Hi, 

 lazy seqs are slow for number crunching, you can try to remove them. 

 Then you can check that you make (set! *warn-on-reflection* true). And 
 that your code does not have the warnings. 

 Then may be use native (Java) data structures or even arrays. 

 Then you can change defn for definline for sensitive code. 

 Also see the thread can Clojure 1.3 code always be made as fast as 
 Java for numeric computations? 

 Sergey 


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Timothy Baldridge
 Thanks. But I don't do any number crunching here - just a huge structure
 creation in memory. I can't get why removing the 'lazy-seq' wrapper from the
 second 'concat' argument make things 10x times slower.

Lazy-seqs require the allocation of a LazySeq object. Due to the lazy
nature of this structure, we have to protect against multiple
evaluation. This means that certain methods have to be synchronized:
(https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java).
All that makes it quite a bit slower than a simple Iterator.


Timothy

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 2:58 PM, Alexander Semenov bohtva...@gmail.com wrote:

 (do (time (doall (to-list tree))) :done)
 Elapsed time: 19716.222 msecs

 Why is this so? Both results are kind of disappointing for me cause Scala
 gives me ~270ms time using functional code and 5x faster using the mutable
 one (on much slower machine).

The comparison doesn't really make sense as internally Scala's :::
uses ListBuffer.

http://github.com/scala/scala/blob/v2.9.2/src/library/scala/collection/immutable/List.scala#L107

David

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
I see. Just removed the lazyness and got ~800ms.

(defn generate-tree [[h  t :as coll]]
  (if (seq coll)
(let [lr (generate-tree t)] [h lr lr])
nil))

(defn to-list [[v l r :as node]]
  (if-not (nil? node)
(into
 (to-list l)
 (conj (to-list r) v))
[]))

On Monday, July 23, 2012 11:20:50 PM UTC+3, tbc++ wrote:

  Thanks. But I don't do any number crunching here - just a huge structure 
  creation in memory. I can't get why removing the 'lazy-seq' wrapper from 
 the 
  second 'concat' argument make things 10x times slower. 

 Lazy-seqs require the allocation of a LazySeq object. Due to the lazy 
 nature of this structure, we have to protect against multiple 
 evaluation. This means that certain methods have to be synchronized: 
 (
 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java).
  

 All that makes it quite a bit slower than a simple Iterator. 


 Timothy 


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Softaddicts
Did you try flatten ?

Luc P.


 Hello.
 
 I did a naive simple benchmark of Haskell and Scala recently and now i 
 decided to add Clojure to the picture. Here is the idea 
 http://blog.worldcognition.com/2012/06/folding-tree-to-list-benchmark-scala-vs.html
 
 So, I wrote the following functions:
 
 (defn generate-tree [[h  t :as coll]]
   (if (seq coll)
 (let [lr (generate-tree t)] [h lr lr])
 nil))
 
 (defn to-list [[v l r :as node]]
   (if-not (nil? node)
 (concat
  (to-list l)
  (lazy-seq (cons v (to-list r
 []))
 
 Now I get these results:
 
 (def tree (generate-tree (range 1 21)))
 
 (do (time (doall (to-list tree))) :done)
 Elapsed time: 1681.75 msecs
 :done
 
 If I remove the 'lazy-seq' wrapping second 'concat' argument, things become 
 worst:
 
 (do (time (doall (to-list tree))) :done)
 Elapsed time: 19716.222 msecs
 
 Why is this so? Both results are kind of disappointing for me cause Scala 
 gives me ~270ms time using functional code and 5x faster using the mutable 
 one (on much slower machine).
 
 -- 
 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
--
Softaddictslprefonta...@softaddicts.ca sent by ibisMail from my ipad!

-- 
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: is their a Clojure framework for handling form validation?

2012-07-23 Thread gaz jones
https://github.com/mikejones/mississippi

again, not specific to web forms. works on clojure maps and is extensible.

On Sun, Jul 22, 2012 at 6:46 PM, larry google groups
lawrencecloj...@gmail.com wrote:
 Since 2000 I've been doing web development, first with PHP and then with
 Ruby On Rails. In the world of PHP, there are some frameworks, such as
 Symfony, that have classes for managing forms, both generating the HTML for
 the forms, and also handling the validation of the forms. In the world of
 Python, the Django framework also has facilities for generating and
 validating forms. These frameworks offer certain time saving conveniences.
 For instance, with the Symfony framework, if you have a database table that
 has a foreign key, then you can get that other table (the target of the
 foreign key) to appear in a form as a pre-populated select box,
 automatically (after filling out some config files).

 I'm now trying to make Clojure my primary development language for
 everything, including web development. I'm curious, are there any libraries
 in the land of Clojure that offer similar conveniences for forms?

 --
 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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Yes, but these are implementation details - API is still functional and 
side-effects free.

On Monday, July 23, 2012 11:23:32 PM UTC+3, David Nolen wrote:

 On Mon, Jul 23, 2012 at 2:58 PM, Alexander Semenov wrote: 
  
  (do (time (doall (to-list tree))) :done) 
  Elapsed time: 19716.222 msecs 
  
  Why is this so? Both results are kind of disappointing for me cause 
 Scala 
  gives me ~270ms time using functional code and 5x faster using the 
 mutable 
  one (on much slower machine). 

 The comparison doesn't really make sense as internally Scala's ::: 
 uses ListBuffer. 


 http://github.com/scala/scala/blob/v2.9.2/src/library/scala/collection/immutable/List.scala#L107
  

 David 


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
It died with out of memory with a half a minute delay.

On Monday, July 23, 2012 11:30:19 PM UTC+3, Luc wrote:

 Did you try flatten ? 

 Luc P. 


  Hello. 
  
  I did a naive simple benchmark of Haskell and Scala recently and now i 
  decided to add Clojure to the picture. Here is the idea 
  
 http://blog.worldcognition.com/2012/06/folding-tree-to-list-benchmark-scala-vs.html
  
  
  So, I wrote the following functions: 
  
  (defn generate-tree [[h  t :as coll]] 
(if (seq coll) 
  (let [lr (generate-tree t)] [h lr lr]) 
  nil)) 
  
  (defn to-list [[v l r :as node]] 
(if-not (nil? node) 
  (concat 
   (to-list l) 
   (lazy-seq (cons v (to-list r 
  [])) 
  
  Now I get these results: 
  
  (def tree (generate-tree (range 1 21))) 
  
  (do (time (doall (to-list tree))) :done) 
  Elapsed time: 1681.75 msecs 
  :done 
  
  If I remove the 'lazy-seq' wrapping second 'concat' argument, things 
 become 
  worst: 
  
  (do (time (doall (to-list tree))) :done) 
  Elapsed time: 19716.222 msecs 
  
  Why is this so? Both results are kind of disappointing for me cause 
 Scala 
  gives me ~270ms time using functional code and 5x faster using the 
 mutable 
  one (on much slower machine). 
  


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
Hi,
With the new version without laziness, what exact test do you pass ?

Is it still (do (time (doall (to-list tree))) :done) ?

Because the doall adds an unfair re-traversal of the list, I think

2012/7/23 Alexander Semenov bohtva...@gmail.com

 I see. Just removed the lazyness and got ~800ms.


 (defn generate-tree [[h  t :as coll]]
   (if (seq coll)
 (let [lr (generate-tree t)] [h lr lr])
 nil))

 (defn to-list [[v l r :as node]]
   (if-not (nil? node)
 (into
  (to-list l)
  (conj (to-list r) v))
 []))


 On Monday, July 23, 2012 11:20:50 PM UTC+3, tbc++ wrote:

  Thanks. But I don't do any number crunching here - just a huge
 structure
  creation in memory. I can't get why removing the 'lazy-seq' wrapper
 from the
  second 'concat' argument make things 10x times slower.

 Lazy-seqs require the allocation of a LazySeq object. Due to the lazy
 nature of this structure, we have to protect against multiple
 evaluation. This means that certain methods have to be synchronized:
 (https://github.com/clojure/**clojure/blob/master/src/jvm/**
 clojure/lang/LazySeq.javahttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java).

 All that makes it quite a bit slower than a simple Iterator.


 Timothy

  --
 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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Oh yes, you're absolutely right. Now its 570 ms (just removed the 'doall').

On Monday, July 23, 2012 11:34:40 PM UTC+3, lpetit wrote:

 Hi, 
 With the new version without laziness, what exact test do you pass ?

 Is it still (do (time (doall (to-list tree))) :done) ?

 Because the doall adds an unfair re-traversal of the list, I think

 I see. Just removed the lazyness and got ~800ms.


 (defn generate-tree [[h  t :as coll]]
   (if (seq coll)
 (let [lr (generate-tree t)] [h lr lr])
 nil))

 (defn to-list [[v l r :as node]]
   (if-not (nil? node)
 (into
  (to-list l)
  (conj (to-list r) v))
 []))


 On Monday, July 23, 2012 11:20:50 PM UTC+3, tbc++ wrote:

  Thanks. But I don't do any number crunching here - just a huge 
 structure 
  creation in memory. I can't get why removing the 'lazy-seq' wrapper 
 from the 
  second 'concat' argument make things 10x times slower. 

 Lazy-seqs require the allocation of a LazySeq object. Due to the lazy 
 nature of this structure, we have to protect against multiple 
 evaluation. This means that certain methods have to be synchronized: 
 (https://github.com/clojure/**clojure/blob/master/src/jvm/**
 clojure/lang/LazySeq.javahttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java).
  

 All that makes it quite a bit slower than a simple Iterator. 


 Timothy 

 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: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 4:30 PM, Alexander Semenov bohtva...@gmail.com wrote:
 Yes, but these are implementation details - API is still functional and
 side-effects free.

So your benchmark is just timing implementation details.

I'm sure you can get get identical numbers to Scala / Haskell if you
provide your own ListBuffer implementation.

David

-- 
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: Any downside of record compared to map

2012-07-23 Thread Lee Spector

On Jul 23, 2012, at 4:06 PM, Aravindh Johendran wrote:

 Are struct-maps really deprecated? I don't see a deprecation warning anywhere 
 (clojure website, source, api, etc.). All I see is the following line in 
 clojure website.
 --- Note: Most uses of StructMaps would now be better served by records.
 Is the use of struct-maps officially being discouraged? Is that the same as 
 being almost deprecated? Will struct-maps go away in a future release?
  

There's also this:

Overall, records will be better than structmaps for all information-bearing 
purposes, and you should move such structmaps to defrecord. It is unlikely much 
code was trying to use structmaps for programming constructs, but if so, you 
will find deftype much more suitable.

from http://clojure.org/datatypes

FWIW there's also a comment on stackoverflow Michał Marczyk: in fact, the 
latter is deprecated in 1.2 
(http://stackoverflow.com/questions/4288360/clojures-macro-define-a-binding-whose-name-is-composed-from-an-argument).

I don't know if there's any more official statement anywhere. Myself, I really 
like struct-maps and I hope they stay around.

 -Lee

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
To some degree. Neither Clojure nor Haskell won't beat direct mutable code 
in Scala which results in 65ms on a machine 2x slower than my current.

On Monday, July 23, 2012 11:44:18 PM UTC+3, David Nolen wrote:

 So your benchmark is just timing implementation details. 

 I'm sure you can get get identical numbers to Scala / Haskell if you 
 provide your own ListBuffer implementation. 

 David 


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 4:52 PM, Alexander Semenov bohtva...@gmail.com wrote:
 To some degree. Neither Clojure nor Haskell won't beat direct mutable code
 in Scala which results in 65ms on a machine 2x slower than my current.

Direct mutable code can be written with little difficulty in Clojure.
It's just discouraged.

David

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/23 Alexander Semenov bohtva...@gmail.com

 Oh yes, you're absolutely right. Now its 570 ms (just removed the 'doall').


Does the timing stabilize to a lesser value if you execute it multiple
times (as they did in the scala test) :

(dotimes [ _ 10] (time (to-list tree)) :done)

?



 On Monday, July 23, 2012 11:34:40 PM UTC+3, lpetit wrote:

 Hi,
 With the new version without laziness, what exact test do you pass ?

 Is it still (do (time (doall (to-list tree))) :done) ?

 Because the doall adds an unfair re-traversal of the list, I think

 I see. Just removed the lazyness and got ~800ms.


 (defn generate-tree [[h  t :as coll]]
   (if (seq coll)
 (let [lr (generate-tree t)] [h lr lr])
 nil))

 (defn to-list [[v l r :as node]]
   (if-not (nil? node)
 (into
  (to-list l)
  (conj (to-list r) v))
 []))


 On Monday, July 23, 2012 11:20:50 PM UTC+3, tbc++ wrote:

  Thanks. But I don't do any number crunching here - just a huge
 structure
  creation in memory. I can't get why removing the 'lazy-seq' wrapper
 from the
  second 'concat' argument make things 10x times slower.

 Lazy-seqs require the allocation of a LazySeq object. Due to the lazy
 nature of this structure, we have to protect against multiple
 evaluation. This means that certain methods have to be synchronized:
 (https://github.com/clojure/**cl**ojure/blob/master/src/jvm/**cloj**
 ure/lang/LazySeq.javahttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java).

 All that makes it quite a bit slower than a simple Iterator.


 Timothy

 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: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
Here's what my code looks like, using records and removing pattern matching:

(defrecord Tree [h l r])

(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list [t]
  (if t
(into
  (conj (to-list (:l t)) (:h t))
  (to-list (:r t)))
[]))

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
No, the results are pretty the same (+-20ms).

In fact I tried using https://github.com/hugoduncan/criterium but it dies 
with 'out of memory' (:reduce-with option doesn't help), so I gave up.

On Monday, July 23, 2012 11:54:28 PM UTC+3, lpetit wrote:


 Does the timing stabilize to a lesser value if you execute it multiple 
 times (as they did in the scala test) : 

 (dotimes [ _ 10] (time (to-list tree)) :done)

 ?  


-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
Don't forget to use the -server flag.  Makes a big difference in the perf
of Clojure code.

-- 
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: Any downside of record compared to map

2012-07-23 Thread Warren Lynn

Thank everybody for the discussion. I am now aware of some pitfalls in 
using defrecord.

For me, I like to have type information associated with my data. I still 
prefer defrecord over map in general, but I will proceed with more caution. 
I think some pitfalls here are not due to the greatness of regular map, but 
is because record is not yet so great (e.x. Python has no problem 
serializing typed data). But still, with current state of things, those 
downsides are real.

By the way, it seems record is not necessarily slower than map in map 
operations. Here is my test result:

(defrecord myrec [a b])
(def rec (myrec. 1 2))
(def m {:a 1 :b 2})


user= (time (dotimes [x 1000] (assoc m :a 4)))
Elapsed time: 2499.155478 msecs

user= (time (dotimes [x 1000] (assoc rec :a 4)))
Elapsed time: 802.191248 msecs

But I did not test other operations.

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Yes, I tried pretty the same and it gives same timings as without records. 
BTW, I noticed that destructuring brings some little overhead (~50ms).

On Monday, July 23, 2012 11:59:34 PM UTC+3, puzzler wrote:

 Here's what my code looks like, using records and removing pattern 
 matching:

 (defrecord Tree [h l r])

 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))] 
   (Tree. (first s) lr lr

 (defn to-list [t]
   (if t
 (into
   (conj (to-list (:l t)) (:h t))
   (to-list (:r t)))
 []))



-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
Hm, currently I run those functions from inside SLIME repl session in emacs 
and I have no idea whereas it starts clojure with that flag. Let me see...

On Tuesday, July 24, 2012 12:00:23 AM UTC+3, puzzler wrote:

 Don't forget to use the -server flag.  Makes a big difference in the perf 
 of Clojure code.



-- 
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: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
(deftype Tree [n l r]
  clojure.lang.Indexed
  (nth [this idx]
(nth this idx nil))
  (nth [_ idx not-found]
(case idx
  0 n
  1 l
  2 r
  not-found)))

(defn generate-tree [[h  t :as coll]]
  (when (seq coll)
(let [lr (generate-tree t)] (Tree. h lr lr

(defn to-list
  ([node] (persistent! (to-list node (transient []
  ([[v l r :as node] acc]
 (if-not (nil? node)
   (let [lacc (to-list l acc)
 _   (conj! lacc v)
 racc (to-list r lacc)]
 racc)
   acc)))

(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 5]
 (time
  (dotimes [_ 1]
(count (to-list t))

Takes ~53ms on my machine.

David

On Mon, Jul 23, 2012 at 5:00 PM, Alexander Semenov bohtva...@gmail.com wrote:
 No, the results are pretty the same (+-20ms).

 In fact I tried using https://github.com/hugoduncan/criterium but it dies
 with 'out of memory' (:reduce-with option doesn't help), so I gave up.


 On Monday, July 23, 2012 11:54:28 PM UTC+3, lpetit wrote:


 Does the timing stabilize to a lesser value if you execute it multiple
 times (as they did in the scala test) :

 (dotimes [ _ 10] (time (to-list tree)) :done)

 ?

 --
 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: Little becnhmark (need insight)

2012-07-23 Thread David Nolen
(defn to-list
  ([node] (persistent! (to-list node (transient []
  ([[v l r :as node] acc]
 (if-not (nil? node)
   (let [lacc (to-list l acc)
 vacc  (conj! lacc v)
 racc (to-list r vacc)]
 racc)
   acc)))

There was a mistake in my to-list. Timings have not changed.

On Mon, Jul 23, 2012 at 5:07 PM, David Nolen dnolen.li...@gmail.com wrote:
 (deftype Tree [n l r]
   clojure.lang.Indexed
   (nth [this idx]
 (nth this idx nil))
   (nth [_ idx not-found]
 (case idx
   0 n
   1 l
   2 r
   not-found)))

 (defn generate-tree [[h  t :as coll]]
   (when (seq coll)
 (let [lr (generate-tree t)] (Tree. h lr lr

 (defn to-list
   ([node] (persistent! (to-list node (transient []
   ([[v l r :as node] acc]
  (if-not (nil? node)
(let [lacc (to-list l acc)
  _   (conj! lacc v)
  racc (to-list r lacc)]
  racc)
acc)))

 (defn tree [n]
   (generate-tree (range 1 n)))

 (let [t (tree 21)]
(dotimes [_ 5]
  (time
   (dotimes [_ 1]
 (count (to-list t))

 Takes ~53ms on my machine.

 David

 On Mon, Jul 23, 2012 at 5:00 PM, Alexander Semenov bohtva...@gmail.com 
 wrote:
 No, the results are pretty the same (+-20ms).

 In fact I tried using https://github.com/hugoduncan/criterium but it dies
 with 'out of memory' (:reduce-with option doesn't help), so I gave up.


 On Monday, July 23, 2012 11:54:28 PM UTC+3, lpetit wrote:


 Does the timing stabilize to a lesser value if you execute it multiple
 times (as they did in the scala test) :

 (dotimes [ _ 10] (time (to-list tree)) :done)

 ?

 --
 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: Little becnhmark (need insight)

2012-07-23 Thread Alexander Semenov
And ~44ms on mine. Impressive! Will study your code tomorrow, thanks.

On Tuesday, July 24, 2012 12:07:59 AM UTC+3, David Nolen wrote:

 (deftype Tree [n l r] 
   clojure.lang.Indexed 
   (nth [this idx] 
 (nth this idx nil)) 
   (nth [_ idx not-found] 
 (case idx 
   0 n 
   1 l 
   2 r 
   not-found))) 

 (defn generate-tree [[h  t :as coll]] 
   (when (seq coll) 
 (let [lr (generate-tree t)] (Tree. h lr lr 

 (defn to-list 
   ([node] (persistent! (to-list node (transient [] 
   ([[v l r :as node] acc] 
  (if-not (nil? node) 
(let [lacc (to-list l acc) 
  _   (conj! lacc v) 
  racc (to-list r lacc)] 
  racc) 
acc))) 

 (defn tree [n] 
   (generate-tree (range 1 n))) 

 (let [t (tree 21)] 
(dotimes [_ 5] 
  (time 
   (dotimes [_ 1] 
 (count (to-list t)) 

 Takes ~53ms on my machine. 

 David


-- 
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: [ANN] jenkins-leiningen

2012-07-23 Thread Phil Hagelberg
On Wed, Jul 18, 2012 at 7:23 AM, Pierre-Yves Ritschard p...@spootnik.org 
wrote:
 I wanted this for a while so here goes:
 https://github.com/pyr/jenkins-leiningen.
 It is very simplistic and inspired from the sbt one.

This is great. Could you add it to the Leiningen wiki?

https://github.com/technomancy/leiningen/wiki

Thanks!

-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


Re: Little becnhmark (need insight)

2012-07-23 Thread Mark Engelberg
As David was posting his code, I was wrapping up my own experimentation
with how transients apply here.  Mine is similar, but doesn't use pattern
matching -- seems a bit faster:

(defrecord Tree [h l r])

(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list
  ([t] (persistent! (to-list t (transient []
  ([t b]
(if t
  (let [b (to-list (:l t) b),
b (conj! b (:h t)),
b (to-list (:r t) b)]
  b)
  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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/23 Mark Engelberg mark.engelb...@gmail.com

 As David was posting his code, I was wrapping up my own experimentation
 with how transients apply here.  Mine is similar, but doesn't use pattern
 matching -- seems a bit faster:


 (defrecord Tree [h l r])

 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   (Tree. (first s) lr lr

 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (:l t) b),
 b (conj! b (:h t)),
 b (to-list (:r t) b)]
   b)
   b)))


True,

and notice you can also drop records altogether:

(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  [(first s) lr lr])))

(defn to-list
  ([t] (persistent! (to-list t (transient []
  ([t b]
(if t
  (let [b (to-list (t 1) b),
b (conj! b (t 0)),
b (to-list (t 2) b)]
  b)
  b)))
(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 10]
 (time
  (dotimes [_ 1]
(println (count (to-list t)))

1048575
Elapsed time: 346.446 msecs
1048575
Elapsed time: 37.2 msecs
1048575
Elapsed time: 32.795 msecs
1048575
Elapsed time: 31.655 msecs
1048575
Elapsed time: 45.388 msecs
1048575
Elapsed time: 30.612 msecs
1048575
Elapsed time: 27.141 msecs
1048575
Elapsed time: 40.887 msecs
1048575
Elapsed time: 27.526 msecs
1048575
Elapsed time: 26.747 msecs
nil

-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
Oh, and finally, note that even without transients, you get 6x better perf
by not calling into directly:

= (defrecord Tree [h l r])

   (defn generate-tree [c]
 (when-let [s (seq c)]
   (let [lr (generate-tree (rest s))]
 (Tree. (first s) lr lr

   (defn to-list
 ([t] (to-list t []))
 ([t b]
   (if t
 (let [b (to-list (:l t) b),
   b (conj b (:h t)),
   b (to-list (:r t) b)]
 b)
 b)))
   (defn tree [n]
 (generate-tree (range 1 n)))

   (let [t (tree 21)]
  (dotimes [_ 10]
(time
 (dotimes [_ 1]
   (println (count (to-list t)))
user.Tree
#'user/generate-tree
#'user/to-list
#'user/tree
1048575
Elapsed time: 174.14 msecs
1048575
Elapsed time: 124.218 msecs
1048575
Elapsed time: 130.186 msecs
1048575
Elapsed time: 109.883 msecs
1048575
Elapsed time: 104.221 msecs
1048575
Elapsed time: 98.387 msecs
1048575
Elapsed time: 98.21 msecs
1048575
Elapsed time: 103.543 msecs
1048575
Elapsed time: 98.663 msecs
1048575
Elapsed time: 101.913 msecs
nil
= (defrecord Tree [h l r])

   (defn generate-tree [c]
 (when-let [s (seq c)]
   (let [lr (generate-tree (rest s))]
 (Tree. (first s) lr lr

   (defn to-list
 ([t] (to-list t []))
 ([t b]
   (if t
 (into (conj (to-list (:l t) b) (:h t)) (to-list (:r t) b))
 b)))
   (defn tree [n]
 (generate-tree (range 1 n)))

   (let [t (tree 21)]
  (dotimes [_ 10]
(time
 (dotimes [_ 1]
   (println (count (to-list t)))
user.Tree
#'user/generate-tree
#'user/to-list
#'user/tree
1048575
Elapsed time: 1149.562 msecs
1048575
Elapsed time: 846.225 msecs
1048575
Elapsed time: 605.007 msecs
1048575
Elapsed time: 604.409 msecs
1048575
Elapsed time: 625.605 msecs
1048575
Elapsed time: 626.066 msecs
1048575
Elapsed time: 605.502 msecs
1048575
Elapsed time: 621.007 msecs
1048575
Elapsed time: 606.064 msecs
1048575
Elapsed time: 642.739 msecs
nil

2012/7/23 Laurent PETIT laurent.pe...@gmail.com

 2012/7/23 Mark Engelberg mark.engelb...@gmail.com

 As David was posting his code, I was wrapping up my own experimentation
 with how transients apply here.  Mine is similar, but doesn't use pattern
 matching -- seems a bit faster:


 (defrecord Tree [h l r])

 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   (Tree. (first s) lr lr

 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (:l t) b),
 b (conj! b (:h t)),
 b (to-list (:r t) b)]
   b)
   b)))


 True,

 and notice you can also drop records altogether:


 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   [(first s) lr lr])))


 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (t 1) b),
 b (conj! b (t 0)),
 b (to-list (t 2) b)]
   b)
   b)))

 (defn tree [n]
   (generate-tree (range 1 n)))

 (let [t (tree 21)]
(dotimes [_ 10]
  (time
   (dotimes [_ 1]
 (println (count (to-list t)))

 1048575
 Elapsed time: 346.446 msecs
 1048575
 Elapsed time: 37.2 msecs
 1048575
 Elapsed time: 32.795 msecs
 1048575
 Elapsed time: 31.655 msecs
 1048575
 Elapsed time: 45.388 msecs
 1048575
 Elapsed time: 30.612 msecs
 1048575
 Elapsed time: 27.141 msecs
 1048575
 Elapsed time: 40.887 msecs
 1048575
 Elapsed time: 27.526 msecs
 1048575
 Elapsed time: 26.747 msecs
 nil


-- 
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

Logger conflicts

2012-07-23 Thread Eric in San Diego
I'm in the process of upgrading some oldish code, and I'm encountering some 
compatibility problems with the loggers required by various libraries.

See the *appendix* below for my project.clj, which loads a number of 
libraries and to which I've recently added statements like this:

 [com.hp.hpl.jena/jena 2.6.4
  :exclusions [org.slf4j/slf4j-log4j12
   org.slf4j/slf4j-api
   ]
  ]

I added these exclusions to turn off this error:

java.lang.NoSuchMethodError: 
org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V


Which I gather from reading things like this:

http://stackoverflow.com/questions/3519978/logging-framework-incompatibility

- stem from incompatible logging libraries.

Excluding these dependencies  seems to turn off this error, but now when I 
try load my code, I'm getting this error:

org.slf4j.LoggerFactory
  [Thrown class java.lang.ClassNotFoundException]

See the appendix for a stack trace.

I'm including org.clojure/tools.logging in the project.clj, but it's not 
clear to me how to keep the logger associated with my 'jena' library happy 
without re-introducing my compatibility error.

Up to this point, my logging has 'just worked', so I guess this is an 
opportunity to learn about this stuff. Is there a good way to deal with the 
fact that different supporting libraries will use different logging regimes?

Thanks for any help.


* appendix *

(defproject MyProject 1.0.0-SNAPSHOT

  :jvm-opts [-Xmx8g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseSerialGC]


  :dependencies [[org.clojure/clojure 1.3.0]
 [org.clojure/math.numeric-tower 0.0.1]
 [org.clojure/tools.trace 0.7.1]
 [org.clojure/tools.logging 0.2.3]
 [org.clojure/algo.generic 0.1.0]
 [clojure-csv 1.3.2] 
 ;;statistics...
 [incanter/incanter-core 1.3.0-SNAPSHOT] 
 [incanter/incanter-charts 1.3.0-SNAPSHOT]
 [incanter/incanter-processing 1.3.0-SNAPSHOT]

 ;;web
 [compojure 1.1.1]
 [hiccup 1.0.0]
 [ring 1.1.1]

 ;;jena ...
 [com.hp.hpl.jena/jena 2.6.4
  :exclusions [org.slf4j/slf4j-log4j12
   org.slf4j/slf4j-api
   ]
  ]
 ;;TDB 
 [com.hp.hpl.jena/arq 2.8.8
  :exclusions [org.slf4j/slf4j-api]
  ]
 [com.hp.hpl.jena/iri 0.8]
 [com.ibm.icu/icu4j 3.4.4]
 [com.hp.hpl.jena/tdb 0.8.10
  :exclusions [org.slf4j/slf4j-api]
  ]
 ;;lucene
 [org.apache.lucene/lucene-core 2.3.1]
  ]
  :dev-dependencies [
   [swank-clojure 1.3.2 
:exclusions [org.clojure/clojure]]
 [lein-autodoc 0.9.0]
   
   ]
 
)

-- stack trace:

org.slf4j.LoggerFactory
  [Thrown class java.lang.ClassNotFoundException]
Backtrace:
  0: java.net.URLClassLoader$1.run(URLClassLoader.java:217)
  1: java.security.AccessController.doPrivileged(Native Method)
  2: java.net.URLClassLoader.findClass(URLClassLoader.java:205)
  3: java.lang.ClassLoader.loadClass(ClassLoader.java:321)
  4: sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
  5: java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  6: com.hp.hpl.jena.util.Metadata.clinit(Metadata.java:26)
  7: com.hp.hpl.jena.JenaRuntime.clinit(JenaRuntime.java:25)
  8: 
com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.clinit(RDFReaderFImpl.java:85)
  9: com.hp.hpl.jena.rdf.model.impl.ModelCom.clinit(ModelCom.java:42)



-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
And I guess it is so because into, being called numerous times, keeps
transforming bigger and bigger vectors into transient vectors, and back to
persistent vectors, etc.

2012/7/24 Laurent PETIT laurent.pe...@gmail.com

 Oh, and finally, note that even without transients, you get 6x better perf
 by not calling into directly:

 = (defrecord Tree [h l r])


(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list
  ([t] (to-list t []))

  ([t b]
(if t
  (let [b (to-list (:l t) b),
b (conj b (:h t)),

b (to-list (:r t) b)]
  b)
  b)))
(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 10]
 (time
  (dotimes [_ 1]
(println (count (to-list t)))
  user.Tree
 #'user/generate-tree
 #'user/to-list
 #'user/tree
 1048575
 Elapsed time: 174.14 msecs
 1048575
 Elapsed time: 124.218 msecs
 1048575
 Elapsed time: 130.186 msecs
 1048575
 Elapsed time: 109.883 msecs
 1048575
 Elapsed time: 104.221 msecs
 1048575
 Elapsed time: 98.387 msecs
 1048575
 Elapsed time: 98.21 msecs
 1048575
 Elapsed time: 103.543 msecs
 1048575
 Elapsed time: 98.663 msecs
 1048575
 Elapsed time: 101.913 msecs
 nil
 = (defrecord Tree [h l r])


(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list
  ([t] (to-list t []))

  ([t b]
(if t
  (into (conj (to-list (:l t) b) (:h t)) (to-list (:r t) b))

  b)))
(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 10]
 (time
  (dotimes [_ 1]
(println (count (to-list t)))
  user.Tree
 #'user/generate-tree
 #'user/to-list
 #'user/tree
 1048575
 Elapsed time: 1149.562 msecs
 1048575
 Elapsed time: 846.225 msecs
 1048575
 Elapsed time: 605.007 msecs
 1048575
 Elapsed time: 604.409 msecs
 1048575
 Elapsed time: 625.605 msecs
 1048575
 Elapsed time: 626.066 msecs
 1048575
 Elapsed time: 605.502 msecs
 1048575
 Elapsed time: 621.007 msecs
 1048575
 Elapsed time: 606.064 msecs
 1048575
 Elapsed time: 642.739 msecs
 nil


 2012/7/23 Laurent PETIT laurent.pe...@gmail.com

 2012/7/23 Mark Engelberg mark.engelb...@gmail.com

 As David was posting his code, I was wrapping up my own experimentation
 with how transients apply here.  Mine is similar, but doesn't use pattern
 matching -- seems a bit faster:


 (defrecord Tree [h l r])

 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   (Tree. (first s) lr lr

 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (:l t) b),
 b (conj! b (:h t)),
 b (to-list (:r t) b)]
   b)
   b)))


 True,

 and notice you can also drop records altogether:


 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   [(first s) lr lr])))


 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (t 1) b),
 b (conj! b (t 0)),
 b (to-list (t 2) b)]
   b)
   b)))

 (defn tree [n]
   (generate-tree (range 1 n)))

 (let [t (tree 21)]
(dotimes [_ 10]
  (time
   (dotimes [_ 1]
 (println (count (to-list t)))

 1048575
 Elapsed time: 346.446 msecs
 1048575
 Elapsed time: 37.2 msecs
 1048575
 Elapsed time: 32.795 msecs
 1048575
 Elapsed time: 31.655 msecs
 1048575
 Elapsed time: 45.388 msecs
 1048575
 Elapsed time: 30.612 msecs
 1048575
 Elapsed time: 27.141 msecs
 1048575
 Elapsed time: 40.887 msecs
 1048575
 Elapsed time: 27.526 msecs
 1048575
 Elapsed time: 26.747 msecs
 nil




-- 
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: Little becnhmark (need insight)

2012-07-23 Thread Laurent PETIT
2012/7/24 Laurent PETIT laurent.pe...@gmail.com

 And I guess it is so because into, being called numerous times, keeps
 transforming bigger and bigger vectors into transient vectors, and back to
 persistent vectors, etc.


Answering to self: I was wrong, problem does not seem to be with internal
use of transients inside into, since removing them makes things worse:

= (defn my-into
 Returns a new coll consisting of to-coll with all of the items of
 from-coll conjoined.
 {:added 1.0
  :static true}
 [to from]
 (reduce conj to from))

   (defrecord Tree [h l r])

   (defn generate-tree [c]
 (when-let [s (seq c)]
   (let [lr (generate-tree (rest s))]
 (Tree. (first s) lr lr

   (defn to-list
 ([t] (to-list t []))
 ([t b]
   (if t
 (my-into (conj (to-list (:l t) b) (:h t)) (to-list (:r t) b))
 b)))
   (defn tree [n]
 (generate-tree (range 1 n)))

   (let [t (tree 21)]
  (dotimes [_ 10]
(time
 (dotimes [_ 1]
   (println (count (to-list t)))
#'user/my-into
user.Tree
#'user/generate-tree
#'user/to-list
#'user/tree
1048575
Elapsed time: 1121.971 msecs
1048575
Elapsed time: 969.479 msecs
1048575
Elapsed time: 991.333 msecs
1048575
Elapsed time: 940.975 msecs
1048575
Elapsed time: 956.785 msecs
1048575
Elapsed time: 1007.633 msecs
1048575
Elapsed time: 984.384 msecs
1048575
Elapsed time: 965.166 msecs
1048575
Elapsed time: 955.469 msecs
1048575
Elapsed time: 963.43 msecs
nil




 2012/7/24 Laurent PETIT laurent.pe...@gmail.com

 Oh, and finally, note that even without transients, you get 6x better
 perf by not calling into directly:

 = (defrecord Tree [h l r])


(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list
  ([t] (to-list t []))

  ([t b]
(if t
  (let [b (to-list (:l t) b),
b (conj b (:h t)),

b (to-list (:r t) b)]
  b)
  b)))
(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 10]
 (time
  (dotimes [_ 1]
(println (count (to-list t)))
  user.Tree
 #'user/generate-tree
 #'user/to-list
 #'user/tree
 1048575
 Elapsed time: 174.14 msecs
 1048575
 Elapsed time: 124.218 msecs
 1048575
 Elapsed time: 130.186 msecs
 1048575
 Elapsed time: 109.883 msecs
 1048575
 Elapsed time: 104.221 msecs
 1048575
 Elapsed time: 98.387 msecs
 1048575
 Elapsed time: 98.21 msecs
 1048575
 Elapsed time: 103.543 msecs
 1048575
 Elapsed time: 98.663 msecs
 1048575
 Elapsed time: 101.913 msecs
 nil
 = (defrecord Tree [h l r])


(defn generate-tree [c]
  (when-let [s (seq c)]
(let [lr (generate-tree (rest s))]
  (Tree. (first s) lr lr

(defn to-list
  ([t] (to-list t []))

  ([t b]
(if t
  (into (conj (to-list (:l t) b) (:h t)) (to-list (:r t) b))

  b)))
(defn tree [n]
  (generate-tree (range 1 n)))

(let [t (tree 21)]
   (dotimes [_ 10]
 (time
  (dotimes [_ 1]
(println (count (to-list t)))
  user.Tree
 #'user/generate-tree
 #'user/to-list
 #'user/tree
 1048575
 Elapsed time: 1149.562 msecs
 1048575
 Elapsed time: 846.225 msecs
 1048575
 Elapsed time: 605.007 msecs
 1048575
 Elapsed time: 604.409 msecs
 1048575
 Elapsed time: 625.605 msecs
 1048575
 Elapsed time: 626.066 msecs
 1048575
 Elapsed time: 605.502 msecs
 1048575
 Elapsed time: 621.007 msecs
 1048575
 Elapsed time: 606.064 msecs
 1048575
 Elapsed time: 642.739 msecs
 nil


 2012/7/23 Laurent PETIT laurent.pe...@gmail.com

 2012/7/23 Mark Engelberg mark.engelb...@gmail.com

 As David was posting his code, I was wrapping up my own experimentation
 with how transients apply here.  Mine is similar, but doesn't use pattern
 matching -- seems a bit faster:


 (defrecord Tree [h l r])

 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   (Tree. (first s) lr lr

 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (:l t) b),
 b (conj! b (:h t)),
 b (to-list (:r t) b)]
   b)
   b)))


 True,

 and notice you can also drop records altogether:


 (defn generate-tree [c]
   (when-let [s (seq c)]
 (let [lr (generate-tree (rest s))]
   [(first s) lr lr])))


 (defn to-list
   ([t] (persistent! (to-list t (transient []
   ([t b]
 (if t
   (let [b (to-list (t 1) b),
 b (conj! b (t 0)),
 b (to-list (t 2) b)]
   b)
   b)))

 (defn tree [n]
   (generate-tree (range 1 n)))

 (let [t (tree 21)]
(dotimes [_ 10]
  (time
   (dotimes [_ 1]
 (println (count (to-list t)))

 1048575
 Elapsed time: 346.446 msecs
 1048575
 Elapsed time: 37.2 msecs
 1048575
 Elapsed time: 32.795 msecs
 1048575
 Elapsed 

core.match invert match

2012-07-23 Thread Simone Mosciatti
Hi everybody,
I was looking if it is possible to invert the match macro, an example worth 
more than 1000 words.

(def x (match [a b]
   [true true] 0.5
   [false true] 0.6
   [true false] 0.4
   [false false] 0.8))

(max x)
= [false false]
(filter odd? x)
= [true true]

It is possible ?

I am definitely not an expert but it looks like a core.logic task, doesn't ?

-- 
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: core.match invert match

2012-07-23 Thread David Nolen
On Mon, Jul 23, 2012 at 6:42 PM, Simone Mosciatti mweb@gmail.com wrote:
 Hi everybody,
 I was looking if it is possible to invert the match macro, an example worth
 more than 1000 words.

 (def x (match [a b]
[true true] 0.5
[false true] 0.6
[true false] 0.4
[false false] 0.8))

 (max x)
 = [false false]
 (filter odd? x)
 = [true true]

 It is possible ?

 I am definitely not an expert but it looks like a core.logic task, doesn't ?

If you want to go in both directions yes - core.logic is more suitable.

David

-- 
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: Clojurians in Pune

2012-07-23 Thread Aniruddh Joshi
+1

On Tuesday, 17 July 2012 15:45:39 UTC+5:30, Murtaza Husain wrote:

 Hi,

 Anyone interested in organizing a clojure dojo in Pune ?

 Thanks,
 Murtaza


On Tuesday, 17 July 2012 15:45:39 UTC+5:30, Murtaza Husain wrote:

 Hi,

 Anyone interested in organizing a clojure dojo in Pune ?

 Thanks,
 Murtaza


On Tuesday, 17 July 2012 15:45:39 UTC+5:30, Murtaza Husain wrote:

 Hi,

 Anyone interested in organizing a clojure dojo in Pune ?

 Thanks,
 Murtaza


On Tuesday, 17 July 2012 15:45:39 UTC+5:30, Murtaza Husain wrote:

 Hi,

 Anyone interested in organizing a clojure dojo in Pune ?

 Thanks,
 Murtaza


-- 
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: is their a Clojure framework for handling form validation?

2012-07-23 Thread Robert Marianski
Form validation:

https://github.com/joodie/clj-decline
https://github.com/joodie/pretzel

Form generation:

https://github.com/joodie/flutter

Robert

On Mon, Jul 23, 2012 at 03:30:21PM -0500, gaz jones wrote:
 https://github.com/mikejones/mississippi
 
 again, not specific to web forms. works on clojure maps and is extensible.
 
 On Sun, Jul 22, 2012 at 6:46 PM, larry google groups
 lawrencecloj...@gmail.com wrote:
  Since 2000 I've been doing web development, first with PHP and then with
  Ruby On Rails. In the world of PHP, there are some frameworks, such as
  Symfony, that have classes for managing forms, both generating the HTML for
  the forms, and also handling the validation of the forms. In the world of
  Python, the Django framework also has facilities for generating and
  validating forms. These frameworks offer certain time saving conveniences.
  For instance, with the Symfony framework, if you have a database table that
  has a foreign key, then you can get that other table (the target of the
  foreign key) to appear in a form as a pre-populated select box,
  automatically (after filling out some config files).
 
  I'm now trying to make Clojure my primary development language for
  everything, including web development. I'm curious, are there any libraries
  in the land of Clojure that offer similar conveniences for forms?
 
  --
  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: Any downside of record compared to map

2012-07-23 Thread Sean Corfield
On Mon, Jul 23, 2012 at 1:47 PM, Lee Spector lspec...@hampshire.edu wrote:
 On Jul 23, 2012, at 4:06 PM, Aravindh Johendran wrote:
 Are struct-maps really deprecated?

It's a good question.

Christophe Grand thinks they're half deprecated here:
http://www.adrianmouat.com/bit-bucket/2011/02/common-lisp-clojure-and-evolution/#comment-3932

Brian Carper expected them to be deprecated back in mid-2010 here:
http://stackoverflow.com/questions/2994618/in-clojure-how-do-i-access-keys-in-a-vector-of-structs#comment3062840_2994618

Sam Aaron thought they were deprecated in Clojure 1.2 here:
http://www.pawfal.org/dave/blog/2011/01/clojure-frustrations/comment-page-1/#comment-250

Andrew Brehaut thought they were due to be deprecated in 1.2 here:
http://brehaut.net/blog/2010/a_couple_of_lists

Alex Miller considers them deprecated here:
http://stackoverflow.com/questions/4575170/where-should-i-use-defrecord-in-clojure

Stuart Sierra says they should probably be considered deprecated
here: http://comments.gmane.org/gmane.comp.java.clojure.user/52628

Clojure Programming (Grand, Carper, Emerick) says Clojure retains a
vestigial “struct” map implementation—via the def struct,
create-struct, struct-map, and struct functions—that should be
considered deprecated at this point, and avoided. on page 272.

Another reference to them being deprecated back in Clojure 1.2:
http://faustus.webatu.com/clj-quick-ref.html

But I agree it's hard to find an official statement of deprecation anywhere.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.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


how can a become *agent* in this code?

2012-07-23 Thread larry google groups

I am confused by this blog post:

http://www.bestinclass.dk/index.clj/2009/09/php-vs-clojure-what-does-it-cost-to-be-old-school.html

In particular, I am confuse by this function:

(defn log-dumper
  [a]
  (Thread/sleep *write-delay*)
  (let [sql-statements  (let [tmp @*sql-buffer*]
  (ref-set *sql-buffer* [])
   tmp)]
(doseq [stmt sql-statements]
  (run *mysql-connection* stmt))
(send-off *agent* log-dumper)))


It looks like a is being passed in as an argument to the function. But at 
the end of the function, *agent* is being passed into the function again. I 
don't see a point in this function where a is magically transformed into 
*agent*. I'm under the impression that this same agent is suppose to be 
sent, over and over again, every 5 minutes, for all eternity, into the 
function. But if the function is suppose to send the same agent to itself, 
5 minutes in the future, then I would think that if the argument is named 
a then a is what would be send-off to the function again. 

The blog post says:

send-off myself (the *agent* is the thread) to the same function again, 
ie. keep running.

How does this work? How does the final line know that *agent* is the a 
that was passed in as an argument? 





-- 
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 do you determine terminal/console width in `lein repl`?

2012-07-23 Thread Gabriel Horner
With some pointers from 
Colin, https://github.com/trptcolin/reply/issues/75, I was able to find a 
workable solution using stty:

user= (- (clojure.java.shell/sh /bin/sh -c stty -a  /dev/tty) 
:out (re-find #(\d+) columns) second)
238

As for the $COLUMNS dilemma, it seems that's a java-specific issue - 
http://stackoverflow.com/a/1286677/83510.
I'm curious why `tput cols` doesn't work but that's for another day.


On Monday, July 23, 2012 12:01:17 PM UTC-4, Gabriel Horner wrote:

 Hi,

 For a clojar I'm writing http://github.com/cldwalker/table, I'd like to 
 know a user's terminal width so I can resize output appropriately. All the 
 following techniques, which work fine in a ruby repl, don't work in 
 leiningen2:

 $ lein repl
 user= (System/getenv COLUMNS)
 nil

 user= (clojure.java.shell/sh tput cols)
 {:exit 0, :out 80\n, :err }
 ; This is incorrect as my terminal width is 238

 user= (clojure.java.shell/sh stty size)
 {:exit 1, :out , :err stty: stdin isn't a terminal\n}

 The only thing that does work is if I `export COLUMNS`, something I don't 
 have to do for a ruby repl. Thoughts on why none of these approaches work 
 and what a correct one would be?

 Thanks,
 Gabriel



-- 
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: reduction to tail recursion

2012-07-23 Thread Christian Mueller
No, not any recursion can be expressed as a  tail recursion. One example: 
the Ackermann function (http://en.wikipedia.org/wiki/Ackermann_function)

On Saturday, July 21, 2012 11:15:33 AM UTC+2, Mimmo Cosenza wrote:

 Hi,
 a very basic question. Any not tail recursion code can be reduced to 
 tail recursion code? 

 Thanks

 Mimmo


-- 
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 can a become *agent* in this code?

2012-07-23 Thread Philip Potter
a is the current value of the agent. *agent* is the agent itself.

Remember the universal update mechanism: an agent, atom or ref is updated
by applying a (normally) pure function to it; the function takes the
current state and returns the new state.

Phil
On Jul 24, 2012 5:16 AM, larry google groups lawrencecloj...@gmail.com
wrote:


 I am confused by this blog post:


 http://www.bestinclass.dk/index.clj/2009/09/php-vs-clojure-what-does-it-cost-to-be-old-school.html

 In particular, I am confuse by this function:

 (defn log-dumper
   [a]
   (Thread/sleep *write-delay*)
   (let [sql-statements  (let [tmp @*sql-buffer*]
   (ref-set *sql-buffer* [])
tmp)]
 (doseq [stmt sql-statements]
   (run *mysql-connection* stmt))
 (send-off *agent* log-dumper)))


 It looks like a is being passed in as an argument to the function. But
 at the end of the function, *agent* is being passed into the function
 again. I don't see a point in this function where a is magically
 transformed into *agent*. I'm under the impression that this same agent is
 suppose to be sent, over and over again, every 5 minutes, for all eternity,
 into the function. But if the function is suppose to send the same agent to
 itself, 5 minutes in the future, then I would think that if the argument is
 named a then a is what would be send-off to the function again.

 The blog post says:

 send-off myself (the *agent* is the thread) to the same function
 again, ie. keep running.

 How does this work? How does the final line know that *agent* is the a
 that was passed in as an argument?





  --
 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

[ANN] table 0.3.0 release - ascii tables that fit in your terminal

2012-07-23 Thread Gabriel Horner
Hi,
 Announcing a new version of table, https://github.com/cldwalker/table, a 
clojar that prints ascii tables for almost any data structure. This release 
allows tables to automatically fit your terminal's width.

Thanks,
Gabriel 

-- 
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: Logger conflicts

2012-07-23 Thread Peter Taoussanis
Hi Eric,

I can't offer any advice on resolving this particular incompatibility, but 
I would say that Java logging config difficulties are frustratingly common 
in my experience.

If the opportunity ever arises, I'd suggest you take a look at Timbre as an 
alternative: https://github.com/ptaoussanis/timbre

It's an all-Clojure logging lib I'm working on that's particularly easy to 
configure and that doesn't interfere with or depend on any of the Java 
logging nonsense.

May or may not be a fit for what you need, but it might be worth taking a 
look.

Best of luck!

- Peter Taoussanis (@ptaoussanis)

-- 
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