Re: Clojure at JavaOne

2009-05-22 Thread Brian Doyle
I have a one pagish program that you pass in your screen resolution and it
randomly picks out a new
desktop image from ftp.gnome.org, downloads the image and updates your
desktop.  This assumes
your using Gnome.

http://github.com/heyZeus/clojure-stuff/blob/0c81123fcb3dc4bafa0df94b6e32dc49729595d3/update-desktop-image.clj

On Fri, May 22, 2009 at 5:33 AM, Rich Hickey richhic...@gmail.com wrote:




 On May 22, 7:16 am, Rich Hickey richhic...@gmail.com wrote:
  On May 21, 11:38 pm, Adrian Cuthbertson adrian.cuthbert...@gmail.com
  wrote:
 
   ... impact part can be merged with the business application mindset
 by
   generating a report that includes the data visualization (I think PDF
   generation is built into processing).
 
   I've been doing some work with enlive and XHtmlRenderer - it's a
   pretty awesome way of generating (business, media, etc)  PDF docs from
   html templates, css style sheets and clojure generated data. I could
   post some examples if there's any interest.
 
  Sure, please do.
 


 Actually, let me extend that invitation  - if anyone's got a small
 (one-page-ish) Clojure program that does something interesting, and
 are willing to have it demonstrated at JavaOne, please paste it
 somewhere and post a note here.

 Thanks,

 Rich
 


--~--~-~--~~~---~--~~
You 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: HTTP clients in clojure

2009-05-06 Thread Brian Doyle
I wrote clj-web-crawler which wraps the Apache commons client library and
made it suck
a little bit less.   I haven't tested it out with the Clojure 1.0 release
just yet, but I'll do that
tonight.

http://github.com/heyZeus/clj-web-crawler/tree/master

On Wed, May 6, 2009 at 7:16 PM, Chris Dean ctd...@sokitomi.com wrote:



 Eric Tschetter eched...@gmail.com writes:
  Last I checked the various clojure libraries, it seemed like noone has
  publicized a set of wrappers/clojure-native implementation of an http
  client.

 There is (slurp* url) and (reader url) in clojure.contrib.duck-streams

   (count (slurp* http://google.com;))  =  4675

 Cheers,
 Chris Dean

 


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



Clojure Library

2009-04-20 Thread Brian Doyle
I posted this a couple of weeks ago and haven't seen it updated on the
clojure
website.  Maybe it got lost in the shuffle.


Name: clj-web-crawler
URL: http://github.com/heyZeus/clj-web-crawler/tree/master
Author: Brian Doyle
Categories: Web, Automation
License: MIT
Dependencies: clojure, clojure-contrib, Apache commons-client 3.1
Description:
clj-web-crawler is a wrapper around the Apache commons-client Java
library that allows you to easily crawl the web in a functional way.

--~--~-~--~~~---~--~~
You 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: Got a Clojure library?

2009-04-09 Thread Brian Doyle
Name: clj-web-crawler
URL: http://github.com/heyZeus/clj-web-crawler/tree/master
Author: Brian Doyle
Categories: Web, Automation
License: MIT
Dependencies: clojure, clojure-contrib, Apache commons-client 3.1
Description:
clj-web-crawler is a wrapper around the Apache commons-client Java
library that allows you to easily crawl the web in a functional way.


On Wed, Apr 8, 2009 at 9:16 AM, Rich Hickey richhic...@gmail.com wrote:


 Added - thanks!

 Rich

 On Apr 8, 2009, at 3:43 AM, Remco van 't Veer wrote:

 
  Name: clj-android
  URL: http://github.com/remvee/clj-android/
  Author: Remco van 't Veer
  Categories: android framework
  License: MIT
  Dependencies: clojure
  Description:
  Basic application framework for building Android applications using
  Clojure.
 
  


 


--~--~-~--~~~---~--~~
You 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: [ANN] clojuredev 0.0.30 released

2009-04-05 Thread Brian Doyle
If I wanted to download and play with clojuredev where would I find it?

On Sat, Apr 4, 2009 at 3:58 PM, Laurent PETIT laurent.pe...@gmail.comwrote:


 New release, with a lot of changes!

 I would particularly like to thank Stephan Mühlstrasser for his
 contributions !
 The clojure symbols omni-completion feature was also quickly made available
 thanks to Meikel Brandmeyer's help and code :-)

 IMPORTANT NOTE: the layouts of the plugins that host clojure and
 clojure-contrib code have changed. So for your projects that use the
 out-of-the-box versions of these jars, you may have to manually fix it: go
 to the project's context menu  Properties  Java Build Path  Libraries.
 Remove the clojure and clojurecontrib classes directories. Instead, add
 external jars for clojure and clojurecontrib, located in your eclipse
 plugins directory : %ECLIPSE_HOME%/plugins/clojure/clojure.jar and
 %ECLIPSE_HOME%/plugins/clojurecontrib/clojure-contrib.jar

 Below the list of changes:

 1. User visible changes

 1.a) new features
  * Patch from Stephan Mühlstrasser
* inheritance of standard editorpreferences
  * user-editable preferences
* Currently you can switch on and off the bracket matching, and
 change the tab width
  * Added an (configurable via preferences) auto-switch to the loaded file
 namespace when a REPL is launched via the selection of a file (uses the
 last found ns call in the file)
  * Change of the default REPL to use clojure.contrib.repl_ln
  * Enhancement of the syntax coloring:
* more colorized types of symbols
* now defaults to colors similar to those used by emacs clojure mode
* uses a dynamically created symbol table for clojure core symbols
 (special symbols, macros, functions) for coloring clojure symbols
   * code completion :
* added omni-completion on clojure symbols (e.g. w-o resolves to
 with-out)
* added limits to the search to prevent the IDE from hanging too long:
  * prefix must not be less than 3 characters
  * java search halts if more than 200 results are matched (only those
 200 results are proposed, with a warning message at the bottom of the
 completion box)

 1.b) bug fixed
  * the namespace browser now sorts namespace names and symbol names by
 natural ascending order

 2. Technical changes

  * Tweaked the settings of clojure, clojurecontrib and clojuredev Eclipse
 plugins to enable clojure's driven clojuredev code by adding buddy policy
 (registered)
  * Made code sent to the REPL more robust (namespace qualify the used
 symbols)

 Enjoy !

 


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



advice needed converting large files to xml

2009-03-16 Thread Brian Doyle
I've been using Clojure for about 6 months now and really like it.  I am
somewhat new to multi-threading
and using any of the parallel features in Clojure though.   I have a
situation where I need to convert
7 files from CSV to XML.  Each one of these files is about 180MB apiece in
size.   I have dual core machine
with 2GB of RAM and would like some advice on the best strategy for
processing these files in a way that
really utilizes both cores and my memory to really speed up the
processing.I'm sure this isn't the best
way, but I've only come up with starting up two threads at first, having
each thread open up a file,
call line-seq on that file, write out the XML for each line and then go to
the next file when it's complete.   Any
advice would be great.  Thanks.

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



Re: advice needed converting large files to xml

2009-03-16 Thread Brian Doyle
On Mon, Mar 16, 2009 at 4:21 PM, Stu Hood stuh...@gmail.com wrote:

 If you write your CSV - XML processing as a function, you could pmap (
 http://clojure.org/api#pmap)  that function across the list of input
 files. pmap will transparently create the threads as needed, and it will
 probably be enough to saturate your disk.

 Thanks,
 Stu


Stu,  I just want to make sure I understand what you are saying here.  Would
it look something like this:

(pmap (fn [input-file]
   ; open input for reading
   ; open output for writing
   ; read line
   ; process line
   ; write line
 )
 [input-file1, input-file2, input-file3, ])

Thanks.




 On Mon, Mar 16, 2009 at 5:56 PM, Brian Doyle brianpdo...@gmail.comwrote:

 I've been using Clojure for about 6 months now and really like it.  I am
 somewhat new to multi-threading
 and using any of the parallel features in Clojure though.   I have a
 situation where I need to convert
 7 files from CSV to XML.  Each one of these files is about 180MB apiece in
 size.   I have dual core machine
 with 2GB of RAM and would like some advice on the best strategy for
 processing these files in a way that
 really utilizes both cores and my memory to really speed up the
 processing.I'm sure this isn't the best
 way, but I've only come up with starting up two threads at first, having
 each thread open up a file,
 call line-seq on that file, write out the XML for each line and then go to
 the next file when it's complete.   Any
 advice would be great.  Thanks.




 


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



Re: advice needed converting large files to xml

2009-03-16 Thread Brian Doyle
On Mon, Mar 16, 2009 at 4:29 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote:


 On Mon, Mar 16, 2009 at 4:56 PM, Brian Doyle brianpdo...@gmail.com
 wrote:
  I've been using Clojure for about 6 months now and really like it.  I am
  somewhat new to multi-threading
  and using any of the parallel features in Clojure though.   I have a
  situation where I need to convert
  7 files from CSV to XML.  Each one of these files is about 180MB apiece
 in
  size.   I have dual core machine
  with 2GB of RAM and would like some advice on the best strategy for
  processing these files in a way that
  really utilizes both cores and my memory to really speed up the
  processing.I'm sure this isn't the best
  way, but I've only come up with starting up two threads at first, having
  each thread open up a file,
  call line-seq on that file, write out the XML for each line and then go
 to
  the next file when it's complete.   Any
  advice would be great.  Thanks.

 Most libraries that write XML build a data structure to represent the
 XML and then write it out. That doesn't work for writing out large XML
 documents because you'll run out of memory before you finish building
 the data structure.

 I don't know if there is a Clojure library that writes XML as you
 specify it. If there isn't then you should consider WAX, a Java
 library I wrote. You can learn more about it at
 http://ociweb.com/wax/. You could use it from Clojure. Check out the
 tutorial. It's a really simple library, it's really fast and it's very
 memory efficient!


Mark,

WAX looks really nice!  I'll look around in Clojure some more about writing
XML but if I don't find anything to my linking I'll give WAX a go.  Thanks!



 --
 R. Mark Volkmann
 Object Computing, Inc.

 


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



clj-web-crawler

2009-03-09 Thread Brian Doyle
I wrote a Clojure script that wraps the Apache commons-client library for
crawling the web.   It's a simple 125 line script and I also wrote some test
cases for it as well.  I was wondering if this is something that
could/should
be included in clojure.contrib or if it should be a standalone Clojure
library?
The code is here if you want to check it out:

http://github.com/heyZeus/clj-web-crawler/tree/master

--~--~-~--~~~---~--~~
You 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: sequences from Enumerations

2009-03-02 Thread Brian Doyle
I had the same issue and ended up having to use enumeration-seq function.
Seems
strange but it worked.

On Mon, Mar 2, 2009 at 4:22 PM, Mark Volkmann r.mark.volkm...@gmail.comwrote:


 Should I be able to do something like this?

 (doseq [table-column (- jtable .getColumnModel .getColumns)]

 javax.swing.JTable has a getColumnModel method that returns a
 TableColumnModel.
 TableColumnModel has a getColumns method that returns
 EnumerationTableColumn.
 I was hoping that would automatically be treated as a sequence, but I get

 java.lang.IllegalArgumentException: Don't know how to create ISeq from:

 --
 R. Mark Volkmann
 Object Computing, Inc.

 


--~--~-~--~~~---~--~~
You 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: sequences from Enumerations

2009-03-02 Thread Brian Doyle
That makes sense now.  Thanks for the link to the thread.

On Mon, Mar 2, 2009 at 5:01 PM, Stephen C. Gilardi squee...@mac.com wrote:


 On Mar 2, 2009, at 6:37 PM, Brian Doyle wrote:

  I had the same issue and ended up having to use enumeration-seq function.
  Seems
 strange but it worked.


 The seq function is not able to provide a seq on either an Enumeration or
 an Iterator.

 clojure.core provides enumeration-seq and iterator-seq to create seqs on
 them.

 The rationale for this is contained in this thread:


 http://groups.google.com/group/clojure/browse_thread/thread/decbd098646353c/7a78ebf588bf0f7e?lnk=gstq=iterator-seq#7a78ebf588bf0f7e

 --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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Importing lots of Java classes at once

2009-02-24 Thread Brian Doyle
I wrote something similar to what you are asking about.  My
code does not import java class files but calls 'use' on clojure
files that live in the clojure-contrib.jar file.   I load this when I
start the REPL only.


(defn name-to-symbol [lib-name]
  Converts the lib-name to a symbol
(- lib-name (.replaceFirst .clj$ ) (.replaceAll  _ -)
(.replaceAll / .) (symbol)))

(defn contrib-ns [jar]
  Returns a seq of symbols from the clojure.contrib package, is not
recursive
  (for [f (map #(.getName %)
   (enumeration-seq (.entries (java.util.zip.ZipFile. jar
:when (and (.endsWith f clj)
   (= 3 (count (.split f /)))
   (not (or (.endsWith f test_clojure.clj) (.endsWith f
test_contrib.clj]
(name-to-symbol f)))

;sets the variable to the colure-contrib.jar path, otherwise nil
(def contrib-jar (if-let [url (.getResource
(ClassLoader/getSystemClassLoader) clojure-contrib.jar)]
   (.getFile url)))

(defn use-contribs []
  Calls the use function on every clj file in the clojure.contrib package.
Not every clj file can
  be loaded because of function name clashes with the core.
  (if contrib-jar
(println (str use  (reduce (fn [ret n]
  (try
(use n)
(conj ret n)
(catch Exception _ ret))) []
(contrib-ns contrib-jar))


On Fri, Feb 20, 2009 at 10:48 PM, Jason Wolfe jawo...@berkeley.edu wrote:


 I have a horrible hack to do this, which uses even more appalling code
 than [2] ripped off from a different forum, but which (in my limited
 experience) seems to work OK.  I'll email it to you privately, and to
 anyone else who wants to use it (just ask).

 -Jason

 On Feb 20, 9:33 pm, Brian Carper briancar...@gmail.com wrote:
  One could argue that wildcard imports in Java (import package.*) are
  evil, pollute your namespaces, create potential naming conflicts,
  etc.  One would probably be correct.
 
  One could also argue that having to manually type a list of dozens of
  classnames is pretty tedious, especially if all you want to do is goof
  off at a REPL for a few minutes.  e.g. I wanted to run some SWT
  snippets [1], and to import all the necessary SWT classes into Clojure
  can be a bit of a pain.
 
  I found this somewhat appalling bit of code [2] which I can use to get
  a list of all the classnames in some package and then import them all
  that way.  There are all kinds of ways that code can fail though.
  Does anyone else have a way that they routinely import lots and lots
  of Java classes at once?  I don't care how dirty a hack it is, I'm not
  going to do this in production code.  I only want to save my fingers a
  bit of typing.
 
  I know this probably isn't planned [3] for Clojure, just looking for
  the best workaround.
 
  [1]:http://www.eclipse.org/swt/snippets/
  [2]:http://forums.sun.com/thread.jspa?threadID=341935start=30tstart=0
  [3]:
 http://groups.google.com/group/clojure/browse_thread/thread/c65e19d51...
 


--~--~-~--~~~---~--~~
You 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: Newbie: Separating and grouping the elements in a bunch of vectors

2009-02-15 Thread Brian Doyle
From the original question it looked like there was a vector of unknown
length of vectors

[[a0 a1 a2] [b0 b1 b2] ...]

So my solution is something like:

1:12 user= (def vecs [[:a0 :a1 :a2] [:b0 :b1 :b2]])
#'user/vecs
1:13 user= (partition (count vecs) (interleave (flatten vecs)))
((:a0 :a1) (:a2 :b0) (:b1 :b2))

This doesn't return a sequence of vectors and just a sequence of sequences.
I'm sure it can be done, but it's not clear to me if you have a vector of
vectors
how Stuart's solution would work:

1:15 user= (map vector vecs)
([[:a0 :a1 :a2]] [[:b0 :b1 :b2]])


On Sun, Feb 15, 2009 at 7:54 PM, David Nolen dnolen.li...@gmail.com wrote:

 Of course ;) Keep forgetting the obvious things.


 On Sun, Feb 15, 2009 at 9:36 PM, Stuart Halloway 
 stuart.hallo...@gmail.com wrote:


 (map vector [1 2 3] ['a 'b 'c] [cat dog bird])
 - ([1 a cat] [2 b dog] [3 c bird])

  Actually something closer to your exact expression is this:
 
  (apply (partial map (fn [ rest] (apply vector rest))) [[1 2 3] ['a
  'b 'c] [cat dog bird]])
 
  On Sun, Feb 15, 2009 at 7:42 PM, David Nolen
  dnolen.li...@gmail.com wrote:
  (map (fn [ rest] (apply vector rest)) [1 2 3] ['a 'b 'c] [cat
  dog bird])
 
 
  On Sun, Feb 15, 2009 at 7:16 PM, samppi rbysam...@gmail.com wrote:
 
  What would I do if I wanted this:
 
  [[a0 a1 a2] [b0 b1 b2] ...] - [[a0 b0 ...] [a1 b1 ...] [a2 b2 ...]]
 
  I could write a loop, I guess, but is there a nice, idiomatic,
  functional way of doing this? I didn't spot a way in
  clojure.contrib.seq-utils either.
 
 
 
 
  





 


--~--~-~--~~~---~--~~
You 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: Denver/Boulder Clojure users

2009-02-05 Thread Brian Doyle
I live in southeast Denver and have been doing some Clojure on my own for a
few months now.

On Thu, Feb 5, 2009 at 12:39 PM, chris cnuern...@gmail.com wrote:


 Are there any existing clojure users in the Denver/Boulder area (other
 than me)?.

 Chris
 


--~--~-~--~~~---~--~~
You 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: symbols, vars and namespaces

2009-01-27 Thread Brian Doyle
On Tue, Jan 27, 2009 at 7:43 AM, Chouser chou...@gmail.com wrote:


 On Tue, Jan 27, 2009 at 8:51 AM, Mark Volkmann
 r.mark.volkm...@gmail.com wrote:
 
  Are these statements correct? Actually, I know some are correct
  because I just looked though the source. Hopefully others that haven't
  will find this interesting.
 
  Symbol objects have a String name and a String namespace name, but no
 value.
  Var objects have references to a Symbol object, a Namespace object and
  an Object object which is its root value.
  Namespace objects have a reference to a Map that holds associations
  between Symbol objects and Var objects.
  In Clojure, the term interning typically refers to adding a
  Symbol-to-Var mapping to a Namespace.

 Those all sound right to me, with the (very minor) caveat that
 Namespaces also have a aliases map.

  Why don't Symbol objects have a reference to a Namespace object
  instead of a String that is a Namespace name?

 The namespace part of a symbol doesn't have to refer to any existing
 namespace.  This is useful for example when using the symbol as its
 own value.

 user= (namespace 'foo/bar)
 foo

 The namespace part can even be 'nil', which is probably the most
 common case for symbols created by the reader:

 user= (def expr (read (java.io.PushbackReader. (java.io.StringReader.
 (+ 1 2)
 user= (first expr)
 +
 user= (namespace (first expr))
 nil


This nil namespace seems a bit odd.  Wasn't expr created in the user
namespace?



 Or even just:

 user= (namespace 'zipmap)
 nil

 --Chouser

 


--~--~-~--~~~---~--~~
You 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: *1 *2 isn't working properly

2009-01-14 Thread Brian Doyle
Here's an example of *1 *2 *3

1:1 user= (str gavin)
gavin
1:2 user= (str teri)
teri
1:3 user= (str brian)
brian
1:4 user= (str-join   [*1 *2 *3])
brian teri gavin


On Wed, Jan 14, 2009 at 2:29 AM, Stephen C. Gilardi squee...@mac.comwrote:


 By the time you evaluated *2, the second most recent result was what
 it showed you. All top level evaluations count.

 In short, you were Heisenberged.

 --Steve

 On Jan 14, 2009, at 3:59 AM, HB hubaghd...@gmail.com wrote:

 
  Hey,
  I'm trying to run my first Clojure example
 
  user= (defn hello [name] (str Cool!  name))
  #'user/hello
  user= (hello Google)
  Cool! Google
  user= (hello Wicket)
  Cool! Wicket
  user= (str *1)
  Cool! Wicket
  user= (str *2)
  Cool! Wicket
 
  Isn't (str *2) supposed to return Cool! Google ?
  Environment:
  Clojure20081217
  Ubuntu 8.04
 
  Thanks.
 
  


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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: Setting a value inside a map of map of maps...

2009-01-11 Thread Brian Doyle
I think you can just use the update-in function like:

1:1 user= (def m {:a {:b {:c {:d 3)
#'user/m

1:2 user= (update-in m [:a :b :c :d] - 5)
{:a {:b {:c {:d -2


On Sun, Jan 11, 2009 at 11:08 AM, CuppoJava patrickli_2...@hotmail.comwrote:


 Hi,
 I'm just wondering if there's a clever way of creating a new map from
 an existing map of map of maps.. with a key deep inside altered.

 ie. given this map: {:a {:b {:c {:d 3

 i want to create a new map, with the value at :d increased by 5.

 I wrote a macro to do this, but it's quite ugly.

 Thanks for the tip
  -Patrick

 --
 In case this helps at all, this is the macro that I wrote.
 Usage: (set_map mymap [:a :b :c :d] (+ it 5))

 (defmacro -set_map [mymap mykeys expr]
  (let [syms (take (dec (count mykeys))
   (repeatedly gensym))
bindings (interleave
  (concat syms ['it])
  (map list
   mykeys
   (concat [mymap] syms)))]
`(let [...@bindings]
   ~((fn assoc_fn [maps keys expr]
   (if (empty? keys)
 expr
 `(assoc ~(first maps) ~(first keys)
 ~(assoc_fn (rest maps) (rest keys) expr
 (concat [mymap] syms) mykeys expr

 (defmacro set_map [map keys expr]
  `(let [map# ~map]
 (-set_map map# ~keys ~expr)))
 


--~--~-~--~~~---~--~~
You 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: How can I find all files ending with .clj, for example

2009-01-08 Thread Brian Doyle
Here's one of many ways to do this:

(filter #(.endsWith (.getName %1) .clj ) (file-seq (java.io.File. .)))


On Thu, Jan 8, 2009 at 5:48 PM, wubbie sunj...@gmail.com wrote:


 Hi all,

 I can use file-seq
 (file-seq (File. .))
 But how can I filter out all files ending with .clj?
 Do we use re-find, re-seq etc?

 thanks
 sun

 


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



writing bytes to a file

2009-01-07 Thread Brian Doyle
I couldn't find anything in core or contrib that wrote out
bytes to a file so I wrote something to do it.   Is this
functionality already implemented and I just couldn't find
it?   If there isn't anything already, would this be something
good to put in contrib somewhere?  Thanks.

   (defn write-bytes
 Writes the bytes from the in-stream to the given filename.
 [#^java.io.InputStream in-stream #^String filename]
 (with-open [out-stream (new FileOutputStream filename)]
   (let [buffer (make-array (Byte/TYPE) 4096)]
 (loop [bytes (.read in-stream buffer)]
   (if (not (neg? bytes))
 (do
   (.write out-stream buffer 0 bytes)
   (recur (.read in-stream buffer

--~--~-~--~~~---~--~~
You 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: writing bytes to a file

2009-01-07 Thread Brian Doyle
Looks like spit is for printing just text.

On Wed, Jan 7, 2009 at 12:20 PM, Paul Barry pauljbar...@gmail.com wrote:

 clojure.contrib.duck_streams/spit?


 On Wed, Jan 7, 2009 at 2:14 PM, Brian Doyle brianpdo...@gmail.com wrote:

 I couldn't find anything in core or contrib that wrote out
 bytes to a file so I wrote something to do it.   Is this
 functionality already implemented and I just couldn't find
 it?   If there isn't anything already, would this be something
 good to put in contrib somewhere?  Thanks.

(defn write-bytes
  Writes the bytes from the in-stream to the given filename.
  [#^java.io.InputStream in-stream #^String filename]
  (with-open [out-stream (new FileOutputStream filename)]
(let [buffer (make-array (Byte/TYPE) 4096)]
  (loop [bytes (.read in-stream buffer)]
(if (not (neg? bytes))
  (do
(.write out-stream buffer 0 bytes)
(recur (.read in-stream buffer





 


--~--~-~--~~~---~--~~
You 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: Very noob file reading and printing question

2009-01-06 Thread Brian Doyle
On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst tom.aye...@gmail.com wrote:

 Its not the println, nor getting a reader (duckstreams is fine, I can do
 that). Its the converting it to a seq and stepping through it printing each
 element (which should be a line). Its the loopy, steppy bit, just for a side
 effect; that I am messing up.

 Cheers

 Tom


I've done this type of thing and it worked great for me.

   (with-open [r (clojure.contrib.duck-streams/reader filename.txt)]
   (doseq [line (line-seq r)]
   ; do stuff with the line here
  ))

Basically you'll want to use the line-seq function.  Hopefully that helps.


 2009/1/6 Mark Volkmann r.mark.volkm...@gmail.com


 On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst tom.aye...@gmail.com wrote:
  Hi,
 
  How do I read and print a text file?  I can read it, its the printing
 that
  is the problem, I feel it should be obvious but I keep tripping myself
 up.
  (The context is I need to extract data line by line, translate the line
  format and save it for a legacy app)

 Do you just need to print to stdout?
 The println function does that. It puts a space between the output of
 each of its arguments. If you don't want that you can use the str
 function to concatenate a bunch of string values together.
 If you need something fancier, don't forget that you can access
 everything in java.io from Clojure.

 --
 R. Mark Volkmann
 Object Computing, Inc.




 


--~--~-~--~~~---~--~~
You 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: Some code review for clj-record?

2009-01-04 Thread Brian Doyle
Looks good.  I didn't know about the *file* var.

On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume duelin.mark...@gmail.comwrote:


 Brian,
 I incorporated your changes and then made changes to load and run all
 clj_record/test/*-test.clj files. Thanks again.
 -hume.

 


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



finding all vars starting with *

2009-01-04 Thread Brian Doyle
Today I found out about the var *file*.  I looked it up *file* on
clojure.com/api and couldn't find anything.
Is there some place where all of these vars are defined?   Is there some way
programatically I can find
them all?  Thanks.

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

2009-01-04 Thread Brian Doyle
John,

I was looking at the validates method and I had a thought I'd bounce off
you.  Instead of
just returning a hash of errors what about returning the record with the
errors hash in
the metadata?   That way you just have the data and the errors in one
object similar
to an ActiveRecord model.

On Sun, Jan 4, 2009 at 2:22 PM, Brian Doyle brianpdo...@gmail.com wrote:

 Looks good.  I didn't know about the *file* var.

 On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume duelin.mark...@gmail.comwrote:


 Brian,
 I incorporated your changes and then made changes to load and run all
 clj_record/test/*-test.clj files. Thanks again.
 -hume.

 



--~--~-~--~~~---~--~~
You 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: Some code review for clj-record?

2009-01-02 Thread Brian Doyle
John,

I was looking around at your tests just to get a feel for using the test-is
stuff in the contrib library.  I noticed that when I ran main.clj it would
run
not only the tests in clj-record, but all of the tests in the
clojure.contrib
as well.  I was curious so I attempted to figure out what was going on
and what to do to only run the tests in clj-record.test.*.

I changed the end of the clj-record/test/main.clj script to this:

main.clj 
(def files [core-test validation-test associations-test])

(doseq [file files]
   (load file))

(def base-ns (re-find #^\w*.*\. (str *ns*)))

(apply test-is/run-tests (map #(symbol (str base-ns %)) files))
main.clj 

I also had to change the ns function in the associations-test.clj file
to match the name of the file.   The word 'associations' in the namespace
was just misspelled.

On Wed, Dec 31, 2008 at 9:39 AM, John D. Hume duelin.mark...@gmail.comwrote:


 Hi Brian,

 On Tue, Dec 30, 2008 at 11:41 AM, Brian Doyle brianpdo...@gmail.com
 wrote:
  (ns com.example.user)
(clj-record.core/init-model)
 
  but when I do that I get the error:
 
  java.lang.ClassNotFoundException: clj-record.core
 ...
  (first (reverse (re-split #\. (name (ns-name *ns*)
 
  and could be changed to:
 
  (last (re-split #\. (name (ns-name *ns*

 Those changes have been incorporated, along with stuff in the README
 about validation.

 I'm confused as to how I ended up with (first (reverse ...)) since I
 remember looking at the doc for (last seq), but anyway, it's there
 now.

 -hume.
 --
 http://elhumidor.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
To unsubscribe from 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: Some code review for clj-record?

2008-12-30 Thread Brian Doyle
I see what you are doing with the validations and defining them in the
init-modelcall.
I think that's a good idea actually and like it better than my solution to
putting the
callbacks in the model namespace.

A couple of small things that I noticed when starting to play around with
clj-record.  In your
example you have:

(ns com.example.user)
  (clj-record.core/init-model)

but when I do that I get the error:

java.lang.ClassNotFoundException: clj-record.core

When I add a require it clears it up like:

(ns com.example.user
  (:require [clj-record.core :as cr.core]))
   (cr.core/init-model)

I know this is picky, but in your clj-record.core/init-model function you
have:

(first (reverse (re-split #\. (name (ns-name *ns*)

and could be changed to:

(last (re-split #\. (name (ns-name *ns*

I look forward to seeing clj-record progress.   Thanks John.

On Mon, Dec 29, 2008 at 10:20 PM, John D. Hume duelin.mark...@gmail.comwrote:


 On Mon, Dec 29, 2008 at 7:15 PM, Brian Doyle brianpdo...@gmail.com
 wrote:
  I noticed that in the init-model macro you are creating a 'defn table []
  ...' function in the
  model namespace and was wondering why you didn't just make it a def
 instead,
  since
  it doesn't take any args?

 That didn't occur to me. I do like the idea of all the functionality
 being available directly on clj-record.core with model name as a first
 argument in addition to being defined in the model namespace, so I
 guess that's one reason. But the inference of table name from model
 name should only be the default, so maybe it would be better to just
 def it there and let clj-record.core look it up there if needed,
 somewhat as you recommended doing for callbacks...

  I have an idea for you with the callbacks like, before-create,
 after-create,
  etc.  In the
  all-models-metadata in the core.clj you could store the namespace in the
  hash
  associated with the model-name on setup.   Then in the create function
  defined in
  the core.clj you could call the before-create function defined in the
 model
  something
  like:
 
  (let-if [bc ('before-create (ns-publics model-namespace)] (bc
  attributes#))

 That's interesting. It's basically the opposite of the way I did the
 validation stuff, where you pass in validation functions and those get
 stored away in metadata and aren't directly accessible. (Here
 metadata is not used in the clojure.org/metadata sense of the word.
 I've thought about using clojure metadata to store model info, but I
 don't know what symbol or collection I'd attach it to.) I think I
 prefer the validation approach, because those functions have a certain
 job to do and shouldn't be sitting there cluttering the model
 namespace. (On the other hand, it is awfully convenient to be able to
 test those functions directly.)

 Thanks again for looking. If you or anyone else has further comments,
 I'd like to hear them.
 git clone git://github.com/duelinmarkers/clj-record.git

 -hume.

 --
 http://elhumidor.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
To unsubscribe from 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: Understanding how to use namespaces

2008-12-30 Thread Brian Doyle
On Tue, Dec 30, 2008 at 11:25 PM, Mark Engelberg
mark.engelb...@gmail.comwrote:


 Thanks, that helps dramatically.  It took me a while to figure out how
 to edit the SLIME startup to include my clojure files directory in the
 classpath, but I got it working.

 So it seems like you have to make sure the namespace always matches
 the file.  That means if you change the name of the file, you've got
 to remember to change the namespace declaration as well, right?  Is
 there any way to require/use a file that has no namespace specified at
 the top?

 In Clojure Box, is there any way to make the REPL automatically use
 whatever namespaces are in the files you are actively working on?


I don't know anything about SLIME or Clojure Box, but I wrote a little
Clojure script
that is called when I start the REPL that calls 'use' on most of the
namespaces in the
Clojure contrib jar.   You can see the code here:

http://github.com/heyZeus/clojure-stuff/tree/master/repl-init.clj



 


--~--~-~--~~~---~--~~
You 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: making code readable

2008-12-29 Thread Brian Doyle
Looking at this code the uppercase variables stands out.
This isn't idiomatic is it?

(def GRID_SIZE 10)
(def HEIGHT 600)
(def MARGIN 50)


On Mon, Dec 29, 2008 at 12:19 PM, Mark Volkmann
r.mark.volkm...@gmail.comwrote:


 On Mon, Dec 29, 2008 at 11:11 AM, lpetit laurent.pe...@gmail.com wrote:
 
  You should consider using docstrings for documenting functions

 Good suggestion. I've changed my code to do that. I also noticed that
 I had forgotten to replace special characters with built-in entities
 in my HTML, so that is fixed now. The new version is at
 http://www.ociweb.com/mark/programming/ClojureSnake.html. What else
 would you do different in this code? Do you think it still contains
 too many comments?

  On 29 déc, 16:45, Mark Volkmann r.mark.volkm...@gmail.com wrote:
  On Mon, Dec 29, 2008 at 5:44 AM, Mark Volkmann
 
 
 
  r.mark.volkm...@gmail.com wrote:
   I would like to produce a version of the snake code that could serve
   as an example of the kind of code that the Clojure community thinks is
   good. Unless it's part of an exercise to produce the shortest code
   possible, I think we should always write Clojure code with a goal of
   making it as easy as possible for others to read, while not attempting
   to serve as a Clojure tutorial. Again, my goal here is to get more
   developers to give Clojure a shot.
 
   My challenge to everyone on the list is to start with any version of
   the snake code you've seen and make it as readable as *you* think it
   should be by doing things like renaming variables and functions,
   adding comments and changing indentation. I'd really like to see what
   *you* think is the best way to write this code. The lessons learned
   from this exercise could then be applied to other code we write in the
   future.
 
  Okay, I took the challenge and produced a modified version of my
  earlier code where I removed what I considered to be redundant
  comments and did a little more renaming. You can see it athttp://
 www.ociweb.com/mark/programming/ClojureSnake.html. Feedback is
  welcomed!
 
  I also started documenting some Clojure coding guidelines aimed at
  making code more readable athttp://
 www.ociweb.com/mark/programming/ClojureCodingGuidelines.html
  and would appreciate feedback on these. I expect there will be cases
  where not following these is justified, which is why I refer to them
  as guidelines instead of rules.
 
  --
  R. Mark Volkmann
  Object Computing, Inc.
  
 



 --
 R. Mark Volkmann
 Object Computing, Inc.

 


--~--~-~--~~~---~--~~
You 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: Some code review for clj-record?

2008-12-29 Thread Brian Doyle
That seems to be working better now John.   I looked over most of the code
and it seems
like a good start.  I'm no expert when it comes to functional programming or
Clojure,
so I'm not sure how to critic the code exactly.   If I was doing the porting
I would prolly
do it in very OO way, since that's what I'm used to, and that would not be
correct.

I noticed that in the init-model macro you are creating a 'defn table []
...' function in the
model namespace and was wondering why you didn't just make it a def instead,
since
it doesn't take any args?

I have an idea for you with the callbacks like, before-create, after-create,
etc.  In the
all-models-metadata in the core.clj you could store the namespace in the
hash
associated with the model-name on setup.   Then in the create function
defined in
the core.clj you could call the before-create function defined in the model
something
like:

(let-if [bc ('before-create (ns-publics model-namespace)] (bc
attributes#))

That was just an idea I had, but there could be a better way to do it that's
for sure!
Of course it's prolly a bit more complex than that since you the
before-create function
could alter the attributes#, but you get the idea of discovering and calling
the
appropriate callback function in the model namespace.

On Sun, Dec 28, 2008 at 9:49 PM, John D. Hume duelin.mark...@gmail.comwrote:


 Ok, please pull the latest and try again.
 git clone git://github.com/duelinmarkers/clj-record.git

 The problem was due to something I've seen a couple other messages
 about: When running a file as a script, it starts out in the
 clojure.core namespace. I was doing (def db {...}) before any (ns ...)
 so the db var lived in clojure.core, which made it conveniently (but
 sloppily) visible everywhere. Loading from the REPL, however, it was
 landing in the user namespace. I've now put it in a config namespace
 and required config from the two places that need it.

 Thanks for looking.
 -hume.

 On Sun, Dec 28, 2008 at 11:27 PM, John D. Hume duelin.mark...@gmail.com
 wrote:
  The db configuration isn't reasonable at the moment. You can run
  clj_record/test/main.clj as a script but not load it from the REPL.
  Let me see if I can get it to work both ways and push an update.
 
  On Sun, Dec 28, 2008 at 6:28 PM, Brian Doyle brianpdo...@gmail.com
 wrote:
  Having used Rails myself I wanted to check this out and play with it.
 I'm
  having some
  trouble just loading the clj_record/core.clj file though:
 
  1:1 user= (load-file clj_record/core.clj)
  java.lang.Exception: Unable to resolve symbol: db in this context
  (core.clj:19)
 
  I'm sure it's something I'm doing wrong but I do have derby.jar on my
  classpath.  Thanks.

 


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

2008-12-28 Thread Brian Doyle
Having used Rails myself I wanted to check this out and play with it.   I'm
having some
trouble just loading the clj_record/core.clj file though:

1:1 user= (load-file clj_record/core.clj)
java.lang.Exception: Unable to resolve symbol: db in this context
(core.clj:19)

I'm sure it's something I'm doing wrong but I do have derby.jar on my
classpath.  Thanks.


On Sat, Dec 27, 2008 at 1:48 PM, John D. Hume duelin.mark...@gmail.comwrote:


 Hi all,
 As a learning exercise, I've started working on a sort of clojure
 clone of ActiveRecord (from Rails). You can see it here:
 http://github.com/duelinmarkers/clj-record/tree/master

 The model used in the tests is defined in files here:

 http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/model

 And the tests most worth reading are:

 http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/core-test.clj

 http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/associations-test.clj

 I'd be interested in any feedback about issues you see, idioms I could
 be using that I'm not, suggestions on testing approach, or other
 comments or questions.

 One style question I'm particularly interested in is what people think
 the model setup should look like. Currently I've got it implemented to
 allow a minimum of punctuation:

 (cljrec/init-model
  (has-many products))

 But is it bad form to use the fact that macros don't evaluate
 arguments to allow all those naked symbols? For consistency with ns it
 seems it would be preferable to make has-many a keyword:

 (cljrec/init-model
  (:has-many products))

 (There actually is a has-many method that gets invoked by init-model,
 but that's an implementation detail.)

 My gut says the least confusing approach for a user would be this.

 (cljrec/init-model
  (:has-many :products))

 ... but something seems weird to me about both :has-many and :products
 being keywords, where :has-many is a magic keyword and :products is a
 name being introduced. (Note it doesn't define a var called 'products
 but does create 'find-products and 'destroy-products functions.)

 Note that I'm using clojure.contrib.sql and not worrying about the
 constantly opening and closing connections. Obviously I'd need some
 way of wrapping a single db transaction around a bunch of expressions
 to make this a generally useful library. But that's not the point
 right now.

 Thanks.
 -hume.
 --
 http://elhumidor.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
To unsubscribe from 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: Exercise: how to print multiplication table?

2008-12-22 Thread Brian Doyle
2008/12/22 J. McConnell jdo...@gmail.com

 On Mon, Dec 22, 2008 at 10:23 AM, Piotr 'Qertoip' Włodarek
 qert...@gmail.com wrote:
 
  Being new to Clojure, to Lisp and to functional programming in
  general, I have some trouble wraping my head around it.
 
  As the first exercice, I would like to print multiplication table of
  specified order, like:
  (print-multiplication-table 3)
   1  2  3
   2  4  6
   3  6  9
 
  I came that far:
 
  (defn multiplication-row [n k]
 (map (partial * k) (range 1 (inc n
 
  (defn multiplication-table [n]
 (map (partial multiplication-row n) (range 1 (inc n
 
  (println (multiplication-table 3)); = ((1 2 3) (2 4 6) (3 6 9))
 
  Now, how to pretty print this?
 
  This does not work - prints nothing - why?:
  (defn pretty-print-row [row]
   (map print row))

 The problem is that you are using map in two different ways here. In
 the multiplication-row and multiplication-table functions you are
 using it correctly as a function that applies a given function to all
 of the values in a collection, returning the results in a new
 collection. In the pretty-printing function you do not care about the
 results like you did in the above two functions, you care about the
 side-effects. For this, you can use doseq:

 1:1 user= (defn multiplication-row [n k]
   (map (partial * k) (range 1 (inc n
 #'user/multiplication-row
 1:3 user= (defn multiplication-table [n]
   (map (partial multiplication-row n) (range 1 (inc n
 #'user/multiplication-table
 1:5 user= (defn pretty-print-row [row]
  (doseq [v row] (print v \space)) (print \newline))
 #'user/pretty-print-row
 1:7 user= (defn print-multiplication-table [n]
  (doseq [row (multiplication-table n)] (pretty-print-row row)))
 #'user/print-multiplication-table
 1:9 user= (print-multiplication-table 3)
 1  2  3
 2  4  6
 3  6  9
 nil
 1:10 user= (print-multiplication-table 5)
 1  2  3  4  5
 2  4  6  8  10
 3  6  9  12  15
 4  8  12  16  20
 5  10  15  20  25
 nil

 HTH,

 - J.


This is off topic from the original questions, but are the 1:#'s in your
REPL line numbers?
If so, what did you do to get those?   Also if those are line numbers how
come only odd
numbers are printed?  What does the '1:' stand for?   Thanks.



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from 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 encapsulate local state in closures

2008-12-21 Thread Brian Doyle
I haven't been following the new atom stuff, so I was wondering why atom
would be best in this
situation, vs a ref?  Thanks.

On Sun, Dec 21, 2008 at 1:03 PM, Parth Malwankar
parth.malwan...@gmail.comwrote:




 On Dec 21, 11:47 pm, chris cnuern...@gmail.com wrote:
  I would like to be able to encapsulate local state in a closure.
  Specifically, I would like a function that returns an incrementing
  integer, thus:
  (test_func)
  1
  (test_func)
  2
  What is the best way to go about this?  With local bindings is failing
  and I can't figure just why...
 

 One way to do this would be to use atom.

 (defn mk-counter [start]
  (let [n (atom start)]
(fn [] (swap! n inc

 (def counter (mk-counter 0))

 user= (counter)
 1
 user= (counter)
 2
 user= (counter)
 3

 Parth
  (def test_closure
 (with-local-vars [one 1]
   (fn [] (var-get one
  #'user/test_closure
  user (test_closure)
  ; Evaluation aborted.
  The var is null when I call the closure.
 
  Thanks,
  Chris
 


--~--~-~--~~~---~--~~
You 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: for FAQ: what are use/require/import/refer?

2008-12-20 Thread Brian Doyle
This would make an excellent FAQ question and answer!

On Sat, Dec 20, 2008 at 9:53 AM, Stuart Sierra
the.stuart.sie...@gmail.comwrote:


 This might make a good FAQ question:

 On Dec 20, 11:25 am, chris cnuern...@gmail.com wrote:
  I am unclear as to the difference between refer, import use, and require.

 Hi Chris,

 require: Load a Clojure library from a file on classpath.  Use this
 when you want to load a library, but leave it in its own namespace.

 refer: Bring public symbols from one namespace into the current
 namespace.  Use this when a library has already been loaded (example:
 clojure.set) but you want to use its public symbols without a
 namespace qualifier.

 import: Copy Java class names into current namespace.  Use this when
 you want to use a Java class without typing the full package name.

 use: Combination of require and refer.  Use this when you want to load
 a library AND use its symbols without a namespace qualifier.

 All four are available as keyword arguments to ns, which is the
 preferred way to use them:

 (ns foo.bar
  (:use my.little.lib)
  (:require clojure.contrib.duck-streams)
  (:import (java.io File InputStream))
  (:refer clojure.set))

 :require also allows aliasing, like this:
 (ns foo.bar
  (:require [clojure.set :as set]))

 Now you can write the symbol clojure.set/union as set/union.

 -Stuart Sierra
 


--~--~-~--~~~---~--~~
You 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: multiple sets on one item - is this a good idea?

2008-12-20 Thread Brian Doyle
Instead of require call use and should get you what you want.

On Dec 20, 2008 9:15 AM, chris cnuern...@gmail.com wrote:


That helped, thanks Christophe.

I have one more problem:

I put it in a util file, under a util namespace:

(ns lambinator.util)

(defmacro sets! [vars  rest] `(do ~@(map (fn [flds] `(set! (. ~vars ~(first
flds)) ~(second flds...
Now I want to use it outside that namespace.  It seems that I have to
do two things when I load from a jar...

(require 'lambinator.util)

(lambinator.util/sets! c fill GridBagConstraints/VERTICAL weightx 1.5)

How do I use the function/macro outside the namespace it was created
in without prefixing it with lambinator.util?  Import, require don't
seem to do what I want...

Chris

On Dec 20, 12:28 am, Christophe Grand christo...@cgrand.net wrote:  chris
a écrit :Hello,...

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



calling use with a seq of strings

2008-12-15 Thread Brian Doyle
I have a seq of strings that are namespaces like,
(clojure.contrib.str-utils, clojure.contrib.duck-streams).
I wanted to call the use function on this seq.   I can't seem to do that
though.   Any way I can do this or
is this just a bad idea?   Thanks.

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



Re: calling use with a seq of strings

2008-12-15 Thread Brian Doyle
I didn't know about the symbol function.  Thanks!  I just want to call use
on all
of the namespaces in the clojure.contrib jar when starting the repl and this
will
work nicely!

On Mon, Dec 15, 2008 at 1:59 PM, Stuart Sierra
the.stuart.sie...@gmail.comwrote:


 You can do this:
 (apply use (map symbol (list clojure.contrib.str-utils
 clojure.contrib.duck-streams)))
 -Stuart Sierra

 On Dec 15, 3:51 pm, Brian Doyle brianpdo...@gmail.com wrote:
  I have a seq of strings that are namespaces like,
  (clojure.contrib.str-utils, clojure.contrib.duck-streams).
  I wanted to call the use function on this seq.   I can't seem to do that
  though.   Any way I can do this or
  is this just a bad idea?   Thanks.
 


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



possible bug with seq and Enumeration?

2008-12-15 Thread Brian Doyle
According to the docs the seq function should be able to take an
enumeration,
but here is what I see:

user= (seq (.elements (doto (java.util.Vector.) (.add hello) (.add
world
java.lang.IllegalArgumentException: Don't know how to create ISeq
from:  (NO_SOURCE_FILE:0)

SVN 1160, thanks.

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

2008-12-15 Thread Brian Doyle
Using enumeration-seq does the trick!  Thanks.

user= (enumeration-seq (.entries (java.util.zip.ZipFile. path to some
jar)))

On Mon, Dec 15, 2008 at 5:14 PM, Rich Hickey richhic...@gmail.com wrote:




 On Dec 15, 6:01 pm, Brian Doyle brianpdo...@gmail.com wrote:
  According to the docs the seq function should be able to take an
  enumeration,
  but here is what I see:
 
  user= (seq (.elements (doto (java.util.Vector.) (.add hello) (.add
  world
  java.lang.IllegalArgumentException: Don't know how to create ISeq
  from:  (NO_SOURCE_FILE:0)
 

 If you really want to create a seq on an Enumeration you have to use
 enumeration-seq. But there is no need to explicitly obtain
 enumerations/iterators for Collections (and Vector implements
 Collection):

 (seq (doto (java.util.Vector.) (.add hello) (.add world)))
 - (hello world)

 Note also that Collections have constructors from Collections, and
 Clojure vectors are Collections:

 (seq (java.util.Vector. [hello world]))
 - (hello world)

 Rich

 


--~--~-~--~~~---~--~~
You 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: understanding quoting

2008-12-15 Thread Brian Doyle
On Mon, Dec 15, 2008 at 9:43 PM, Daniel Eklund doekl...@gmail.com wrote:


  Looks like an if then else version of the map lookup??
  ie: (if (%1 %2) (%1 %2) %3)
  Is this a special feature of maps in general, such that you can look
  up a key but return something else if it doesn't exist?
  I hadn't come across it yet, but it sounds useful :)

 This is exactly right (I just confirmed it for myself).  I looked up
 the java code for Keyword.java and Symbol.java both of which implement
 IFn  (those things that can be put in the function position).  The
 single and double arity invoke() merely delegate to 'get'.  And voila:


How did you know that it delegates to 'get'?



 user (doc get)
 -
 clojure.core/get
 ([map key] [map key not-found])
  Returns the value mapped to key, not-found or nil if key not
 present.

 The last parameter is definitely for those situations where 'if not
 found, use this'

 I think I _finally_ understand the statement, keywords and symbols
 are functions of maps.

 So, the original poster's observation about ('+ '1 '2) returning '2
 makes more sense when you consider that it turns into this:

 (get '1 '+ '2)

 or get from the hashmap ( '1 ) the value stored at key ( '+ ) and if
 nil is returned, return ( '2 ) instead

 (get '1 '+) returns nil as '1 is not even a map.


 


--~--~-~--~~~---~--~~
You 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: doall and dorun

2008-12-15 Thread Brian Doyle
I'll take a crack at this.  It may appear that the doall and dorun return
something
different with subsequent calls but they don't actually.   The doall always
returns
the sequence (1 2) and dorun always returns nil.

The first time (doall x) is called the for loop executes and prints 1 2 (a
side effect
and is not returned from the for loop) and then returns the seq.  The second
time
it's called x is already assigned the seq and just returns it. It does not
execute
the for loop again.

The dorun call is similar, but instead of returning the seq of the for loop,
it always
returns nil.  According to the api docs, dorun is used to force side
effects.

On Mon, Dec 15, 2008 at 9:19 PM, wubbie sunj...@gmail.com wrote:


 Hello,

 doall and dorun returns different results from seond run on...
 e.g.
 user= (def x (for [i (range 1 3)] (do (println i) i)))
 #'user/x
 user= (doall x)
 1
 2
 (1 2)
 user= (doall x)
 (1 2)
 user= (doall x)
 (1 2)
 user=

 user= (def x (for [i (range 1 3)] (do (println i) i)))
 #'user/x
 user= (dorun x)
 1
 2
 nil
 user= (dorun x)
 nil
 user= (dorun x)
 nil
 user=


 What's the explanation for that?

 thanks
 sun



 


--~--~-~--~~~---~--~~
You 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: Gorilla: Release of Version 1.1.0

2008-12-13 Thread Brian Doyle
I'm sure I'm doing something stupid but I can't start up gorilla.

Exception in thread main java.lang.NoClassDefFoundError: de/kotka/gorilla
Caused by: java.lang.ClassNotFoundException: de.kotka.gorilla
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Here is my script:

java -cp ~/share/clojure.jar:~/share/clojure-contrib.jar:~/share/gorilla.jar
de.kotka.gorilla

Gorilla is in my path:

$ ls ~/share/gorilla.jar
/home/bdoyle/share/gorilla.jar

No clue what is going on.

On Sat, Dec 13, 2008 at 8:10 AM, Meikel Brandmeyer m...@kotka.de wrote:

 Hi,

 Am 13.12.2008 um 15:07 schrieb Randall R Schulz:

 I installed a couple of new packages on my 10.3 box and
 now vim --version reports +ruby, so I guess I can at least give it a
 try there (that's not my primary box, though it is the faster one).


 Unfortunately, vim by itself cannot do, what I need.
 There emacs is really better with its elisp. The Ruby
 interface is - well - also not very satisfactory, but it
 gets the job done. But one has to pass everything
 around as strings *ugh*, since the is no basic glue
 between Vim and the Ruby side. So it's currently a
 total mess. I'll try to clean that up for the next release

 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
To unsubscribe from 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: Gorilla: Release of Version 1.1.0

2008-12-13 Thread Brian Doyle
Thanks Meikel, removing the ~'s worked.  Oh and thanks for vimclojure and
gorilla!

On Sat, Dec 13, 2008 at 9:28 AM, Meikel Brandmeyer m...@kotka.de wrote:

 Hi,

 Am 13.12.2008 um 17:17 schrieb Brian Doyle:

  Here is my script:

 java -cp
 ~/share/clojure.jar:~/share/clojure-contrib.jar:~/share/gorilla.jar
 de.kotka.gorilla


 I can reproduce the issue. The ~ is a shellish feature
 from Unix. It is only expanded at the start of a word.
 So the first ~ in your -cp argument is probably expanded
 while the others are not. Hence it doesn't find the
 gorilla.jar, since the JVM sees ~/share/gorilla.jar.
 When opening this file, the system says: Dunno.
 Never heard that name. So the class is not found.
 Convert all ~ in your classpath to absolute (or relative)
 paths and it works.

 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
To unsubscribe from 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: Java interop question

2008-12-11 Thread Brian Doyle
This article has a good example using the proxy function.

http://gnuvince.wordpress.com/2008/11/18/fetching-web-comics-with-clojure-part-2/

On Thu, Dec 11, 2008 at 1:22 PM, Randall R Schulz rsch...@sonic.net wrote:


 On Thursday 11 December 2008 11:31, Mark Engelberg wrote:
  I understand how Clojure lets you consume Java objects, and pass
  Clojure objects to Java programs.
 
  However, it is not uncommon for Java libraries to be designed in such
  a way that you need to create a subclass of something in the library
  in order to make use of the library.  I don't understand whether this
  is possible in Clojure.

 It's not only possible, but quite straightforward. The basic thing
 you're looking for is (proxy ...). In some cases, you may need
 (gen-class). Check them out. They'll get you everything you need for
 working with white-box frameworks.

 (I'll check out Geocode/J as soon as I get Firefox back up. It just
 crashed and I keep 9 windows and over 80 tabs open, so starting it up
 is pretty slow...)


  ...
 
  Thanks,
 
  Mark


 Randall Schulz

 


--~--~-~--~~~---~--~~
You 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: why can't I set! stuff in user.clj?

2008-12-09 Thread Brian Doyle
Stuart,

I have a ~/.cljrc file that has this stuff in there and in my bash (clj)
script to start clojure I do:

$JAVA -cp $CLOJURE_JARS clojure.lang.Repl ~/.cljrc

On Tue, Dec 9, 2008 at 1:12 PM, Stuart Halloway
[EMAIL PROTECTED]wrote:


 Why can't I call set! in user.clj? (And what is the idiomatic way to
 do what I want here?)

 (set! *print-length* 103)
 - Exception in thread main java.lang.ExceptionInInitializerError
at clojure.lang.Repl.clinit(Repl.java:23)
 Caused by: java.lang.RuntimeException: java.lang.IllegalStateException:
 Can't change/establish root binding of: *print-length* with set

 Thanks,
 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: why can't I set! stuff in user.clj?

2008-12-09 Thread Brian Doyle
Steve,

Could you post your bash shell script that starts Clojure?   I would like to
see what you have concerning the new options that can be passed to the
updated clojure.jar.  Thanks.

On Tue, Dec 9, 2008 at 1:59 PM, Stephen C. Gilardi [EMAIL PROTECTED] wrote:

 user.clj is loaded before thread-local bindings are established. I see
 you're using Repl.java. You can see the call to pushThreadBindings there to
 see how it works. user.clj allows you to set up the user namespace, but not
 set! most vars.
 With the repl in clojure.main, you can include an init file on your
 java... command line using the -i option. It will be loaded after those
 bindings have been established. We do not have anything like a
 repl-init.clj file that's auto-loaded if it exists to accomplish these
 kinds of settings. It might be a good idea to have one, loaded from
 classpath, with a suitable name.

 More complete solutions to this initialization task (.e.g., for the bash
 shell) look in a few places for init files. That's something to consider as
 well.

 --Steve

 On Dec 9, 2008, at 3:12 PM, Stuart Halloway wrote:


 Why can't I call set! in user.clj? (And what is the idiomatic way to
 do what I want here?)

 (set! *print-length* 103)
 - Exception in thread main java.lang.ExceptionInInitializerError
 at clojure.lang.Repl.clinit(Repl.java:23)
 Caused by: java.lang.RuntimeException: java.lang.IllegalStateException:
 Can't change/establish root binding of: *print-length* with set

 Thanks,
 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
-~--~~~~--~~--~--~---



unsupported binding form for cond-let

2008-12-05 Thread Brian Doyle
I started to play with cond-let in the contrib.cond package and got an
unexpected error:

user= (cond-let [x (zero? 0)] (println hello world))
java.lang.Exception: Unsupported binding form: (zero? 0) (NO_SOURCE_FILE:11)

user= (cond-let x (zero? 0) (println hello world))
hello world

Maybe it was overlooked when making the binding forms more
consistent?   Like:

user= (when-let [x (zero? 0)] (println hello world))
hello world

user= (if-let [x true] (println hello world))
hello world

--~--~-~--~~~---~--~~
You 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: A try on condp (was: Re: proposal: match multimethod)

2008-12-03 Thread Brian Doyle
Can you include an example usage of this function?  Thanks.

On Wed, Dec 3, 2008 at 12:51 PM, Meikel Brandmeyer [EMAIL PROTECTED] wrote:

 Hi Stuart and Rich,

 Am 03.12.2008 um 19:00 schrieb Stuart Sierra:

 I'm pretty sure I don't like the sound of that at all. We had a nice
 discussion about fcase/condf, which I'd like to get in, here:

 http://groups.google.com/group/clojure/browse_frm/thread/dee910bef629...


 And I haven't forgotten about that, just haven't had time to work on
 it.  Anyone else who wants to tackle it is welcome.


 How about the following:

 (defmacro condp
  condp compares the given needle with the first clause using the given
  predicate. In case the predicate returns true the second clause is
  returned. Otherwise condp goes on with the rest of the clauses. In
  case there is an odd number of clauses the last one will be returned
  if no preceding clause matched. If no default clause is given an
  exception is thrown. The predicate is called with needle as first
  argument and the first clause as second argument.
  [pred needle  clauses]
  (let [c(count clauses)
par  (rem c 2)
cls  (take (if (zero? par) c (dec c)) clauses)
cls  (mapcat (fn [[x c]] `[(~xprd ~xndl ~x) ~c]) (partition 2 cls))
xndl (gensym condp_needle__)
xprd (gensym condp_predicate__)
lst  (if (zero? par)
   `(throw (Exception. (str No condp clause matched for: 
(prn-str ~xndl
   (last clauses))]
`(let [~xprd ~pred
   ~xndl ~needle]
   (cond
 [EMAIL PROTECTED]
 :else ~lst

 I mulled about the (x _) syntax, but to be honest: I think #() is
 perfectly sufficient. We would need to quote all the contents to
 prevent multiple evaluation, but then we have to recurse and check
 for _ vs. non-_...

 I expect the predicate to be a function of two arguments with the first
 being the needle and the second being the clause, we compare to.
 Predicates where order doesn't matter or the order agrees may be simply
 used. Others or more complicated expressions can be wrapped in a #().
 Here we still have a problem for #(pred (complicated-computation) %2
 %1)

 In case the number of clauses is even, and no clause matched the
 predicate, we throw an exception. In case the number of clauses is
 odd, we return the last one as default. I think adding a simple nil
 is tolerable, making the I ignore a failed run explicit.

 What do you think?

 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
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: Bug: recur won't work in tail position within cond

2008-12-03 Thread Brian Doyle
This seems to work for me:

(defn sub-til-0 [n]
(cond
  (zero? n) 0
  :else (recur (dec 1

I'm not sure what those extra ['s are for in your example.

On Wed, Dec 3, 2008 at 9:39 PM, puzzler [EMAIL PROTECTED] wrote:


 (defn sub-til-0 [n]
  (if (zero? n) 0 (recur (dec 1

 works but the equivalent

 (defn sub-til-0 [n]
  (cond
   [(zero? n) 0]
   [:else (recur (dec 1))]))

 does not.

 Recursion is already limited enough in Clojure...  give us recur in
 tail position within cond!  :)

 Thanks,

 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: randomize a collection?

2008-12-02 Thread Brian Doyle
Seems like shuffle should be part of the core or in the contrib.  Is there a
reason why it's not?

On Mon, Dec 1, 2008 at 9:55 PM, Timothy Pratley [EMAIL PROTECTED]wrote:



 http://groups.google.com/group/clojure/browse_thread/thread/180842eb58c58370/0e19ab338452c64f?lnk=gstq=shuffle#0e19ab338452c64f
 The recommendation was to use java.util.Collections/shuffle and an
 example was given:

 (defn shuffle [coll]
  (let [l (java.util.ArrayList. coll)]
(java.util.Collections/shuffle l)
(seq l)))

 user= (shuffle [1 2 3 4 5])
 (4 2 1 5 3)

 On Dec 2, 3:28 pm, Brian Doyle [EMAIL PROTECTED] wrote:
  Is there a function that takes a collection and randomizes, or shuffles,
 the
  items?
 


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



randomize a collection?

2008-12-01 Thread Brian Doyle
Is there a function that takes a collection and randomizes, or shuffles, the
items?

--~--~-~--~~~---~--~~
You 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: Flattening any collection

2008-11-30 Thread Brian Doyle
As long as you have the clojure.contrib jar in your path you can do:

(use 'clojure.contrib.seq-utils)

(flatten [1 2 3 '(4 5 6)])
= (1 2 3 4 5 6)

On Sun, Nov 30, 2008 at 9:36 PM, samppi [EMAIL PROTECTED] wrote:


 For any given collection [3 2 [3 5 1] 1 [3 4 1] 0], how may I get [3 2
 3 5 1 1 3 4 1 0]?

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



update a ref struct

2008-11-24 Thread Brian Doyle
I am parsing a file and to compare the current line
with the previous line of the file.  I am using line-seq
to go thru the file and I thought I would create a
ref to store the previous line.   When I want to update
the previous line value I can't seem to do it.  I've
never used refs before so I'm sure I'm doing something
very stupid.

(defstruct line :lat :lon :name)

(defn convert [file]
  (let [prev-line (ref (struct line))]
(with-open [r (reader file)]
   (doseq [l (line-seq r)]
 (let [ps (split #, l)
c-line (struct line (ps 0) (ps 1) (ps 2))]
   (if (not= c-line @pre-line)
 (do ; do stuff here then update pre-line
(dosync ref-set pre-line (apply struct line (vals c-line)))
(println @pre-line  ; this prints out all nils
doesn't seem to work



Sorry if this email is not formatted correctly.  Something is wrong with my
browser
currently typing in a textarea.  Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
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: update a ref struct

2008-11-24 Thread Brian Doyle
Thanks Kevin, I will try using reduce instead.  I would like to know what
I'm doing wrong with updating the ref for future reference.  Thanks.

On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey [EMAIL PROTECTED] wrote:


 I know you are asking about refs, but you might want to think about
 using reduce to walk the line-seq. the nature of reduce lets you have
 access to the line-seq, two lines at a time no need for a ref.

 On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle [EMAIL PROTECTED]
 wrote:
  I am parsing a file and to compare the current line
  with the previous line of the file.  I am using line-seq
  to go thru the file and I thought I would create a
  ref to store the previous line.   When I want to update
  the previous line value I can't seem to do it.  I've
  never used refs before so I'm sure I'm doing something
  very stupid.
 
  (defstruct line :lat :lon :name)
 
  (defn convert [file]
(let [prev-line (ref (struct line))]
  (with-open [r (reader file)]
 (doseq [l (line-seq r)]
   (let [ps (split #, l)
  c-line (struct line (ps 0) (ps 1) (ps 2))]
 (if (not= c-line @pre-line)
   (do ; do stuff here then update pre-line
  (dosync ref-set pre-line (apply struct line (vals
 c-line)))
  (println @pre-line  ; this prints out all nils
  doesn't seem to work
 
 
 
  Sorry if this email is not formatted correctly.  Something is wrong with
 my
  browser
  currently typing in a textarea.  Thanks.
 
 
 
  
 



 --
 The Mafia way is that we pursue larger goals under the guise of
 personal relationships.
Fisheye

 


--~--~-~--~~~---~--~~
You 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: update a ref struct

2008-11-24 Thread Brian Doyle
Yep, that's just a typo in the email.  Something was wrong with my browser
and I
couldn't just paste the code in :(

On Mon, Nov 24, 2008 at 3:33 PM, Shawn Hoover [EMAIL PROTECTED]wrote:

 On Mon, Nov 24, 2008 at 5:17 PM, Brian Doyle [EMAIL PROTECTED]wrote:

 I am parsing a file and to compare the current line
 with the previous line of the file.  I am using line-seq
 to go thru the file and I thought I would create a
 ref to store the previous line.   When I want to update
 the previous line value I can't seem to do it.  I've
 never used refs before so I'm sure I'm doing something
 very stupid.

 (defstruct line :lat :lon :name)

 (defn convert [file]
   (let [prev-line (ref (struct line))]
 (with-open [r (reader file)]
(doseq [l (line-seq r)]
  (let [ps (split #, l)
 c-line (struct line (ps 0) (ps 1) (ps 2))]
(if (not= c-line @pre-line)
  (do ; do stuff here then update pre-line
 (dosync ref-set pre-line (apply struct line (vals
 c-line)))
 (println @pre-line  ; this prints out all nils
 doesn't seem to work


 Your let binds prev-line, while the code inside uses pre-line. Is that just
 a typo in your email, or is that the code you're running, too?

 Shawn


 


--~--~-~--~~~---~--~~
You 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-11-21 Thread Brian Doyle
Denver, CO

Brian Doyle

On Wed, Nov 19, 2008 at 4:09 AM, liu chang [EMAIL PROTECTED] wrote:


 Singapore +1.

 On Wed, Nov 19, 2008 at 5:24 PM, walterc [EMAIL PROTECTED] wrote:
 
  taipei, taiwan
 
  cheers,
 
  walter chang
  
 

 


--~--~-~--~~~---~--~~
You 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: multi-method dispatch for structs

2008-11-14 Thread Brian Doyle
I wonder if it would good to have something indicating the struct name
put in the metadata when creating a struct?

On Fri, Nov 14, 2008 at 1:42 PM, Chouser [EMAIL PROTECTED] wrote:


 On Fri, Nov 14, 2008 at 2:11 PM, Jeff Rose [EMAIL PROTECTED] wrote:
  Does my dispatch function have to inspect the passed in values to
  figure out which type of struct they are, or can I query that
  somehow?

 My understanding is that StructMaps are just Maps with an
 implementation that's optimized to reduce memory usage.  The different
 basis types don't really function as classes of StractMaps or
 anything.  You can still add new keys to StructMaps, for example, just
 like any other Map.  So if you want some kind of 'type' data do
 dispatch off of, you'll have to attach that yourself, either as
 another key that all your Maps share or as metadata.

 --Chouser

 


--~--~-~--~~~---~--~~
You 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: Getting a flat sequence from a map (and vice versa)

2008-11-14 Thread Brian Doyle
Another way to create a map is:

user= (apply hash-map [:a 1 :b 2 :c 3])
{:a 1, :c 3, :b 2}


On Fri, Nov 14, 2008 at 9:42 PM, samppi [EMAIL PROTECTED] wrote:


 Excellent! I must remember about the apply function. Thank you very
 much.

 On Nov 14, 9:35 pm, Kevin Downey [EMAIL PROTECTED] wrote:
  On Fri, Nov 14, 2008 at 8:33 PM, Kevin Downey [EMAIL PROTECTED] wrote:
   On Fri, Nov 14, 2008 at 8:17 PM, samppi [EMAIL PROTECTED] wrote:
 
   Yeah, I need to be able to do this to easily manage trees of maps. I
   meant, how would you idiomatically implement their algorithms?
 
   Fold isn't build into Clojure, but they should still somehow be
   possible...right?
 
   On Nov 14, 9:12 pm, Michel Salim [EMAIL PROTECTED] wrote:
   On Nov 14, 10:56 pm, samppi [EMAIL PROTECTED] wrote: I'm trying
 to figure out how to do this:
 
  (flat-map-seq {:a 3, :b 1, :c 2}) ; returns (:a 3 :b 1 :c 2)
 
   (defn flat-map-seq [m]
 (if (empty? m) '()
   (let [kv (first m)]
 (lazy-cons (kv 0) (lazy-cons (kv 1) (flat-map-seq (rest
 m))) ...and vice versa:
 
  (map-from-flat-collection {} [:a 3 :b 1 :c 2]) ; returns {:a 3,
 :b
1, :c 2}
 
   (defn map-from-flat-collection [c]
 (if (empty? c) {}
   (conj (map-from-flat-collection (rrest c)) [(first c) (frest
   c)])))
 
Anyone have any idiomatic ideas?
 
   Well, not sure how idiomatic this is; apart from conj, this is how
   you'd do it in Lisp/Scheme. I'd use fold to do the first function if
   it's built into Clojure.
 
   Regards,
 
   --
   Michel
 
   (apply assoc {} [:a 1 :b 2 :c 3])
   -   {:c 3, :b 2, :a 1}
   --
   The Mafia way is that we pursue larger goals under the guise of
   personal relationships.
  Fisheye
 
  user= (apply concat (seq {:c 3, :b 2, :a 1}))
  (:c 3 :b 2 :a 1)
  user=
 
  --
  The Mafia way is that we pursue larger goals under the guise of
  personal relationships.
  Fisheye
 


--~--~-~--~~~---~--~~
You 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?) bug

2008-11-11 Thread Brian Doyle
Yep, I'm going that route.  Thanks

On Tue, Nov 11, 2008 at 2:27 PM, Dave Newton [EMAIL PROTECTED] wrote:


 --- On Sun, 11/9/08, Brian Doyle wrote:
  Yes, it is a StringBuilder so technically yes.   I guess you
  since the only thing you ever do with a StringBuilder is produce a
  string it just seemed like it would be a string.   Same goes for
  StringBuffer.

 I'd say create your own (stringish? ...) function then--since Clojure is
 strongly Java-interop returning a T for a non-String would make (string?
 ...) seem less useful, but that's just my opinion.

 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
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?) bug

2008-11-09 Thread Brian Doyle
Yes, it is a StringBuilder so technically yes.   I guess you since the only
thing you ever do with a StringBuilder is produce a string it just seemed
like
it would be a string.   Same goes for StringBuffer.

On Sat, Nov 8, 2008 at 11:52 PM, Dave [EMAIL PROTECTED] wrote:


 (Sorry if this is a repeat; hotel networking is sketchy.)

 On Nov 9, 12:07 am, Brian Doyle [EMAIL PROTECTED] wrote:
  This seems like a bug returning false for StringBuilder.
 
  user= (string? (new java.lang.String hello))
  true
 
  user= (string? (new java.lang.StringBuilder hello))
  false

 Wouldn't it be a StringBuilder, not a String?

 user= (. (new java.lang.StringBuilder hello) getClass)
 #=java.lang.StringBuilder
 user= (string? (. (new java.lang.StringBuilder hello) toString))
 true

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



slurp accepting an encoding parameter

2008-11-07 Thread Brian Doyle
I had a file that was not encoded using the default file encoding so I
modified slurp to accept an optional encoding parameter.

(defn slurp
  Reads the file named by f into a string and returns it. Uses the given
encoding
  when opening the file.
  ([#^String f encoding]
(with-open r (if encoding
   (new java.io.BufferedReader (new
java.io.InputStreamReader(new java.io.FileInputStream f), encoding))
   (new java.io.BufferedReader (new java.io.FileReader f)))
  (let [sb (new StringBuilder)]
(loop [c (. r (read))]
  (if (neg? c)
(str sb)
 (do
(. sb (append (char c)))
(recur (. r (read)
  Reads the file named by f into a string and returns it. Uses the default
encoding
  when opening the file.
  ([#^String f] (slurp f 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
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
-~--~~~~--~~--~--~---



Clojure Maven integration

2008-11-06 Thread Brian Doyle
Does anyone know of any Clojure maven integration?
What I'd like to see is something that will modify Clojure's
classpath updated based upon a given pom.xml file.
Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Clojure group.
To post to this group, send email to clojure@googlegroups.com
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: lancet: Clojure controlling Ant

2008-11-06 Thread Brian Doyle
On Thu, Nov 6, 2008 at 11:48 AM, Stuart Halloway
[EMAIL PROTECTED]wrote:


 Hi all,

 I am playing around with using Clojure to control Ant, something along
 the lines of Groovy's Gant. I don't know how far I will take this--
 right now it is serving as a code example for the book.

 Two questions:

 (1) Anybody interested in seeing lancet carried forward into a real
 project?


Yes, I hate ant and pretty much anything would be better!  I might have
some time to help out with the implementation.




 (2) Below is an example of lancet syntax (compare with Clojure's own
 build.xml). Any big likes/dislikes?


No complaints from me.  I like the syntax.




 Cheers,
 Stuart

 (project {:name clojure :default jar}

  (properties :src src
 :jsrc (i :src /jvm)
 :cljsrc (i :src /clj)
 :build classes
 :clojure_jar clojure.jar
 :bootclj (i :cljsrc /clojure/boot.clj))

  (target {:name test}
   (echo {:message init target}))

  (target {:name compile :depends init
  :description Compile Java sources.}
   (javac {:srcdir (i :jsrc) :destdir (i :build)
  :includejavaruntime yes
  :debug true
  :target 1.5}))

  (target {:name init}
   (tstamp)
   (mkdir {:dir (i :build)}))

  (target {:name clean
  :description Remove autogenerated files and directories}
   (delete {:dir (i :build)}))

 )


 


--~--~-~--~~~---~--~~
You 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: remainder function

2008-10-15 Thread Brian Doyle
The function is 'rem'.

user= (rem 5 2)
1


On Wed, Oct 15, 2008 at 3:35 PM, Islon [EMAIL PROTECTED] wrote:

 Is there a remainder (rest of the division) function in closure? (as java
 '%' operator).
 I browse the docs but couldn't find one.

 


--~--~-~--~~~---~--~~
You 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: equality and struct inheritance

2008-10-07 Thread Brian Doyle
On Tue, Oct 7, 2008 at 2:32 PM, Stuart Halloway
[EMAIL PROTECTED]wrote:


 Hi Brian,

 (1) What does it mean to be equal on id and not equal on the other
 fields? If two fields claim the same id but a different name, how
 would you know which one to keep?


I guess it could depend on the situation and you may not care about
the other fields at all, only on the id.   I'm used to Java/Ruby
when you define an equals and hashcode method that determines
equality which very well may be a subset of the total attributes on an
object.

(2) Given some answer to #1, why not store the structs in a map under
 id?


I could, but does this mean that I couldn't store the place objects in a set
to dedup the places?   It would appear that a struct uses all of the
attributes
of the map to determine equality.  I was hoping I could overwrite equality
for a given struct.




 (3) For the geocoded place struct, I would be tempted to just create a
 separate defstruct. Nothing in Clojure prevents the two different
 kinds of structures from being substituted for one another. You could
 look into make-hierarchy, etc. plus defmulti if you find that you need
 inheritance-like behavior for method dispatch.


Yes, I was just being somewhat lazy with this.  If I define 10 attributes
for a given struct and wanted to use all of those plus 3 more in a new
struct I didn't want to have to write out those original 10 attributes
again.

Thanks.






 Stuart

  I'm attempting to learn Clojure with a long history of OO and have
  some
  questions.I've created a defstruct for a place type object like:
 
  (defstruct place :id :name :street :city :state :zip)
 
  I want to write a function that would take a list of places and remove
  the duplicates.   Duplicates are defined by places having the
  same :id.
  I created a 'place' namespace and attempted to create a function
  called '=' that would only use the :id to compare two places, however,
  I was not about to create such a function name.   Is there a preferred
  function name for equality in this case?
 
  Coming from an OO background and wanting a geocoded-place
  struc is there a way to inherit from the place struct?   Something
  like take all of the existing keys from the place struct and also add
  :latitude  :longitude?
 
  Thanks.
 
 
 
 
 
  


 


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