Re: New clojure support in Polyglot Maven

2010-04-09 Thread Graham Fawcett
Hi Antony,

On Wed, Apr 7, 2010 at 8:07 PM, Antony Blakey antony.bla...@gmail.com wrote:

 I've just pushed a major update to the Clojure support in pmaven to
 http://github.com/sonatype/polyglot-maven. It now covers 100% of
 maven by reflecting over the maven object model. Examples are in the
 tests and in the reader.clj source file. It includes leiningen
 support e.g. mvn -f project.clj install should work.

Thank you, this is a very interesting piece of work.

Your building/installation instructions are a bit on the terse side,
and left this Maven newbie in trial-and-error-land. :) Particularly
this statement confused me, because I don't know what an assembly
play is, or why I'd want one:

  After this completes, you can unzip the assembly play with polyglot
  maven:

  unzip pmaven-cli/target/pmaven-*-bin.zip
  ./pmaven-cli*/bin/mvn

Or did you mean unzip the assembly, and play with polyglot maven?

After trial-and-erroring, I gathered that after unzipping I ended up
with a 'polyglot maven' directory whose 'bin/mvn' could be used to run
tasks like 'mvn -f project.clj'. I assume that the Maven 2 instance I
used to build polyglot-maven is not modified in any way (e.g. it
wasn't retooled to be able to run 'mvn -f project.clj'). Is that
correct?

To use this on an ongoing basis, should I should unzip polyglot-maven
somewhere stable, and then just add the new 'polylot-maven/bin' to my
PATH? (That may seem a silly question, but maybe there's a more
Mavenish way to do these things, and I just don't know about it.)

One last point -- I tried 'mvn -f project.clj' on one of my existing
Leiningen projects, and it failed because the project.clj contained
some clauses that Polyglot Maven didn't expect (:main, :compile-path).
These may not be relevant in a Maven build, but it would be nice if
they could exist in the project.clj file without causing an error when
using your tool. You've gone so far with Leiningen support already,
this would be a valuable next step.

Regards,
Graham



 Antony Blakey
 -
 CTO, Linkuistics Pty Ltd
 Ph: 0438 840 787

 The ultimate measure of a man is not where he stands in moments of comfort 
 and convenience, but where he stands at times of challenge and controversy.
  -- Martin Luther King


 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

 To unsubscribe, reply using remove me as the subject.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: New clojure support in Polyglot Maven

2010-04-09 Thread Graham Fawcett
Hi Antony,

On Fri, Apr 9, 2010 at 11:10 AM, Antony Blakey antony.bla...@gmail.com wrote:

 On 10/04/2010, at 12:24 AM, Graham Fawcett wrote:

 Your building/installation instructions are a bit on the terse side,
 and left this Maven newbie in trial-and-error-land. :)

 I haven't written any instructions, but yes, the instructions on the
 project aren't extensive. And the documentation that is on the
 sonatype site for clojure support is out of date because I don't yet
 have write access to the wiki yet. Sorry, I know software without
 good documentation is only half done.

No worries! It's an early release, and I'm happy that you didn't wait
to announce the software for lack of documentation. Hopefuly the
feedback you get from the list might help you to (eventually) write
some documentation for the Clojure-oriented (and Maven-disoriented!)
audience.

 To use this on an ongoing basis, should I should unzip polyglot-maven
 somewhere stable, and then just add the new 'polylot-maven/bin' to my
 PATH? (That may seem a silly question, but maybe there's a more
 Mavenish way to do these things, and I just don't know about it.)

 No, that's right. Although be aware that there are a few things that
 Maven 3.0 isn't backward compatible with yet. In particular I can't
 use the Atlassian plugin.

OK, thanks for clarifying this.

 One last point -- I tried 'mvn -f project.clj' on one of my existing
 Leiningen projects, and it failed because the project.clj contained
 some clauses that Polyglot Maven didn't expect (:main, :compile-path).
 These may not be relevant in a Maven build, but it would be nice if
 they could exist in the project.clj file without causing an error when
 using your tool. You've gone so far with Leiningen support already,
 this would be a valuable next step.

 Yes, the extensive and complete Leiningen documentation indicates
 that there are a number of things not covered in my defproject macro
 :) I waver between thinking I should ignore properties I don't
 understand and wanting to deal with everything I possibly can, by
 treating unknowns as errors because you never know when that unknown
 property really is important. OTOH, I don't deal with Leiningen
 plugins and have no plans to, so maybe in this case ignorance is
 bliss is the best strategy.

That's a good point. I've only been a casual Leiningen user, so I
can't comment much on the tradeoffs, but I respect that you don't want
to get too deep into Leiningen-compatibility waters. In the short
term, consider documenting that some project.clj clauses may cause
build errors.

Best,
Graham


 Antony Blakey
 --
 CTO, Linkuistics Pty Ltd
 Ph: 0438 840 787

 Lack of will power has caused more failure than lack of intelligence or 
 ability.
  -- Flower A. Newhouse

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

 To unsubscribe, reply using remove me as the subject.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Help needed regarding the let

2010-01-14 Thread Graham Fawcett
Hi,

On Wed, Jan 13, 2010 at 1:30 AM, Manish manish.zed...@gmail.com wrote:
 Thanx for ur response,
 Actually We are using string builder in our project, String Builder
 causing the memory leak in as I google, Thats the main reason i want
 to set the StringBuilder object to nil,
 We are using the htmlunit core js library for fetching the web pages
 which require the javascript enabled. The Decompiler.java using a
 variable StringBuilder result = new  StringBuilder(); Netbeans
 profiler showing that this is the object consuming maximum of memory
 causing memory leak. Thats the reason only I want to set the
 StringBuilder object in our project to null. I also found on net that
 strbuilder.toString() also causing the memory leak. So in place of
 toString() we are trying to use substring(0). Like:

 (defn #^String element-text
  ([thing]
     (let [delimiter #s]
       (element-text thing delimiter)
       ))
  ([thing #^String delimiter]
     (if (instance? Node thing)
       (node-text thing)
       (let [buf (StringBuilder.)]
         (doseq [#^Node e thing]
           (node-text e buf delimiter))
         (let [res (.substring buf 0)]
           (.setLength buf 0)
           res)

Substrings do indeed share memory with their parent strings, and this
will prevent the parents from being garbage-collected.

Try changing this:

  (let [res (.substring buf 0)]
          (.setLength buf 0)
          res))

to:

(String. buf)

and see if your memory problem goes away. Allocating a new String
should copy the StringBuilder buffer, not sharing any storage with it,
and letting the StringBuffer storage be reclaimed.

Best,
Graham
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Lift and bind (was: Understanding the continuation monad's bind operator)

2010-01-12 Thread Graham Fawcett
Hi,

On Mon, Jan 11, 2010 at 8:44 PM, Steven E. Harris s...@panix.com wrote:
 Konrad Hinsen konrad.hin...@fastmail.net writes:

 For a function of a single argument, m-lift and m-fmap are equivalent.

 In Jim Duey's essay Higher Level Monads¹, he writes the following on the
 lift operator:

 ,[ m-lift ]
 | If you have a function that you would like to turn into a monadic
 | function, that is a function that can be passed to m-bind, you use
 | m-lift.
 |
 | m-lift takes two parameters, a function to lift and the number of
 | arguments that function accepts. The argument count is the first
 | parameter and the function is second. The return value is a function
 | that can be passed to m-bind.
 `

 Isn't it the case, though, that a lifted function /can't/ be passed to
 bind, because it's not a monadic function? A lifted function takes
 monadic values as input, rather than a basic value.

 Is there some operator that converts a normal function

  a - b

 to a monadic function

  a - m b

 such that one could adapt a normal function for use in and among some
 other monadic functions (such as with m-chain)? I'm not sure such a
 translation is possible for all monads.

I don't know Clojure monads, but in Haskell that operator would be
(.) return, that is the partial application of the composition
function to the 'return' function:

Prelude :t (.) return
(.) return :: (Monad m) = (a - b) - a - m b

 I considered something like this

 ,
 | (defn as-monadic-fn [f]
 |   (fn [v]
 |     (m-result (f v

I'd say that looks right. It has the same meaning as:

(def as-monadic-fn (partial comp m-result))

...which is a transliteration of (.) return in Haskell.

Best,
Graham

 but it looks too simple.


 Footnotes:
 ¹ http://intensivesystems.net/tutorials/monads_201.html

 --
 Steven E. Harris


 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: parsing/processing of big xml files...

2010-01-06 Thread Graham Fawcett
Hi Alex,

On Wed, Jan 6, 2010 at 9:06 AM, Alex Ott alex...@gmail.com wrote:
 Hello all

 I have question about processing big XML files with lazy-xml.  I'm trying to 
 analyze
 StackOverflow dumps with Clojure, and when analyzing 1.6Gb XML file with
 posts, i get java stack overflow, although i provide enough memory for java
 (1Gb of heap).

Someone asked this question a while back, and a suggestion given was
to use Mark Triggs' XOM wrapper:

http://github.com/marktriggs/xml-picker-seq

Thread:
http://groups.google.com/group/clojure/browse_thread/thread/365ca7aaaf8d55b7?pli=1

Cheers,
Graham


 My code looks following way


 (ns stackoverflow
  (:import java.io.File)
  (:use clojure.contrib.lazy-xml))

 (def so-base /data-sets/stack-overflow/2009-12/122009 SO)

 (def posts-file (File. (str so-base /posts.xml)))

 (defn count-post-entries [xml]
  (loop [counter 0
         lst xml]
    (if (nil? lst)
      counter
      (let [elem (first lst)
            rst (rest lst)]
        (if (and (= (:type elem) :start-element) (= (:name elem) :row))
          (recur (+ 1 counter) rst)
          (recur counter rst))

 and run it with

 (stackoverflow/count-post-entries (clojure.contrib.lazy-xml/parse-seq 
 stackoverflow/posts-file))

 I don't collect real data here, so i expect, that clojure will discard
 already processed data.

 The same problem with stack overflow happens, when i use reduce:

 (reduce (fn [counter elem]
          (if (and (= (:type elem) :start-element) (= (:name elem) :row))
            (+ 1 counter)
            counter))
        0 (clojure.contrib.lazy-xml/parse-seq stackoverflow/posts-file))

 So, question is open - how to process big xml files in constant space? (if
 I won't collect much data during processing)

 --
 With best wishes, Alex Ott, MBA
 http://alexott.blogspot.com/           http://xtalk.msk.su/~ott/
 http://alexott-ru.blogspot.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: SQL addition: connection input

2009-12-23 Thread Graham Fawcett
Hi Richard,

On Wed, Dec 23, 2009 at 5:31 PM, Richard Newman holyg...@gmail.com wrote:
 I just started using Proxool, and c.c.sql doesn't offer a way to
 either pass in a connection object, or to construct a JDBC URI that
 starts with anything but 'jdbc:'.

 Here's a patch that allows {:connection my connection} as a valid DB
 spec. I've tested it out and it seems to work fine.

 Should I create a ticket?

Already ticketed and patched. Not sure what the release schedule is, though.

http://www.assembla.com/spaces/clojure-contrib/tickets/50

Best,
Graham



 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: eval performance

2009-12-21 Thread Graham Fawcett
On Mon, Dec 21, 2009 at 6:07 PM, Gabi bugspy...@gmail.com wrote:
 The problem with is that I need to execute the same function with
 different bindings each time. So caching won't help me
 For example I need to do something like:

 (dotimes [_ 1000]
  (intern  'user 'x (rand))
  (eval '(prn (+(* x x) 5

So, 'x' is an open term within your expression. Simply define a
function (fn [x] (prn (+ (* x x) 5))) instead, and call it with your
binding for 'x'. No need for eval here -- maybe once to define the
function, but certainly not to evaluate the expression.

Best,
Graham


 On Dec 21, 11:53 pm, AlexK alexander.konstanti...@informatik.haw-
 hamburg.de wrote:
 What eval does, is wrapping (fn* [] expression) around its
 arguments, compiling that, and calling the resulting function object
 (except if your list starts with a 'do or a 'def).

 While Clojure's compiler is pretty fast, you should try not to use
 eval. If you want to pass code around you should try something like
 storing functions in a map or something similar.

 If you think that you have to eval lists, try wrapping them in (fn
 [] ...) and eval that form instead. You'll get a function object which
 was compiled once, but can be called as many times as you want.

 eg.

 (defn form-fn [list-to-eval]
   (eval (list 'fn [] list-to-eval))) ;this returns a fn

 (def form-fn (memoize form-fn)) ;caches the resulting fns, beware of
 memory leaks though

 ((form-fn '(println Hello World)))
 ((form-fn '(println Hello World)))
 ((form-fn '(println Hello World))) ; should compile only once

 Alex

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: How to modify the last few elements of a vector

2009-12-17 Thread Graham Fawcett
On Thu, Dec 17, 2009 at 2:04 AM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 On Dec 16, 10:36 pm, Graham Fawcett graham.fawc...@gmail.com wrote:

 Not sure it's better, but I find this more readable:

 (defn stack-apply [n f stack]
   (if (zero? n)
     stack
     (conj (stack-apply (dec n) f (pop stack))
           (f (last stack)

 Unrelated note: (last stack) turns the vector into a seq and walks it
 linearly. (peek stack) returns the last element in O(1) (or maybe O
 (log32 N)?) time.

Definitely related! Thanks, Miekel, I have not yet internalized all of
these seq operations.

Best,
Graham



 Sincerely
 Meikel

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: How to modify the last few elements of a vector

2009-12-16 Thread Graham Fawcett
On Wed, Dec 16, 2009 at 1:33 PM, samppi rbysam...@gmail.com wrote:
 I'm using a vector as a stack. I want to apply a function–let's call
 it modify-element, one argument—to the elements from k to (- (count a-
 vector) k).

 Right now, I have something like (not tested yet):
  (reduce #(update-in %1 [%2] modify-element) a-vector (range k (-
 (count a-vector) k)))

 Is there a better way?

Not sure it's better, but I find this more readable:

(defn stack-apply [n f stack]
  (if (zero? n)
stack
(conj (stack-apply (dec n) f (pop stack))
  (f (last stack)

user (let [stack [1 2 3 4 5]
f #(* 100 %)]
(stack-apply 3 f stack))
[1 2 300 400 500]

Best,
Graham



 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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


Deploying Leiningen project as WAR file?

2009-12-11 Thread Graham Fawcett
Hi folks,

Does anyone have advice (recipe, blog article, etc.) for building a
servlet WAR based on a Leiningen project?

Is there interest in developing a 'lein war' plugin? I'm a novice at
Ant, WAR, etc., but It seems to me that most of the mechanics are
already present in 'lein uberjar' -- it's just a matter of getting the
WAR-specific details ironed out.

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Deploying Leiningen project as WAR file?

2009-12-11 Thread Graham Fawcett
On Fri, Dec 11, 2009 at 11:51 AM, Sean Devlin francoisdev...@gmail.com wrote:
 While we're at it, how 'bout an EAR file?

Never encountered one of those before -- maybe that is a good thing! :)

After a little study, I was able to write a simple servlet, compile it
with Leiningen, and make a WAR using Maven. This might be no big news
to the Java literati in the audience, but it's all new to me. :)

I thought I'd share my notes here, in case anyone else is trying to do
the same thing. There is a copy of my work here:

http://github.com/gmfawcett/simplest

The basic recipe I followed is there, and for lazier readers it also
appears below.

Many thanks to yogthos' clojure-maven-examples, which answered many
questions (though it uses clojure-maven-plugin, and does not use
Leiningen):

http://github.com/yogthos/clojure-maven-examples

Best,
Graham


* Start a new project with Leiningen (I'm using Leiningen 1.0.1):

  $ lein new simplest

* Add your servlet. I put mine in 'src/simplest/servlet.clj':

  (ns simplest.servlet
  (:gen-class :extends javax.servlet.http.HttpServlet))

  (defn -doGet [this req resp]
   ...)

* Add your dependencies to the project file. I added
  [javax.servlet/servlet-api 2.5].

* Set the :compile-path, so that the classfiles end up where Maven
  will expect to see them:

  (defproject simplest 1.0.0-SNAPSHOT
 :compile-path target/classes
 ...)

* Compile it with Leiningen, to make sure there aren't any errors:

  $ lein compile
  [copy] Copying 3 files to /tmp/simplest/lib
  Compiling simplest
  Compiling simplest.servlet

* Add the web.xml file and whatever static resources you want under
  'src/main'. I added:

  src/main/webapp/WEB-INF/web.xml
  src/main/webapp/index.html

  My web.xml is basic:

   web-app xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns=http://java.sun.com/xml/ns/javaee;
xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd;
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd;
id=simplest
version=2.5
 display-nameSimplest Clojure Servlet/display-name
 servlet
   servlet-namesimplest/servlet-name
   servlet-classsimplest.servlet/servlet-class
 /servlet
 servlet-mapping
   servlet-namesimplest/servlet-name
   url-pattern/simplest//url-pattern
 /servlet-mapping
 welcome-file-list
  welcome-fileindex.html/welcome-file
 /welcome-file-list
   /web-app

* Make your POM file for Maven:

  $ lein pom
  Wrote pom.xml

* Generate the WAR file:

  $ lein compile; mvn war:war
  
  $ ls target/*.war
  target/simplest-1.0.0-SNAPSHOT.war

* QED!

* If you want, you can add a 'Jetty plugin' to your pom.xml. This
  will enable Maven to run your servlet(s) for you in a standalone Web
  server, for testing:

  Edit pom.xml: see
  
http://github.com/gmfawcett/simplest/commit/44d978c55ae02112647a743b6f957156787fba25

  $ lein compile; mvn jetty:run
  # visit your servlet at http://localhost:8080/

Lacking proper Leiningen/Maven integration, it's a good idea to always
call 'lein compile' before you run a Maven command.

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Code arrangement for understandability

2009-12-10 Thread Graham Fawcett
On Thu, Dec 10, 2009 at 9:15 AM, ngocdaothanh ngocdaoth...@gmail.com wrote:
 Hi,

 I want to ask about code arrangement and understandability
 (readability).

 Consider this normal code:
 x = 1
 ...
 f(x)
 ...
 y = x + 2
 ...
 g(y)

 x, f, y, g have the same abstractness level, so they are indented to
 the same level.

In what sense do they have the 'same abstractness level'? What do you
mean by abstractness? g(y) depends upon y; y depends upon x; nothing
depends upon f(x), so presumably it is being called for side effects.
I don't see anything similar about them.

You could also write

(let [x 1
  _ (f x)
  y (+ x 2)
  _ (g y)]
  ...)

which puts them all at the same nesting level.

Best,
Graham


 My Clojure code:
 (let [x 1]
  ...
  (f x)
  ...
  (let [y (+ x 2)]
    ...
    (g y)))

 It is very difficult to capture the algorithm behind the Clojure
 code because things of the same abstractness level do not have the
 same indent level.

 How to rearrange the Clojure code for understandability?

 I have been studying Clojure for several months now but I could never
 get it. But I couldn't explain why I couldn't get it, I just didn't
 know why. But today I think I have found the reason: I think the
 problem of Clojure (and Lisp) is not parenthesis, its problem is
 indent.

 I think if I can let over this problem, I will be enlightened. Would
 you please help me?

 Thank you,
 Ngoc

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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


Pull request for clojure.contrib.sql?

2009-12-10 Thread Graham Fawcett
Hi folks,

To whom should I send a pull-request for an enhancement for
clojure.contrib.sql? I see that scgilardi is listed as the author, but
I'm not very clear on how the contrib community works.

My patch provides an :external key to (get-connection), which lets you
pass in an existing db connection instead of a db spec. This makes it
trivial to get get c.c.sql to work with (for example) a Proxool db
connection pool.

http://github.com/gmfawcett/clojure-contrib/commit/c74833d5972eaf9357fdd9fd5da6f6bf7f1769bc
Proxool: http://proxool.sourceforge.net/

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Pull request for clojure.contrib.sql?

2009-12-10 Thread Graham Fawcett
Hi Steve,

On Thu, Dec 10, 2009 at 4:53 PM, Stephen C. Gilardi squee...@mac.com wrote:
 Hi Graham,

 To whom should I send a pull-request for an enhancement for
 clojure.contrib.sql? I see that scgilardi is listed as the author, but
 I'm not very clear on how the contrib community works.

 The contributing process is described at:

        http://clojure.org/contributing

 The patch submission process (once you're a registered contributor) is 
 described at:

        http://clojure.org/patches

 The underlying idea sounds good on a quick read. I'll take a look and see if 
 I have any ideas along those lines.

Thank you! I'm already a registered Clojure contributor. Tomorrow I'll
prepare a ticket and attach the patch.

If you'd rather discuss it first on or off-list, let me know  I'll
hold off on the ticket.

Best,
Graham



 --Steve



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Question about The whole language is there, all of the time.

2009-12-09 Thread Graham Fawcett
On Wed, Dec 9, 2009 at 11:15 AM, Jarkko Oranen chous...@gmail.com wrote:
 Jeff Dik wrote:
 The part Running code at read-time lets users reprogram Lisp's
 syntax caught my attention.  Is this talking about reader macros?  I
 believe I read that clojure doesn't have reader macros, so would it be
 more accurate to say The whole language is there, _most_ of the
 time?


 Clojure does have reader macros, though they're implemented in Java at
 the moment (because the reader is, too.) They're also reserved for the
 implementation, though this may change in the future, if someone can
 convince Rich that an user-augmentable reader provides enough benefits
 to outweigh the potential problems.

There are certainly lots of good reasons not to include reader macros
in the Clojure (e.g. it raises the bar significantly for people
writing editors and other tools). But it would be useful if someone
were to maintain a fork of Clojure that adds reader-macro capability,
and let the community play with it for a while: sort of the way that
the bleeding-edgers are playing now with protocols and deftypes on the
'new' branch. The experimentation might bear some interesting fruit.

Best,
Graham



 --
 Jarkko

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: Handling XML

2009-12-02 Thread Graham Fawcett
On Wed, Dec 2, 2009 at 11:29 AM, Dennis shr3ks...@gmail.com wrote:
 Sean,
 I probably did not make it clear, but I am using parse.  The second line of
 handle-xml function in my original E-Mail has the parse in it.  I then
 iterate over the xml-seq.

Are you familiar with 'zippers'? There is a zipper for xml-seqs in contrib:

http://richhickey.github.com/clojure-contrib/zip-filter-api.html

This might afford you a better way to navigate your XML documents. I
don't know of any how-to docs on xml zippers, but a quick google found
this blog article:

http://netzhansa.blogspot.com/2008/10/trying-clojure.html

Best,
Graham

 I am also using:
 (ns zod
   (:require [clojure.contrib.http.agent :as http])
   (:import (java.util Timer TimerTask))
   (:use [clojure.xml :only (parse)]))
 -- Dennis
 On Wed, Dec 2, 2009 at 10:23 AM, Sean Devlin francoisdev...@gmail.com
 wrote:

 Try the clojure.xml namespace.  There's a funciton parse in there that
 should help.

 On Dec 2, 10:51 am, Dennis shr3ks...@gmail.com wrote:
  Howdy,
 
  Being new to clojure, I am having a difficult time parsing XML in an
  elegant
  manner.  I am pulling metric information from a ganglia server as XML
  and
  then parsing it.  The below function works but it makes me feel icky.  I
  was
  hoping for some tips.
 
  The dc variable contains a map with some data center information (not
  really interesting), and the stream variable comes from http.agent.
 
  (defn handle-xml [dc stream]
    (let [xml-out (xml-seq (parse (http/stream stream)))]
      (doseq [x xml-out]
        (doseq [y (:content x)]
  (doseq [z (:content y)]
    (doseq [a (:content z)]
      (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL
  (:attrs
  a)) (:TN (:attrs a)
 
  The XML is of the form:
  ganglia
    multiple clusters
      multiple hosts
        multiple metrics
 
  Example of the XML:
  GANGLIA_XML VERSION=3.0.7 SOURCE=gmond
  CLUSTER NAME=cluster.example.com LOCALTIME=1258396022
  OWNER=unspecified LATLONG=unspecified URL=unspecified
  HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019
  TN=3
  TMAX=20 DMAX=86400 LOCATION=unspe
  cified GMOND_STARTED=1255757736
  METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB
  TN=6684
  TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/
  METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682
  TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/
  ...
 
  Thanks,
  Dennis

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from 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: Sneak Peek

2009-11-25 Thread Graham Fawcett
Hi Jim,

On Tue, Nov 24, 2009 at 11:21 PM, jim jim.d...@gmail.com wrote:
 Evening all,

 I've been working on a library for writing web applications for
 compojure. I've got it written and (I think) working. First thing
 tomorrow is to write a sample app and post it along with the library.

 But in the meantime, I thought I'd let you all read about it if you're
 having trouble sleeping. :)

 http://intensivesystems.net/tutorials/web_sessions.html

Neat. It looks like you're writing what's usually called a
continuation-based web framework. When I read your title and first
couple paragraphs, I thought you were writing a session-management
library (e.g. setting cookies, keeping server-side state, etc.). You
might consider mentioning continuations somewhere in your article, if
only to attract Googling continuation-based fans.

You might already be familiar with other continuation-based
frameworks. If not, consider looking at projects like Wee (for Ruby)
and Seaside (for Smalltalk) to steal some ideas. :)

Best,
Graham


 One thing I love about FP in general and Clojure specifically is the
 density of code that is possible. This library is only about 80 lines
 of code.

 Jim

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure Scoping Rules

2009-11-21 Thread Graham Fawcett
On Sat, Nov 21, 2009 at 12:17 PM, Mark Engelberg
mark.engelb...@gmail.com wrote:
 Intuitively, it seems to me that what one wants is for lazy data
 structures to contain bound values in some sort of closure-like thing
 so rebindings after the fact don't affect the data structure, but
 regular functions should retain their fully-dynamic behavior.  I
 haven't really thought it through, so probably this doesn't quite
 work, but this kind of separation between the behavior of data
 structures and functions when dealing with dynamic binding is what's
 been going through my mind.

In Haskell, you might use a state-carrying monad as the 'closure-like
thing'. If you squint enough, those monads look an awful lot like
dynamic binding contexts. They have the variable-hiding properties of
dynamic binding, but with a scope that's more amenable to lazy
evaluation.

The same technique ought to work in Clojure. I haven't played at all
with the monad tools in clojure.contrib, but you might want to give
them a try.

If you're new to monads, there are quite a few Haskell tutorials; I
won't try to enumerate them. ;-) This link is an overview of the
Reader monad, which I think is most similar to the dynamic binding
construct:

http://www.haskell.org/all_about_monads/html/readermonad.html

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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] leiningen - a Clojure build tool

2009-11-20 Thread Graham Fawcett
On Wed, Nov 18, 2009 at 2:29 AM, Phil Hagelberg p...@hagelb.org wrote:

 With Leiningen, your build is described using Clojure. You can put any
 code you like in your project.clj file; the only requirement is that
 it includes a call to defproject. You can define your own tasks in
 there if you need to, but the majority of projects should be able to
 get by on the tasks that are provided with Leiningen. If you do find a
 common task that you need to add, you can implement it as a plugin
 rather than copying and pasting among each of your projects.

This is outstanding; thank you!

I'd love to see a short recipe on how to deploy a simple application
(hello-world) into an executable jar using Leiningen. I've tried, but
seem to be messing something up.

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: leiningen - a Clojure build tool

2009-11-20 Thread Graham Fawcett
On Fri, Nov 20, 2009 at 11:11 AM, Sean Devlin francoisdev...@gmail.com wrote:
 The Incanter guys put something up:

 http://incanter-blog.org/2009/11/20/leiningen-clojars/

Excellent, thanks!

Leiningen + Clojars is a game-changer for Clojure. I'm very excited.

Will-need-to-practice-spelling-leiningen'ly yours,
Graham



 On Nov 20, 11:06 am, Graham Fawcett graham.fawc...@gmail.com wrote:
 On Wed, Nov 18, 2009 at 2:29 AM, Phil Hagelberg p...@hagelb.org wrote:

  With Leiningen, your build is described using Clojure. You can put any
  code you like in your project.clj file; the only requirement is that
  it includes a call to defproject. You can define your own tasks in
  there if you need to, but the majority of projects should be able to
  get by on the tasks that are provided with Leiningen. If you do find a
  common task that you need to add, you can implement it as a plugin
  rather than copying and pasting among each of your projects.

 This is outstanding; thank you!

 I'd love to see a short recipe on how to deploy a simple application
 (hello-world) into an executable jar using Leiningen. I've tried, but
 seem to be messing something up.

 Best,
 Graham

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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


tree-shaking a jarred Clojure app?

2009-11-20 Thread Graham Fawcett
Hi folks,

This is somewhat a Java question, but it's in the context of Clojure,
so here goes. Playing with Leiningen got me thinking about bundling a
Clojure application as a JAR, which might include a host of classes
that are loaded but never used. Is it possible to tree-shake such a
jarfile, and eliminate any classes that are not required for the
main-class' operation? (Assuming the program doesn't need 'eval' with
access to all of those classes at runtime.)

This might not save a lot of startup time, but where startup time
matters, maybe it might shave off a meaningful fraction. I'm just
curious whether there is enough dependency information in a set of
class files to calculate a tree-shaking plan; and whether there are
existing tools to do the job.

Best,
Graham

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: tree-shaking a jarred Clojure app?

2009-11-20 Thread Graham Fawcett
On Fri, Nov 20, 2009 at 1:37 PM, Jim Downing jim.down...@gmail.com wrote:
 Hi Graham

 2009/11/20 Graham Fawcett graham.fawc...@gmail.com:
 Hi folks,

 This is somewhat a Java question, but it's in the context of Clojure,
 so here goes. Playing with Leiningen got me thinking about bundling a
 Clojure application as a JAR, which might include a host of classes
 that are loaded but never used. Is it possible to tree-shake such a
 jarfile, and eliminate any classes that are not required for the
 main-class' operation? (Assuming the program doesn't need 'eval' with
 access to all of those classes at runtime.)

 This might not save a lot of startup time, but where startup time
 matters, maybe it might shave off a meaningful fraction. I'm just
 curious whether there is enough dependency information in a set of
 class files to calculate a tree-shaking plan; and whether there are
 existing tools to do the job.

 I might have misunderstood, but isn't the problem the same as in Java;
 you can't know from a static analysis which classes are going to be
 loaded?

If it's not possible in Java, then yes, it wouldn't be any different
in Clojure. But after an admittedly casual search, I don't know what
the specific blockers are to tree-shaking in Java.

I know there are dynamic load-class-by-name facilities in the JVM, and
of course that would be a barrier for static analysis. I've only ever
seen these called with literal strings, though (e.g. in setting a JDBC
driver), and that could be statically analyzed.

But I should be able to know, through class inspection, whether my
'main' program depends on a class which uses, say, the clojure.zip
namespace, and decide whether or not to include it. Or so I am
wondering.

I suppose a better question might be: would a tree-shaker have a
reasonable chance of shaking a typical Clojure jar, or are there too
many dynamic obstacles to a good analysis.

Just curious,
Graham



 Best regards,

 jim

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: version of - short-circuiting on nil

2009-03-24 Thread Graham Fawcett

On Mon, Mar 23, 2009 at 6:49 PM, Laurent PETIT laurent.pe...@gmail.com wrote:
 Hello,

 there has been plenty of time to speak about that in the previous thread on
 the subject, and it's a shame these interesting proposals had to wait for
 the release of the functionality to pop up :-).

 But I think it's my fault: when nobody did additional comments on the
 thread, I considered one of the last proposals as silently accepted by most,
 and since it was one of Rich's proposals to use .?. and -?, I took them. So
 I did not close the brainstorming with a if everybody agrees, I'll use
 these names ... and write the patch.

No worries, Laurent. Sorry for not joining the discussion earlier. :-)
Actually I think the -? squiggle is quite a good name for this
function.

Best,
Graham



 Concerning the fact that .. could be removed from clojure.core, why not. I
 suggest that the .?. version be removed when (if) .. is removed.

 Concerning the names, shouldn't maybe- be reserved for the real monadic
 version (I haven't seen how monads are implemented in clojure, and I'm not
 sure the signature of a maybe- monad would be the same as -?) ?

 Regards,

 --
 Laurent

 2009/3/23 Graham Fawcett graham.fawc...@gmail.com

 On Sun, Mar 22, 2009 at 9:05 PM, Stephen C. Gilardi squee...@mac.com
 wrote:
 
  On Mar 22, 2009, at 4:43 PM, Meikel Brandmeyer wrote:
 
  Is .?. necessary? - does the same job as .. by
  virtue of the .method notation, but is more general.
  So, why not get rid of .. and .?. completely?
 
  That sounds right to me, Meikel. I'm in favor of keeping only -? .

 Might I suggest maybe- ? This function has a strong similarity to
 the Maybe monad in Haskell and similar languages.

 and- would be another less Haskelly candidate, and is reminiscent
 of Scheme's and-let* which is also sort-of similar.

 Best,
 Graham





 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: version of - short-circuiting on nil

2009-03-22 Thread Graham Fawcett

On Sun, Mar 22, 2009 at 9:05 PM, Stephen C. Gilardi squee...@mac.com wrote:

 On Mar 22, 2009, at 4:43 PM, Meikel Brandmeyer wrote:

 Is .?. necessary? - does the same job as .. by
 virtue of the .method notation, but is more general.
 So, why not get rid of .. and .?. completely?

 That sounds right to me, Meikel. I'm in favor of keeping only -? .

Might I suggest maybe- ? This function has a strong similarity to
the Maybe monad in Haskell and similar languages.

and- would be another less Haskelly candidate, and is reminiscent
of Scheme's and-let* which is also sort-of similar.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Object system for Clojure?

2009-01-30 Thread Graham Fawcett

On Fri, Jan 30, 2009 at 1:09 PM, Jan Rychter j...@rychter.com wrote:

 From what I read, the reasoning is that Clojure provides extremely
 general multimethods where you have to define a dispatch function. On
 the object side, there is metadata and you can do with it whatever you
 want. But this seems to leave a gaping hole saying fill me with an
 object system. Is the goal for everyone to roll their own?

Hi,

Just curious, have you seen the a la carte hierarchies scheme that
Rich worked up last summer?

http://groups.google.com/group/clojure/browse_frm/thread/9cc9926de1bdb128?pli=1

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: What is this function called?

2009-01-02 Thread Graham Fawcett

On Thu, Jan 1, 2009 at 10:14 PM, Andrew Baine andrew.ba...@gmail.com wrote:
 I want to get a seq of successive rests of the given seq:
 user (defn f [seq]
 (if (empty? seq)
  nil
  (lazy-cons seq (f (rest seq)
 #'user/f
 user (f '(1 2 3 4))
 ((1 2 3 4) (2 3 4) (3 4) (4))

Hi,

Haskell has tails in the Data.List module which is similar, though
it includes a null-list as a final value:

*Main Data.List.tails [1..4]
[[1,2,3,4],[2,3,4],[3,4],[4],[]]

*Main take 10 . map (take 5) . Data.List.tails $ iterate (+1) 1
[[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9],[6,7,8,9,10],[7,8,9,10,11],[8,9,10,11,12],[9,10,11,12,13],[10,11,12,13,14]]

Rests makes good sense as a Clojure-name, IMO, as does not including
a null-value at the end.

Graham


 user (take 10 (map #(take 5 %) (f (iterate inc 1
 ((1 2 3 4 5) (2 3 4 5 6) (3 4 5 6 7) (4 5 6 7 8) (5 6 7 8 9) (6 7 8 9 10) (7
 8 9 10 11) (8 9 10 11 12) (9 10 11 12 13) (10 11 12 13 14))
 Does this fn already exist in clojure?  If not what would an idiomatic name
 be for it from Haskell or CL?
 Andrew
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: offtopic - where are you come from? (poll)

2008-11-21 Thread Graham Fawcett

On Fri, Nov 21, 2008 at 8:14 PM, Telman Yusupov [EMAIL PROTECTED] wrote:

 Toronto, Canada

Another Canadian! The more the merrier. :-)

Just a reminder that I put up a Google map of Clojure users worldwide:

http://tinyurl.com/5kl68p

If you're so inclined, you're invited to take a moment and add
yourself to the map.

I know the map and this discussion thread aren't of any technical
value, but it's very nice to feel the size and scope of the Clojure
community.
Thank you, Rastislav Kassak, for starting the original thread.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: writing binary values (bytes) to a file

2008-11-19 Thread Graham Fawcett

Hi,

 Dealing with byte-arrays, you will want to use the write-method that
 takes an array, not the one that takes a string.

 Constructing the array is a bit tricky:

 ; Define your int
 (def pix 652187261)

 ; Define your array, typed as array of char
 (def payload
  (into-array Character/TYPE [(char (bit-shift-right pix 16))
  (char (bit-shift-right pix 8))
  (char pix)]))

Char's on the JVM are not bytes, and are wider than 8 bits -- so if
you're packing binary data, you should use Byte and byte instead of
Character and char. (Note too that the pix value is greater than 2^24,
so you need four bytes to store it if you're using a byte-array.)

As wwmorgan mentioned, FileOutputStreams can write out byte-buffers,
so the following seems to work:

; Define your int
(def pix 652187261)

; Define your array, typed as array of byte (not char!)
(def payload
(into-array Byte/TYPE [(byte (bit-shift-right pix 24))
   (byte (bit-shift-right pix 16))
   (byte (bit-shift-right pix 8))
   (byte pix)]))

; Create your FileWriter
(def ofile (java.io.FileOutputStream. /tmp/somefile.bin2))

; Write and close
(.write ofile payload)
(.close ofile)

The created file contains four bytes: 26 df 96 7d.

Bonus question for the bored reader: write a function,
(byte-array-maker N), that takes a width N, and returns a function
that takes an Integer as input and returns an N-width byte array
containing the Integer in big-endian order. E.g.

((byte-array-maker 4) 652187261)
= [4-byte array: 26, df, 96, 7d]

Cheers,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: [SOLVED] writing binary values (bytes) to a file

2008-11-19 Thread Graham Fawcett

On Wed, Nov 19, 2008 at 4:49 PM, Mark Volkmann
[EMAIL PROTECTED] wrote:

 On Wed, Nov 19, 2008 at 2:45 PM, prhlava [EMAIL PROTECTED] wrote:


 Hello again,

 Thank you all for the posts and explanations,

 After getting the clojure SVN version and few tweaks in the code, the
 working result looks like:

 (with-open [ofile (new java.io.FileOutputStream
(str result-directory
 /
 (make-filename x y))
(boolean true))] ; I am appending only
(. ofile write
  (into-array Byte/TYPE
  [(byte (bit-shift-right pix 16))
   (byte (bit-shift-right pix 8))
   (byte pix)])) ; the pix is of the 
 Integer type

 It looks like with-open accepts any number of bindings. Does it just
 call close on the first one when the body finishes or on all of them?

 If I wanted to figure this out for myself, how would I find the source
 code for with-open?

Hi,

If you're using Slime in Emacs, type in the word with-open (or put
your cursor on it in a Clojure source file) and press M-. (alt-period
or Escape, period).

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: precompiling Clojure core sources in Ant build script

2008-11-14 Thread Graham Fawcett

On Fri, Nov 14, 2008 at 2:37 PM, Rich Hickey [EMAIL PROTECTED] wrote:



 On Nov 14, 12:51 pm, Stuart Sierra [EMAIL PROTECTED]
 wrote:
 Patch attached.  This precompiles everything except parallel.clj,
 which requires an extra Jar.  It also omits the source .clj files from
 the clojure.jar file.
 -Stuart Sierra


 Patch applied (svn 1101) - thanks!

Hi folks,

Just FYI, this breaks, at least for me, 'slime-edit-definition' in
swank-clojure (also known as M-.), which pops open the source
definition of the word under point.

I'm sure there's a work-around, of course. The meta information is still there:

user (meta #'last)
{:arglists ([coll]), :doc Return the last item in coll, in linear
time, :name last, :file core.clj, :line 161, :ns #Namespace
clojure.core}

so it must just be a configuration issue. I will read over the
swank-clojure code.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: precompiling Clojure core sources in Ant build script

2008-11-14 Thread Graham Fawcett

On Fri, Nov 14, 2008 at 4:01 PM, Stephen C. Gilardi [EMAIL PROTECTED] wrote:

 On Nov 14, 2008, at 3:38 PM, Graham Fawcett wrote:

 I'm sure there's a work-around, of course. The meta information is still
 there:

 This appears to be because the sources are no longer included in
 clojure.jar. I added path-to-clojure-trunk-svn-directory/src/clj to my
 classpath and now it works.

Thanks, Steve -- an easy fix!

Best,
Graham


 --Steve

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: newbie: can clojure do ...

2008-11-11 Thread Graham Fawcett

On Tue, Nov 11, 2008 at 12:59 AM, Daniel Spiewak [EMAIL PROTECTED] wrote:

 Sounds like you're wasting your time trying to get this working with
 just static HTML pages.  I think that it's possible, but you would
 have to do a lot of really nasty javascript hackery to make the button
 targets dynamic.  Alternatively, the HTML could be truely static and
 pre-generated using a program written in your language of choice.  No
 special software is needed for either route, but they both sound
 painful and really more trouble than they're worth.

If you did choose to go the static-HTML route, then you could export a
table of contents in JavaScript, and let each page use this table to
determine which pages precede and follow it. So if you have pages
like:

2008-11-01.html
2008-11-05.html
2008-11-06.html

you might have a toc.js file containing

days = ['2008-11-01', '2008-11-05', '2008-11-06']
function previous_day_url() { ... }  // uses 'days' and 'document.location.href'
function next_day_url() { ... }

Each html file would include this JS file, and use it to power the
forward/backward buttons. Presumably you can hook into Muse's
publishing function and have it generate the JS file automatically for
you.

You might learn some JavaScript, HTML and Elisp this way, but no Clojure. :-)

Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



The Dread Revision 1089

2008-11-10 Thread Graham Fawcett

Hi folks,

I haven't been bitten by the do not use revisions, R1089 onward, but
it seems that others have.

I'm just curious why the team decided not to use a branch for these
breaking changes, and merging back with trunk once the breakage was
finished?

Like many open-source projects, Clojure seems to have a HEAD culture
rather than a Release culture, so intentionally breaking HEAD should
be taboo, IMHO.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: The Dread Revision 1089

2008-11-10 Thread Graham Fawcett

On Mon, Nov 10, 2008 at 10:33 AM, Rich Hickey [EMAIL PROTECTED] wrote:

 I'll also add that I didn't check in something that didn't run, just
 something that contains changes that require changes to your code or
 environment. Tracking SVN HEAD certainly implies a willingness to make
 such changes.

All points well-taken, Rich -- thanks for the response.

Cheers,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: doseq, dotimes loop/recur

2008-11-08 Thread Graham Fawcett

Hi,

On Sat, Nov 8, 2008 at 11:20 AM, verec
[EMAIL PROTECTED] wrote:

 More of an inquiry into the fp mindset as opposed to the procedural
 one than anything else ...

 If I got this right, there are two forms of iterations: internal and
 external.
 `map' is an internal iterator, `doseq' is an external iterator.

I see where you're going there, but I wouldn't put too fine a point on
the distinction between internal and external. Really they're just
different syntax for expressing the same thing.

The intention behind the do forms isn't about externality but
evaluation strategy. As you know, sequences in Clojure are lazy. The
do forms force evaluation of a sequence's elements to be done
immediately, rather than lazily as needed. A common reason you'd want
to do that is because your do-expression has side-effects (I/O) and
you want the effects to happen now rather than spread out across a
set of future time points (or possibly not at all, if the sequence is
never evaluated to its end).

Ignoring laziness for a moment, all of these iteration constructs can
be expressed in terms of loop/recur, since any iteration form can be
expressed in terms of recursion. They can also be built up from
reduce, which is a form called a fold in other functional languages,
and is the internal equivalent of loop/recur, to borrow your
terminology. Using (doall) in conjunction with either of these would
let you express the non-lazy do forms.

The benefit of map, reduce, filter isn't that they are inherently
different from loop/recur, but that they concisely express a notion of
transforming one sequence into another using a transformation
function. If the expression you're trying to build up naturally fits
that pattern, then map, reduce, filter are a good fit. (Note, reduce
is more general than map/filter, in that it can transform a sequence
into something other than another sequence.)

Since reduce is the internal equivalent to loop/recur, you might
consider writing some expressions in both styles until the equivalence
makes sense. For example, here are two simple functions described
using loop and reduce.

(defn add-up [numbers]
  (loop [nums numbers accumulator 0]
(if (nil? nums)
accumulator
(recur (rest nums) (+ (first nums) accumulator)

(defn add-up-reducing [numbers]
  (reduce + 0 numbers))

(defn sum-and-product [numbers]
  (loop [nums numbers sum 0 product 1]
 (if (nil? nums)
 [sum product]
 (recur (rest nums)
(+ (first nums) sum)
(* (first nums) product)

(defn sum-and-product-reducing [numbers]
  (reduce (fn [[sum prod] frst] [(+ sum frst) (* prod frst)])
  [0 1]
  numbers))

In short, if you can figure out how to write your expression using
reduce rather than a loop, it can lead to more compact code. But more
complex reduce expressions can be hard to follow, and loop will make
for better readability.

Hope this helps,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: doseq, dotimes loop/recur

2008-11-08 Thread Graham Fawcett

HI,

On Sat, Nov 8, 2008 at 2:39 PM, verec
[EMAIL PROTECTED] wrote:

 But then why would we want any of `doseq', `dotimes' or `doall', and
 if we do, is that set complete, and with respect to what design
 principle?

Well, given loop/recur as a fundamental iteration form, and doall as a
mechanism for forcing evaluation of the spine of a sequence, I'd say
that loop/recur + doall could be used to build all the other forms.

(I realize I mis-spoke in my earlier message by saying that loop/recur
and reduce could be equated. That's not true, since loop/recur allows
for short-circuiting, and does not require a sequence as one of its
arguments. So loop/recur is more general than reduce. Sorry about
that.)

I think we want a variety of forms for the same reason Common Lispers
want DOTIMES, LOOP, etc. -- pragmatism.

 For example, CL provides `do-symbols', `do-all-symbols' or `with-
 package-iterator' as external iterators.

 Clojure decided that anything that could be expressed as a `seq' could
 be iterated over using `doseq', so I can express the equivalent of
 CL's (do-symbols ...) using clojure (doseq [n all-ns] )

Yes, exactly -- abstract sequences are a super idea, and make a lot of
special-case procedures unnecessary.

 To rephrase the question differently, what could exist that is not a
 clojure `seq' that we would want to iterate over?

 Clojure already answers this (partially?) by providing (dotimes ...)
 (as CL does) to iterate over a zero based consecutive and finite
 sequence of numbers. Though the same (dotimes ...) could be _used_ to
 iterate over any finite range)

I'd argue that dotimes iterates, but doesn't iterate *over* anything
-- there's no Clojure sequence involved.

 What are the things that one could iterate over, for which clojure
 does not, currently, provide special cases à la `doseq' or 'dotimes' ?

Not special cases -- dotimes doesn't traverse a sequence, and doseq
can be thought of as a map that is evaluated immediately, for
side-effects, and which discards the result of the map. (Like for-each
in Scheme, compared with map in Scheme -- the former is for
side-effects, the latter to produce a transformed list.)

Clojure's concept of the 'seq' as the object of traversal, rather than
a literal type (list, vector, etc.) is its fundamental genius, IMHO.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: doseq, dotimes loop/recur

2008-11-08 Thread Graham Fawcett

On Sat, Nov 8, 2008 at 4:23 PM, verec
[EMAIL PROTECTED] wrote:
 Everything that can be interpreted as a `seq', clojure's `doseq' takes
 care of it.

 What I am after are the special cases for things one could somehow
 enumerate but are not a `seq'.

 A number range is one such thing, and clojure provides 'dotimes' to
 handle this case.

 What could be the XYZ that are neither a `seq' nor a number range, for
 which we would want a `doXYZ' ?

 In other words, is the set `doseq', `dotimes' and `doall' complete,
 and if not, what is missing?

Of course, dotimes could be implemented in terms of doseq, e.g.

(dotimes i n ...)
(doseq i (take n (iterate inc 0)) ...)

so really there aren't any special cases in Clojure. I can't think of
anything that is sequence-like but couldn't be represented as a seq,
so I think the bases are covered. :-)

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Having struggle in understanding FP (and Clojure question)

2008-11-07 Thread Graham Fawcett

On Fri, Nov 7, 2008 at 12:25 AM, cwyang [EMAIL PROTECTED] wrote:

 My expectation is these:
 1) For C10K problem (or C100K), application must not use
 native threads. Big stack size means low concurrency

Hi,

I assume you mean 'new native thread per request' is bad for CnK.
Clojure's thread-pooling is not very different from the N:M threading
model that Erlang-OTP/Yaws uses, in a general sense.

 4) At the same time, there must be ways for connecting conceptual
 gap between 2) and 3). In other words, the way for suspending current
 execution of function, saving current execution snapshot
 (normally native thread stack, but may be different),
 and switching to other functions are needed when the request for I/O
 should be blocked. It's important that the size of current execution
 snapshot should be small, since it determine the degree of
 concurrency.

Sounds like you're looking for first-class continuations here.You
won't find that on any JVM language, there's no JVM support for them.
(It is true that JVM-based Scheme languages have continuations, but
they are severely limited by the constraints of the JVM).

If you really believe you need this, you might be interested in
Termite, an Erlang-style actor system written for Gambit Scheme (which
has serializable first-class continuations and very lightweight
threads, but no SMP support if I remember correctly).

An alternative would be to use non-blocking I/O multiplexing -- an
event-driven model like you would write with select() or epoll(). I
don't know the Java universe very well, but I know JVM has
asynchronous I/O, so this must be an available option. Writing such
programs can sometimes lead to hard-to-understand, fragmented
application code, but Clojure's flexible syntax might be able to help
unify the fragments into a more readable form.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Print compiled Clojure svn revision?

2008-11-07 Thread Graham Fawcett

On Fri, Nov 7, 2008 at 1:15 PM, Rich Hickey [EMAIL PROTECTED] wrote:



 On Nov 7, 1:02 pm, Graham Fawcett [EMAIL PROTECTED] wrote:
 On Fri, Nov 7, 2008 at 11:46 AM, vdm [EMAIL PROTECTED] wrote:

  Is there a way to make Clojure print the svn revision it was compiled
  from? A standard or idiomatic way to do this (print clojure--svn-rev)
  would help when trying to isolate whether observed behaviour is
  happening on old or current code.

 Hi, as far as I know, no. But I agree it would be great to have, and
 is certainly possible to do.

 If Rich would be willing to add this to boot.clj,

 (defn clojure-svn-revision []
   (if-let rev (re-find #Rev: (\d+) \$ $Rev$)
   (second rev)
   unknown))

 and then do this,

 svn propset svn:keywords Revision boot.clj
 svn commit boot.clj

 ...then (clojure-svn-revision) ought to return the revision number as
 a string.


 This works by making $Rev$ magic in some way?

Yes, exactly. See
http://svnbook.red-bean.com/en/1.1/ch07s02.html
in the keywords section.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Print compiled Clojure svn revision?

2008-11-07 Thread Graham Fawcett

On Fri, Nov 7, 2008 at 2:25 PM, Daniel Renfer [EMAIL PROTECTED] wrote:

 This wouldn't work if someone is using a mirror of the repository
 using a different SCM.

No, but it would still include the upstream SVN revision number.

Alas, what I thought was possible with SVN hooks appears to be
impossible -- while in an SVN commit transaction, the SVN server
cannot say and also touch this file over here if that file was not
part of the commited patch.

It seems the best alternative is to let Ant try to get the SVN
revision and push in the change, as Chouser suggested.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: sequence question and style question

2008-11-05 Thread Graham Fawcett

On Wed, Nov 5, 2008 at 12:56 PM, Stuart Halloway
[EMAIL PROTECTED] wrote:

 (1) Is there a simpler way to define pairwise, which takes an existing
 sequence and then returns its items a pair at a time?

 (defn pairwise [ seq]
  (map vector (take-nth 2 seq) (take-nth 2 (rest seq

The built-in (partition) function does this, no?

(partition 2 my-seq)

Best,
Graham



 (2) When writing a function like pairwise, are there any bright-line
 rules about whether to use variable arity?

 Cheers,
 Stuart


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Concerned about Clojure's license choice.

2008-11-05 Thread Graham Fawcett

On Wed, Nov 5, 2008 at 12:53 PM, Matthias Benkard [EMAIL PROTECTED] wrote:

 On Nov 5, 3:33 pm, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:
 Are you sure? You're not modifying the clojure source, so you're not
 creating a derivative work. I would think you can create a GPL
 licensed library in that case.

 I can, but noone else will be allowed to redistribute it or works
 based upon it because the GPL disallows combining the work with CPL'd
 code.

 Imagine this scenario: There's a GPL'd Java library A.  Its license
 disallows combining it with something CPL'd like Clojure.  I can't
 release a programme based upon both Clojure and A because by doing so,
 I'd be combining A with Clojure.

Hi,

But you could release your program, and your installer could download
library A and install it, no? The sticking point is in redistribution,
not installation or use.

Best,
Graham



 The CPL doesn't care, but the GPL does.  I should probably have stated
 this more explicitely.


 Anyone who uses your library and
 distributes the result would have to GPL their work.

 If I create a library and put a GPL + special Clojure
 exception (analogous to the OpenSSL exception that is so common) on
 it (or maybe a GPL + CPL exception or whatever), then yes, something
 like that will be the result.  And that would be a fine situation, if
 Clojure code could only call other Clojure code.  But obviously, most
 GPL'd Java libraries don't do this, if only for the fact that their
 authors didn't know or care about Clojure when they started their
 project.


 It's analagous to claiming that Intel
 have to GPL their design for the x86 chips that Linux runs on, because
 Linux itself is GPL.

 This analogy seems to evade my mind.

 Matthias
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: sequence question and style question

2008-11-05 Thread Graham Fawcett

On Wed, Nov 5, 2008 at 2:00 PM, Stuart Halloway
[EMAIL PROTECTED] wrote:

 Duh. Thanks, and I will be adding that to the sequences chapter. :-/

 Stuart

You're welcome -- looking forward to the book!

Best,
Graham




 On Wed, Nov 5, 2008 at 12:56 PM, Stuart Halloway
 [EMAIL PROTECTED] wrote:

 (1) Is there a simpler way to define pairwise, which takes an
 existing
 sequence and then returns its items a pair at a time?

 (defn pairwise [ seq]
 (map vector (take-nth 2 seq) (take-nth 2 (rest seq

 The built-in (partition) function does this, no?

 (partition 2 my-seq)

 Best,
 Graham



 (2) When writing a function like pairwise, are there any bright-line
 rules about whether to use variable arity?

 Cheers,
 Stuart





 


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: (source name)

2008-11-03 Thread Graham Fawcett

On Sun, Nov 2, 2008 at 6:34 PM, Mark McGranaghan [EMAIL PROTECTED] wrote:

 I really like being able to find and check documentation in the REPL
 with find-doc and doc, but I often would like to see the source code
 of a function or macro to be able to understand it better or learn
 from the implementation.

Hi Mark,

Just FYI, if you use Clojure through Emacs/Slime, you already have
this functionality. The command slime-edit-definition, or M-.
(meta-key period), will open the source for whatever name is currently
under your cursor.

Best,
Graham




 To do this I switch into an editor with
 boot.clj, find and read the source, then switch back into the REPL.
 Doing this a lot got me thinking, what if we could just do e.g.

 user= (source filter)
 (defn filter
  Returns a lazy seq of the items in coll for which
  (pred item) returns true. pred must be free of side-effects.
  [pred coll]
(when (seq coll)
  (if (pred (first coll))
(lazy-cons (first coll) (filter pred (rest coll)))
(recur pred (rest coll)
 nil
 user=

 This might also be also be useful for programatically generating
 documentation with handy view source links.

 I was think for the source macro something like:
 (defmacro source
  Prints the source text of the top-level form in which var was
 created.
  [name]
  `(if-let src-txt# (:source (meta (var ~name)))
 (println src-txt#)
 (println no source found

 For that to work we would need a :source meta value like we currently
 have for :line and :file.

 My questions then are:
 - Does the general idea of a source macro or something similar sound
 useful? Am I missing something that renders such a feature
 unnecessary?
 - How might one implement the source macro and the associated support
 in the reader/compiler?

 Thanks for your thoughts,
 - Mark




 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: string interpolation

2008-10-29 Thread Graham Fawcett

On Wed, Oct 29, 2008 at 1:27 PM, Kyle R. Burton [EMAIL PROTECTED] wrote:

 Thanks for the macro. =)
 The str function is really a good replacement for interpolation.

 Yes, thank you for the macro.  I anticipate using this approach (I'm
 accustomed to it from Ruby, Perl and JScheme), but wanted to support a
 way of stopping the parser (by backslashing the opening brace:
 $\\{x} ).  I think adding the zero-width assertion in the re-matcher
 and the replaceAll to knock the backslash out gets me there:

You're very welcome! The backslash-fix makes good sense.

Graham


 (defn tokenize [s]
  (let [positions (let [mm (re-matcher #\\$(?!)\\{.*?\\} s)]
   (loop [acc []]
 (if (.find mm)
   (recur (conj acc [(.start mm) (.end mm)]))
   acc)))
   intermed (conj (apply vector 0 (apply concat positions))
  (.length s))
   textposns (partition 2 intermed)]
   (my-interleave (map (fn [[a b]] [:text (. (.substring s a b)
 (replaceAll \\$\\{ 
 \\${))])
   textposns)
  (map (fn [[a b]] [:pat (.substring s (+ a 2) (- b 1))])
   positions

 Regards,

 Kyle Burton


 On Oct 28, 8:29 pm, Graham Fawcett [EMAIL PROTECTED] wrote:
 On Tue, Oct 28, 2008 at 7:27 PM, Graham Fawcett

 [EMAIL PROTECTED] wrote:
  But for fun, here's an (i ...) macro, that will give you ${}
  interpolation in strings (if it works at all, I test it very
  thorougly!).

 Haha, nor did I spell- or grammar-check very thoroughly!

 I meant: I didn't test the code very thoroughly, so I hope it works at all.

 Graham
 


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Newbie question: testing if an object is a Struct of a certain kind

2008-10-29 Thread Graham Fawcett

On Wed, Oct 29, 2008 at 2:29 PM, samppi [EMAIL PROTECTED] wrote:

 Is there a way to test an object if it's a certain kind of struct?

  (defstruct person :name :age)
  (def president (struct person Sam 30))
  (struct? person president) ; true

Hi,

Defstruct doesn't define a new type in the OO sense. You can test for
presence of keys, e.g.

(every? #{:name :age} (keys president))

will return true, because 'president' has both :name and :age keys.
But other structures might also have these keys, so this is duck
typing at best.

Others have suggested using metadata to tag struct values with type
information -- that might be an option you prefer over
key-comparision.

Best,
Graham


 Thanks in advance.


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: string interpolation

2008-10-28 Thread Graham Fawcett

On Mon, Oct 27, 2008 at 11:38 PM, Islon [EMAIL PROTECTED] wrote:
 Is there any chance closure will get string interpolation?

 Do things like (prn Hi ${someone}, my name is ${myname}) is nice, not
 crucial of course, but nice.

I'm personally not fond of string interpolation either.

But for fun, here's an (i ...) macro, that will give you ${}
interpolation in strings (if it works at all, I test it very
thorougly!).


(defn my-interleave [a b]
  Like interleave, but uses all elements from both lists.
  (loop [acc [] a a b b]
(if (and (nil? a) (nil? b))
  acc
  (let [acc2 (if (nil? a)
   acc
   (conj acc (first a)))
acc3 (if (nil? b)
   acc2
   (conj acc2 (first b)))]
(recur acc3 (rest a) (rest b))

(defn read-from-string [s]
  (read (java.io.PushbackReader. (java.io.StringReader. s

(defn tokenize [s];; not pretty but it works.
  (let [positions (let [mm (re-matcher #\\$\\{.*?\\} s)]
(loop [acc []]
  (if (.find mm)
(recur (conj acc [(.start mm) (.end mm)]))
acc)))
intermed (conj (apply vector 0 (apply concat positions))
   (.length s))
textposns (partition 2 intermed)]
(my-interleave (map (fn [[a b]] [:text (.substring s a b)]) textposns)
   (map (fn [[a b]] [:pat (.substring s (+ a 2) (- b 1))])
positions

(defmacro i [s]
  (apply list 'str
 (map (fn [[type value]]
(if (= type :text)
  value
  (read-from-string value)))
  (tokenize s

;; test

(let [greeting Hello name Fred age 33]
  (prn (i ${greeting}, my name is ${name} and my age is ${age}.)))


-- Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: string interpolation

2008-10-28 Thread Graham Fawcett

On Tue, Oct 28, 2008 at 7:27 PM, Graham Fawcett
[EMAIL PROTECTED] wrote:
 But for fun, here's an (i ...) macro, that will give you ${}
 interpolation in strings (if it works at all, I test it very
 thorougly!).

Haha, nor did I spell- or grammar-check very thoroughly!

I meant: I didn't test the code very thoroughly, so I hope it works at all.

Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-10-17 Thread Graham Fawcett

Windsor, Ontario, Canada. (Just down the road, Mark!)

Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: (map f coll) using memfn

2008-10-15 Thread Graham Fawcett

On Wed, Oct 15, 2008 at 8:21 AM, Jim Menard [EMAIL PROTECTED] wrote:

 On Wed, Oct 15, 2008 at 7:46 AM, Timothy Pratley
 [EMAIL PROTECTED] wrote:

 Can I get some help with (map f coll)...

 What I want to do is map a java function that takes 2 arguments over a
 list
 where the first argument is the index into the list itself
 and the second argument is taken from the list

 The problem being map uses a function of 1 argument.
 Does that mean I need to create my own map, or is there a better way?

 map can take more than one argument. If it has N arguments, it calls f
 with N arguments, each taken from the Nth value of each collection. So
 you should be able to pass in an infinite sequence like this UNTESTED
 code:

  (map f coll (range (count coll)))

Rather than (range (count coll)), I would use (iterate inc 0), which
incurs no overhead for counting the argument.

Best,
Graham

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---