Re: Simple clojure and contrib install, with SLIME ... ?

2010-02-12 Thread Michael Kohl
On Thu, Feb 11, 2010 at 7:59 PM, Paul  Mooser taron...@gmail.com wrote:
 are a few things that seem to try to make this easier (like clojure-
 mode's install-clojure, or ClojureX) but they also seem unable to keep
 up with the speed of some of the changes that are happening (or, quite
 possibly, I'm using them incorrectly or ineffectively).

In the case of ClojureX you are right, we are struggling a bit to keep
up with things right now since both Scott and I are rather busy
lately. I soon should have a bit more time again which will be used on
making some changes to the overall structure of the project.

Michael

-- 
http://citizen428.net | http://twitter.com/citizen428

ClojureX: http://github.com/citizen428/ClojureX/

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


Re: Request for Feedback: Improve VimClojure's documentation

2010-02-12 Thread Jeff Rose
I have setup VimClojure on Linux, Mac and Windows successfully.  (The
classpath stuff is a major annoyance though, and sometimes I think I
have problems with using different versions of clojure.jar.)  I also
get large error messages like the above though, which is extremely
annoying.  Especially since quite often it still works after popping
up this message.  I'll evaluate a function, and then the 'ng' process
will peg the CPU to 100% until I kill it by hand, and then this kind
of large error message comes up (often it looks like it lists
everything in the namespace), and then once I 'q' the message away
I'll see that the function I evaluated was successfully compiled and
then I can run it fine in the repl.  This namespace has over 400
functions (they are generated from meta-data and they represent DSP
unit generators), and it seems like that could be a source of the
problem, but I don't know.

I recently tried getting the latest version of the plugin from source
control, but now that there isn't a build.xml file included it is even
more troublesome to do an install.  I tried installing groovy and
whatever the new build script needs, but it failed and I got too
annoyed to continue.  How about leiningen?  I know it's not feature
full yet, but the way it will get there is by using it...

All that said, I have been using VimClojure virtually every day since
the first gorilla releases, so I am extremely grateful that you've put
in the work to create this.  Thanks!

-Jeff

On Feb 11, 6:44 pm, Drew Vogel drewpvo...@gmail.com wrote:
 I've pretty much stopped using VimClojure and, since I can't get a decent
 development environment working consistently, Clojure as well. I have more
 success getting VC to work under Linux. On Windows the experience is horrid.
 I cannot consistently get NGserver/ng.exe to communicate. The result is
 horrible error messages like the one in the attached screenshot. I don't
 have a solution to contribute because I've never consistently solved these
 problems. Good luck with this effort. I'd like to see VC become more
 accessible.

 On Sat, Jan 30, 2010 at 5:48 AM, Meikel Brandmeyer m...@kotka.de wrote:
  Dear vimming Clojurians,

  I want to populate the Bitbucket Wiki of VimClojure with tips and FAQs from
  the field. I'd like to collect the problems you hit, while using it and how
  you (hopefully) solved them.

  Please send me your suggestions for FAQ and other tips via private email or
  add a ticket in the bb tracker for the documentation component.

  Thank you in advance for helping to improve VimClojure!

  Sincerely
  Meikel

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



  vimclojureerror.png
 153KViewDownload

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


Re: Request for Feedback: Improve VimClojure's documentation

2010-02-12 Thread Meikel Brandmeyer
Hi,

On Feb 12, 1:06 pm, Jeff Rose ros...@gmail.com wrote:

 (The classpath stuff is a major annoyance though, and sometimes
 I think I have problems with using different versions of clojure.jar.)

This is possible. Since nailgun requires a named class I had to use
gen-class which ties the compiled code relatively tight to a
particular clojure version. This is solved in the latest dev version
however I haven't got to get another release out. (See also:
http://kotka.de/blog/2010/01/Why_macros_are_cool.html)

 I also get large error messages like the above though, which is extremely
 annoying.  Especially since quite often it still works after popping
 up this message.

Ironically these error message where a feature request. I provide a
stacktrace in the messages to make diagnosing the error easier.
However this is nothing more than a quick hack. I agree that I have to
rework this.

 I'll evaluate a function, and then the 'ng' process
 will peg the CPU to 100% until I kill it by hand, and then this kind
 of large error message comes up (often it looks like it lists
 everything in the namespace), and then once I 'q' the message away
 I'll see that the function I evaluated was successfully compiled and
 then I can run it fine in the repl.  This namespace has over 400
 functions (they are generated from meta-data and they represent DSP
 unit generators), and it seems like that could be a source of the
 problem, but I don't know.

Your description fits to a process generating a lot of output. May I
ask how you evaluate your function? ef? Or et?. I guess it's ef. This
will evaluate the whole file. So it fires off the generation of your
the DSP functions you mentioned. The output will look like this:

nil
#your.name.space/foo
#your.name.space/bar
#your.name.space/baz
...

This takes some time. You kill the ng process which basically kills
the evaluation somewhere in the middle. Because of the killed process
Vim thinks that something went wrong. Hence it will display the error
message. Unfortunately there is only one channel between Vim and the
outside world: the temporary file storing the process output. Normally
that's the normal process output (like above). If an error happened,
it will be the error message with the stacktrace. In our case however
nothing bad happened. So the already collected output file be attached
as error message. It should look like the above with spaces instead
of newlines.

If this is the case, please use et or get a cup of coffee and wait
till the process finishes. I can't do much more, because these are
limitations of Vim itself.

 I recently tried getting the latest version of the plugin from source
 control, but now that there isn't a build.xml file included it is even
 more troublesome to do an install.  I tried installing groovy and
 whatever the new build script needs, but it failed and I got too
 annoyed to continue.

You need only Gradle (self-contained) and clojuresque (on
clojars.org). Kresimir Sojat was kind enough to provide a short shell
script, which sets up a running dev version of VC with a single
command. I will include it in the next release.

 How about leiningen?  I know it's not feature
 full yet, but the way it will get there is by using it...

Leiningen does not fit my needs. And I don't want different build
systems for my projects.

 All that said, I have been using VimClojure virtually every day since
 the first gorilla releases, so I am extremely grateful that you've put
 in the work to create this.  Thanks!

Thanks for being loyal for so long. :)

Sincerely
Meikel

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


Re: Seattle Clojure meeting

2010-02-12 Thread Mark Tomko
Oh, man.  I just moved from Seattle to Boston in December, and I miss
Zoka's coffee.  Have fun, everyone!Maybe we can get some of the
Boston-area Clojure folks to meet up sometime.

On Feb 11, 7:30 pm, Phil Hagelberg p...@hagelb.org wrote:
 On Fri, Feb 5, 2010 at 12:50 PM, Phil Hagelberg p...@hagelb.org wrote:
  Wow, I certainly was not expecting that level of response; this is great.

  Looks like the 11th (Thursday) is the crowd favorite. Once again, the
  location ishttp://bit.ly/c9jinW

  We'll be meeting in the back. Zoka is a big place, but it can get
  crowded with all those college students around, so I'll try to save
  some space. Look for the laptop with the my other car is a cdr
  sticker, or for me; my photo is athttp://technomancy.us/colophon

 Just a reminder: this is tonight. I'd love to see you there.

 -Phil

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


Re: Help me make this more idiomatic clojure

2010-02-12 Thread Greg Bowyer
The (list) comes from my dabblings with other lisps, using a vector
does make more sense and I quite like it

I was unaware that, unless I am mistaken from your above code that let
bindings are evaluated left to right, that is I was under the
impression (incorrectly) that you could not use say vm in the next
binding form.

I like the examples you guys have posted they look my nicer than my
code, I guess I still have a lot of playing with clojure to do before
I start using it more effectively

Many thanks

-- Greg

On Feb 11, 8:56 pm, CuppoJava patrickli_2...@hotmail.com wrote:
 Most of that java code is just pasting together library function
 calls. I'm not sure if there's any more elegant ways of doing that.
 Your clojure code looks fine for the most part I think. It's mostly
 just a question of style. The only thing that sticks out is the call
 to (list). That's generally never needed in Clojure. You just use a
 vector instead.

 Here's how I would write your code. Nothing much has changed. Just
 personal style:

 (defn str-interpose [sep strings]
   (apply str (interpose sep strings)))

 (defn acquire-address [vm]
   (.getProperty (.getAgentProperties vm)
     com.sun.management.jmxremote.localConnectorAddress))

 (defn load-agent [vm]
   (.loadAgent vm
     (str-interpose File/separator
       [(.. vm getSystemProperties (getProperty java.home)) lib
 management-agent.jar])))

 (defn obtain-local-connection [vmid]
   (let [vm (VirtualMachine/attach vmid)
         address (or (acquire-address vm)
                     (do (load-agent vm) (acquire-address vm)))]
     (.detach vm)
     address))

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


Re: Request for Feedback: Improve VimClojure's documentation

2010-02-12 Thread Quzanti
I'll give the newbie perspective, which given as I did not really know
what I was doing may involve several false assumptions but will
provide insight into the thinking of a newbie, which may be a hard
frame of mind for experts to imagine.

Firstly when you are new you just want to get something working fast.
I didn't want some snazzy dev environment to wrestle with, I just
wanted some syntax highlighting and maybe some code completion.

The first thing you do is look for recent news on enclojure,
vimClojure etc, and they all looked to be several months old. You
always wonder whether people have moved on, worried Netbeans will be
discontinued by Oracle etc or whatever. So for cutting edge projects
releases or at least news every 6 weeks or so are needed to convince
people the project in still in development.

I looked at all of them and would have liked to go with VIM as I am a
VIM user. For VIM it looked like I was going to have to go though some
elaborate procedure (there was a webcast for it) rather than just
stuff a config file in a directory so I decided to leave off that
until support got built into the standard Ubuntu VIM release (debian
or whatever).

I tried enclojure with the latest netbeans and got a pile of errors so
gave up.

I tried the emacs mode and didn't get very far, largely because of my
lack of emacs knowledge.

Then I realised trusty old jedit had an clojure mode, which worked out
of the box bar one small change in the patterns file (it needed
prodding to map .clj to the clojure mode)

So there I was with some pretty decent syntax formatting from jedit,
the clojure and clojure contrib jars on my classpath and wow the REPL
worked. I could type stuff in, I could test functions I was away.
Yippee.

That's all a newbie with a weekend to spare wants. When I get more
experience of clojure and what my personal pain points and time
consuming things are then I might try some of the more elaborate dev
environments again to see if they help.

So to answer your question a  - be up and running with minimal fuss in
three minutes with perhaps not all the bells and whistles 'Getting
started' page - would be a real help to cater for one section of the
community.

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


Clojure, Lejos, Robust and Lego Mindstorms NXT

2010-02-12 Thread kony
Hi all,

some time ago I wrote a simple control library (called Robust) for
Lego Mindstorms NXT.
Recently I wrote a Clojure wrapper to the Robust library so that it is
possible to write simple control applications for standard Mindstorms'
vehicles directly in Clojure.

The Robust library together with Clojure interface (cljRobust) can be
found at
http://sourceforge.net/projects/robust/

enjoy,
Konrad Kulakowski

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


Re: Request for Feedback: Improve VimClojure's documentation

2010-02-12 Thread Adrian Cuthbertson
I'd like to pitch in here as I think it's distressing to see (vim
familiar) people abandoning clojure when it's quite possible to have
an easy and very efficient working environment using just vim,
vimclojure and rlwrap. I set this up 14 months ago when I started with
clojure and I'd be dragged kicking and screaming to have to use
anything else.

Just to describe what I'm seeing in front of me on a 15 laptop and a
32 external screen as I type;
- Three instances of MacVim, each with about 6 to 12 tabs open with
various clojure and other files.
- Two instances of Terminal, each with about 8 console tabs in various
directories on my local machine and also various ssh sessions on a few
remote servers.
- One instance of Netbeans with about 10 tabs of various java, html,
jsp (yes, I still have to do legacy Jsp stuff), javascript, etc. I
don't use Enclojure on Netbeans as I've just not got around to trying
it. So all my clojure work is done in vim/rlwrap.
- All the other cruft one normally has, e.g (Mail, a few instances of
Firefox, etc).

So, what is a typical sequence of events?
- Option-tab to a particular MacVim instance
- gT to get to a particular tab, or maybe :tabe to open a new file in a tab
- Make a change, :w to save
- Option-tab to a Terminal instance
- Option-shift-right-arrow to a particular terminal tab running the
Repl in rlwrap
- type (use and press up arrow to get last (use 'some-ns.some-fn :reload)
- press Enter to execute. Dabble in the Repl. Use mouse to select from
console, copy and paste into MacVim
- Option-tab to Terminal/ bash session, up-arrow, run previous scp to
copy stuff to server
- Option-tab to Terminal/ssh session running vim on server, quick
change to script, :w
- Option-tab to Terminal/ssh session running repl, recall last clojure
(use, etc, etc
All in the spirit of a good ole unix hacker who eschews the use of the mouse :).

I'll describe my setup so hopefully others can be similarly
empowered. Generally I work on a MacBook Pro OS/X 10.5 with JDK 1.6,
but I also run the same clojure setup on a number of servers running
either Arch Linux or Ubuntu. These I access through ssh terminal
sessions. On the Mac I have MacVim installed (as it has great mouse
support (my mouse sentiment notwithstanding) and handles Mac-like
copy, paste, etc), and on the Linuxes, just vim 7.2. I only installed
the vimclojure syntax and indent plugins, but I haven't used the rest.
Rlwrap is installed through Mac-ports and the package managers on
Arch/Ubuntu. Rlwrap allows you to wrap a terminal/console session and
use really great history recall and line-editing features. Now for the
setup part;

Firstly,  the following .inputrc on the mac...
cat ~/.inputrc...
\e[A: history-search-backward
\e[B: history-search-forward
set completion-ignore-case on
set show-all-if-ambiguous on
$if Bash
  Space: magic-space
$endif

and in /etc/inputrc on linux, the following two lines added...
\e[5~: history-search-backward
\e[6~: history-search-forward

The above allows you to use the up/dn, pgup,pgdn keys to do partial
command line history recall. If you have that, you don't need any
other history recall features. You can then type just the first few
characters of a command, press the up arrow and cycle through all
previous command entries starting with those characters. Of course you
still have all the other command line editing capabilities provided by
readline, e.g, ctrl-e, ctrl-a, ctrl-r, etc.

Java setup; I have a ~/Downloads directory for all downloaded pakages,
libraries, etc. Different versions all go in the same directory, but
under their own sub-tree. E.g
~/Downloads/Apache/lucene-2.9.0/...
~/Downloads/Apache/lucene-3.0.0/...
~/Downloads/Clojure/clojure_1.0.0/...
and so on. Then I have a root directory /jx in which I create symbolic
links for different logical (at least to me) sets of jars from the
above downloads, eg:
ls -l /jx/cl
... clojure-contrib.jar -
/Users/adrian/Downloads/Clojure/clojure-contrib/clojure-contrib.jar
... clojure.jar -
/Users/adrian/Downloads/Clojure/clojure/clojure-1.1.0-master-SNAPSHOT.jar
ls -l /jx/luc
... lucene-analyzers.jar -
/Users/adrian/Downloads/apache/lucene-3.0.0/contrib/analyzers/common/lucene-analyzers-3.0.0.jar
... lucene-core.jar -
/Users/adrian/Downloads/apache/lucene-3.0.0/lucene-core-3.0.0.jar
(I maintain the links with a single bash script).

For running the repl, I use simple bash scripts in each working
directory where I have clojure projects/source;
#!/bin/bash
source /Users/adrian/bin/dirj.sh
dirj /jx/cl
dirj /jx/jty/lib/
dirj /jx/luc
EXTRAS=/jx/misc/quartz.jar:/jx/misc/commons-logging.jar
CP=./:./classes:$EXTRAS:$CP
OPTS='-Dorg.mortbay.util.FileResource.checkAliases=false -Xms32M
-Xmx512M -server'
echo $CP
exec rlwrap java $OPTS -cp $CP clojure.main $1 $2 $3 $4 $5 $6 $7 $8 $9

You'll notice the above uses dirj.sh which is a little script that
sucks in all the jars in a particular directory.
This (at least the idea) is courtesy of either Stuart Sierra, or
Chouser 

Re: Help me make this more idiomatic clojure

2010-02-12 Thread CuppoJava
Yup, literal syntax for vectors are very convenient and heavily used
in Clojure code.

And (let) bindings are evaluated left to right. It's analogous to
Scheme's let* i think?

Only thing to watch out for is that (binding) bindings are not
evaluated left to right. It's for performance reasons I think, though
I'm not sure.

  -Patrick

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


Re: Presentatie over Clojure

2010-02-12 Thread Joop Kiefte
Sorry for the 3rd post, but can someone provide some nice example-code for
functional structures used in real world code?

2010/2/12 Jeff Rose ros...@gmail.com

 Cool!  This is the most fun I've ever had practicing Dutch :-)

 As someone who used to be very skeptical towards functional programming and
 Lisps, I think it would be good to have some examples to show what you mean
 about things being cleaner and simpler in functional Clojure.  I think
 comparing a typical for loop that transforms an array with mapping a
 function over a seq, or something like that, would make for a nice example.
 The other big thing to talk about is immutable values.  Nobody can know what
 this code produces, whether single or multi-threaded, which seems to be the
 heart of the problem with object orientation:

 def foo(obj)
   obj.val = 2
   obj.do_stuff()
   return obj.val
 end

 -Jeff



 On Fri, Feb 12, 2010 at 4:39 PM, Joop Kiefte iko...@gmail.com wrote:

 Graag commentaar

 --
 Communication is essential. So we need decent tools when communication is
 lacking, when language capability is hard to acquire...

 - http://esperanto.net  - http://esperanto-jongeren.nl

 Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004





-- 
Communication is essential. So we need decent tools when communication is
lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

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

Re: Clojure and OOP

2010-02-12 Thread Daniel Simms
On Thu, Feb 11, 2010 at 4:46 AM, HB hubaghd...@gmail.com wrote:
 Since Clojure is a LISP dialect, does this mean that it doesn't
 support OOP?

Another answer is that ``it could be if you wanted it to be'', for example:


http://s-expressions.com/2009/12/10/frumios-a-silly-object-system-for-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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


How to catch exception and keep looping?

2010-02-12 Thread Konrad Kułakowski
I have a piece of code like this:

(def ll ['a 'b 'c 'd])

(loop [e (first ll) f (rest ll)]
  (do
(try
   (do
  (println e) ;; do sth with e which may throw an exception
  (recur (first f) (rest f)))
  (catch Exception _ (println ex)))
(println something)
(recur (first ll) f (rest ll))
))


as a result I've got a message:
java.lang.IllegalArgumentException: Mismatched argument count to
recur, expected: 0 args, got: 2

So, my question is how to catch exception and do something with them
and keep looping?

Does anyone know any solution/workaround of this problem?

Konrad

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


Re: How to catch exception and keep looping?

2010-02-12 Thread Michał Kwiatkowski
2010/2/12 Konrad Kułakowski kulakow...@gmail.com:
 I have a piece of code like this:

 (def ll ['a 'b 'c 'd])

 (loop [e (first ll) f (rest ll)]
  (do
    (try
       (do
          (println e) ;; do sth with e which may throw an exception
          (recur (first f) (rest f)))
      (catch Exception _ (println ex)))
    (println something)
    (recur (first ll) f (rest ll))
 ))


 as a result I've got a message:
 java.lang.IllegalArgumentException: Mismatched argument count to
 recur, expected: 0 args, got: 2

 So, my question is how to catch exception and do something with them
 and keep looping?

You're clearly doing something for side effects, so why not use doseq instead?

(def alist ['a 'b 'c 'd])

(doseq [e alist]
 (try
  (println e) ;; may throw exception here
  (catch Exception _ (println ex

Cheers,
mk

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


Re: Multimethods vs. cond?

2010-02-12 Thread Daniel Werner
On Feb 11, 4:04 pm, Bryce fiat.mo...@gmail.com wrote:
 I'm wondering what the rationale is for using multimethods vs. cond,
 and where it's best to use either?  Multimethods seem to be very
 seldom used, usually to dispatch on type, but I can see advantages to
 using data to dynamically define only the methods you need, rather
 than having all-encompassing cond statements.  It also seems like
 generally cleaner code.  Is there a speed benefit to one or the other?

You may also be interested in using pattern matching. It allows
dispatching based on structure or equality of your values, somewhat
similar to what you could do in Haskell or OCaml:

http://www.brool.com/index.php/pattern-matching-in-clojure

Being mostly a glorified cond, however, it shares the same lack of the
Open/Close principle, as Laurent put it. For the most trivial of
cases, when openness is not an issue, you may even get away with using
a map (as in some parts of clojure.contrib, I believe):

(def month-name {1 January, 2 February, 3 March, ...})

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


newbie question re-seq

2010-02-12 Thread Brian Wolf

Hi,

This is from the book:

(re-seq \w+ the quick brown fox)
- (the quick brown fox)

But when I try it,  these don't work:

user (re-seq \w+ the quick brown fox)
; Evaluation aborted.

clojure.lang.LispReader$ReaderException: java.lang.Exception: 
Unsupported character: \w+ (NO_SOURCE_FILE:0)

 [Thrown class clojure.lang.Compiler$CompilerException]

user (re-seq \\w+ the quick brown fox)
; Evaluation aborted.

clojure.lang.LispReader$ReaderException: java.lang.Exception: 
Unsupported character: \\w+ (NO_SOURCE_FILE:0)

 [Thrown class clojure.lang.Compiler$CompilerException]




user (+ 2 2)
4

Thanks
Brian

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


Re: newbie question re-seq

2010-02-12 Thread Michał Marczyk
Replace \w+ with #\w+.

(#... is the regex literal syntax.)

Sincerely,
Michał

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


Re: newbie question re-seq

2010-02-12 Thread Brian Wolf


Thanks,

I wonder why the book doesn't use that?


Michał Marczyk wrote:

Replace \w+ with #\w+.

(#... is the regex literal syntax.)

Sincerely,
Michał

  


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


Re: Presentatie over Clojure

2010-02-12 Thread Joost
A Very Simple Example:

(defn list-projects
  [request posts]
  (wrap request :project
   (text :projects)
   (map project-block posts)
   (link-to /project/edit/ new)))

That's a top-level view function from a (nearly) production site I'm
working at right now.

Note:

Clean readable code. This doesn't use any particular new or fancy
feature of clojure. All it is pretty much standard LISP with no side
effects. No macros or anything like that. Automatically thread safe.

Uses (map project-block posts) to translate a list of project
descriptions (a seq of nested maps) into a structured display format,
and project-block is simply a function that translates a single
project description into the required format (in this case,
compojure's generator format). Try doing that with a C-style for loop.

If you're presenting to non-functional programmers, I'd concentrate on
the basic and immediately useful stuff: map is one of the most useful
things I can think of - it pops up everywhere. reduce may be cooler,
but you're not going to use it nearly as much.

From that project: total lines (including whitespace, comments etc):
less than 2000. Total uses of (map) - excluding macros that embed it:
78. That's a map call almost 8% of every line. If I'd had to guess,
I'd say that at least half of my loops are done using plain map.

Besides:

new Array arr;
(for i =0; i  list.length; i++)  {
  arr[i] = inputArr[i]+1;
]
return arr;

vs

(map inc inputArr)

And who's going to argue?

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


Help! Clojuresque build failed

2010-02-12 Thread sailormoo...@gmail.com
Hi:

  I am not familiar with gradle, but I cannot build clojuresque, so I
cannot build clojureql.
The log building clojuresque is as follows :

  Thanks for any help.

D:\tools\clojuresquegradle build
:compileJava
:compileGroovy
07:19:24.781 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:antlib:org.apac
he.tools.ant] Could not load definitions from resource org/apache/
tools/ant/antl
ib.xml. It could not be found.
07:19:24.796 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter - Class
org.codehaus.g
roovy.ant.Groovyc loaded from parent loader (parentFirst)
07:19:24.796 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -  +Datatype
groovyc o
rg.codehaus.groovy.ant.Groovyc
07:19:24.828 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter - fileset:
Setup scann
er in dir D:\tools\clojuresque\src\main\groovy with
patternSet{ includes: [] exc
ludes: [] }
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojureCompileTask.groovy omitted as D:\tools\clojuresque\build
\classes\ma
in\clojuresque\ClojureCompileTask.class is up to date.
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojurePlugin.groovy omitted as D:\tools\clojuresque\build
\classes\main\cl
ojuresque\ClojurePlugin.class is up to date.
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojurePluginConvention.groovy omitted as D:\tools\clojuresque
\build\class
es\main\clojuresque\ClojurePluginConvention.class is up to date.
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojureSourceSet.groovy omitted as D:\tools\clojuresque\build
\classes\main
\clojuresque\ClojureSourceSet.class is up to date.
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\DefaultClojureSourceSet.groovy omitted as D:\tools\clojuresque
\build\class
es\main\clojuresque\DefaultClojureSourceSet.class is up to date.
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojureCompileTask.groovy skipped - don't know how to handle it
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojurePlugin.groovy skipped - don't know how to handle it
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojurePluginConvention.groovy skipped - don't know how to
handle it
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\ClojureSourceSet.groovy skipped - don't know how to handle it
07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
[ant:groovyc] clojur
esque\DefaultClojureSourceSet.groovy skipped - don't know how to
handle it
:processResources
:classes
:compileTestJava
:compileTestGroovy
:processTestResources
:testClasses
:test

BUILD SUCCESSFUL

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


clojure-protobuf

2010-02-12 Thread ninjudd
Hello All,

I just finished version 1 of a clojure wrapper for protocol buffers:
http://github.com/ninjudd/clojure-protobuf

I'm using it as a data storage format for an embedded graph db I'm
working on. It ends up being much faster than pr-str/read-string.

If you're interested in fast serialization/deserialization, please
check it out. I tried to make it as clojure-friendly as possible, but
I'm open to suggestions for improvements.

Cheers,
Justin

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


Re: Help! Clojuresque build failed

2010-02-12 Thread Nicolas Buduroi
I'm not sure about this one but I'll guess that your setup can't
compile Groovy scripts. I can't help you there as I didn't installed
it myself.

By the way, you don't need to build clojuresque, Gradle will take care
of downloading it if specified as a dependency. Look at the
build.gradle config file in ClojureQL repository. Post the exception
you're getting if you're having problems running gradle build on
ClojureQL instead.

On Feb 12, 6:27 pm, sailormoo...@gmail.com sailormoo...@gmail.com
wrote:
 Hi:

   I am not familiar with gradle, but I cannot build clojuresque, so I
 cannot build clojureql.
 The log building clojuresque is as follows :

   Thanks for any help.

 D:\tools\clojuresquegradle build
 :compileJava
 :compileGroovy
 07:19:24.781 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:antlib:org.apac
 he.tools.ant] Could not load definitions from resource org/apache/
 tools/ant/antl
 ib.xml. It could not be found.
 07:19:24.796 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter - Class
 org.codehaus.g
 roovy.ant.Groovyc loaded from parent loader (parentFirst)
 07:19:24.796 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -  +Datatype
 groovyc o
 rg.codehaus.groovy.ant.Groovyc
 07:19:24.828 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter - fileset:
 Setup scann
 er in dir D:\tools\clojuresque\src\main\groovy with
 patternSet{ includes: [] exc
 ludes: [] }
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojureCompileTask.groovy omitted as D:\tools\clojuresque\build
 \classes\ma
 in\clojuresque\ClojureCompileTask.class is up to date.
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojurePlugin.groovy omitted as D:\tools\clojuresque\build
 \classes\main\cl
 ojuresque\ClojurePlugin.class is up to date.
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojurePluginConvention.groovy omitted as D:\tools\clojuresque
 \build\class
 es\main\clojuresque\ClojurePluginConvention.class is up to date.
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojureSourceSet.groovy omitted as D:\tools\clojuresque\build
 \classes\main
 \clojuresque\ClojureSourceSet.class is up to date.
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\DefaultClojureSourceSet.groovy omitted as D:\tools\clojuresque
 \build\class
 es\main\clojuresque\DefaultClojureSourceSet.class is up to date.
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojureCompileTask.groovy skipped - don't know how to handle it
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojurePlugin.groovy skipped - don't know how to handle it
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojurePluginConvention.groovy skipped - don't know how to
 handle it
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\ClojureSourceSet.groovy skipped - don't know how to handle it
 07:19:24.843 [main] DEBUG o.g.a.i.p.ant.AntLoggingAdapter -
 [ant:groovyc] clojur
 esque\DefaultClojureSourceSet.groovy skipped - don't know how to
 handle it
 :processResources
 :classes
 :compileTestJava
 :compileTestGroovy
 :processTestResources
 :testClasses
 :test

 BUILD SUCCESSFUL

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


Re: refs, agents and add-watch

2010-02-12 Thread MiltondSilva
@all: Thank you very much for the replies. My bottomless pit of
ignorance must be quite annoying but, I can only hope one day to be in
your position. (e.g. answering others questions)

@ataggart: A different entity is supposed to change the refs when they
go over/under some limit. It's just the way the problem is specified
and it's a purely academic problem so, it doesn't need to make much
sense.

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


Re: Seattle Clojure meeting

2010-02-12 Thread Phil Hagelberg
On Thu, Feb 11, 2010 at 4:30 PM, Phil Hagelberg p...@hagelb.org wrote:
 On Fri, Feb 5, 2010 at 12:50 PM, Phil Hagelberg p...@hagelb.org wrote:
 Wow, I certainly was not expecting that level of response; this is great.

 Looks like the 11th (Thursday) is the crowd favorite. Once again, the
 location is http://bit.ly/c9jinW

 Just a reminder: this is tonight. I'd love to see you there.

We had our first meeting last night, and I'd say it was a big success.
We got 11 hackers packed into the back of the coffee shop and
discussed such things as Incanter and Leiningen and even had a
multi-laptop GNU Screen-shared demo of the debug-repl. Since the
response was so positive we will probably try to make it into a
regular occurrence, tentatively the first Thursday of the month.

The only problem is we need a name for the group. I'm tempted to call
it Seajure in an attempt poke fun at the silly names often chosen for
Clojure projects, but perhaps that's a bit much. Thoughts?

-Phil

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


Which do you prefer, expressing points in {:x 0, :y 0} or [0 0]?

2010-02-12 Thread Hozumi
Hi,all
Although there is no right answer, vector seem to be preferred in many
cases.
Which do you prefer map or vector?
Thanks!

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


Re: Seattle Clojure meeting

2010-02-12 Thread Garth Sheldon-Coulson
It's great to hear the Seattle event was such a success! Mark, I agree that
a Boston-area meet-up would be fun. If someone is interested in
spearheading, I would be happy to support in any way I can.

On Fri, Feb 12, 2010 at 7:58 AM, Mark Tomko mjt0...@gmail.com wrote:

 Oh, man.  I just moved from Seattle to Boston in December, and I miss
 Zoka's coffee.  Have fun, everyone!Maybe we can get some of the
 Boston-area Clojure folks to meet up sometime.

 On Feb 11, 7:30 pm, Phil Hagelberg p...@hagelb.org wrote:
  On Fri, Feb 5, 2010 at 12:50 PM, Phil Hagelberg p...@hagelb.org wrote:
   Wow, I certainly was not expecting that level of response; this is
 great.
 
   Looks like the 11th (Thursday) is the crowd favorite. Once again, the
   location ishttp://bit.ly/c9jinW
 
   We'll be meeting in the back. Zoka is a big place, but it can get
   crowded with all those college students around, so I'll try to save
   some space. Look for the laptop with the my other car is a cdr
   sticker, or for me; my photo is athttp://technomancy.us/colophon
 
  Just a reminder: this is tonight. I'd love to see you there.
 
  -Phil

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


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

Re: Which do you prefer, expressing points in {:x 0, :y 0} or [0 0]?

2010-02-12 Thread Garth Sheldon-Coulson
I have confronted a similar question in the past when deciding how to label
the dimensions of vectors and multidimensional arrays.

My tentative conclusion is that it's best to use raw vectors.

= (def v [40 41 42])
#'user/v

If you need human-readable labels, build a separate index with constant
lookup.

= (def vindex {:x 0 :y 1 :z 2})
#'user/vindex
= (v (:z vindex))
42

You can put v and vindex in a single hashmap or class or type or whatever.

There are all kinds of reasons for this. The main one is that your data
proper remains in a pure array-like data structure and can easily be
processed by high-performance algorithms for things like array slicing and
transposition, not to mention mathematical routines. The fact that you're
putting human-readable names on your indices is just a convenience.

Moreover, every time you want to get a sequence of elements out of your
vector, you don't want to have to loop through the hashmap pulling the
elements out in the right order. Mathematical vectors are orderful things
and should be represented in an orderful data structure. Clojure vectors are
ordered. Hashmaps are unordered.

That's the conclusion I have come to, at any rate.

Garth

On Fri, Feb 12, 2010 at 10:36 PM, Hozumi fat...@googlemail.com wrote:

 Hi,all
 Although there is no right answer, vector seem to be preferred in many
 cases.
 Which do you prefer map or vector?
 Thanks!

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


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

Re: Clojure/SLIME/Emacs questions

2010-02-12 Thread Ramakrishnan Muthukrishnan
On Sat, Feb 13, 2010 at 5:48 AM, Steven E. Harris s...@panix.com wrote:
 Phil Hagelberg p...@hagelb.org writes:

 Upstream slime is not compatible with swank-clojure

 I find this not to be true at present, the stilted SLIME/Swank
 connection problem¹ and disabling autodoc mode notwithstanding.

Yes, I too use slime upstream and avoid elpa. I can't seem to get auto
completion to work with Java functions which some folks on the irc
said they could. Otherwise it works fine for me.

-- 
  Ramakrishnan

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


Re: Which do you prefer, expressing points in {:x 0, :y 0} or [0 0]?

2010-02-12 Thread Hozumi
Hi,Gaarth.
Thank you for helpful advice.


On 2月13日, 午後1:03, Garth Sheldon-Coulson g...@mit.edu wrote:
 I have confronted a similar question in the past when deciding how to label
 the dimensions of vectors and multidimensional arrays.

 My tentative conclusion is that it's best to use raw vectors.

 = (def v [40 41 42])
 #'user/v

 If you need human-readable labels, build a separate index with constant
 lookup.

 = (def vindex {:x 0 :y 1 :z 2})
 #'user/vindex
 = (v (:z vindex))
 42

 You can put v and vindex in a single hashmap or class or type or whatever.

 There are all kinds of reasons for this. The main one is that your data
 proper remains in a pure array-like data structure and can easily be
 processed by high-performance algorithms for things like array slicing and
 transposition, not to mention mathematical routines. The fact that you're
 putting human-readable names on your indices is just a convenience.

 Moreover, every time you want to get a sequence of elements out of your
 vector, you don't want to have to loop through the hashmap pulling the
 elements out in the right order. Mathematical vectors are orderful things
 and should be represented in an orderful data structure. Clojure vectors are
 ordered. Hashmaps are unordered.

 That's the conclusion I have come to, at any rate.

 Garth



 On Fri, Feb 12, 2010 at 10:36 PM, Hozumi fat...@googlemail.com wrote:
  Hi,all
  Although there is no right answer, vector seem to be preferred in many
  cases.
  Which do you prefer map or vector?
  Thanks!

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

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


Re: How to catch exception and keep looping?

2010-02-12 Thread Adrian Cuthbertson
Here's an idiomatic way of doing what you want;

(defn lp [col]
  (loop [ll (seq col)]
(when ll
  (try
(let [itm (first ll)]
  (if (= itm 'x) (throw (IllegalArgumentException.
   (str itm  not supported.)))
(println (str done item:  itm
(catch Exception ex (println (.getMessage ex
  (recur (next ll
  (println done loop))

user= (lp ['a 'b 'x 'd])
done item: a
done item: b
x not supported.
done item: d
done loop

One can use (doseq for a simple example like this, but the above
pattern is useful for doing complex things in the outer loop, eg
accumulating collections, iterating multiple reads in parallel, etc.

Here's a more complex but realistic example; Say we want to loop
through some collection, and for each item, read the next line in a
file, process it (which may throw an exception), write the result to
an output file and accumulate only the successful items in a vector
which is returned to the caller...

(defn lpx
  [col f-in f-out]
  (with-open [fin (BufferedReader. (FileReader. (File. f-in)))
  fout (PrintWriter. f-out)]
(loop [ll (seq col) rec (.readLine fin) cum []]
  (if (and ll rec)
(let [itm (first ll)
  cum (try
(if (= itm 'x) (throw (IllegalArgumentException.
(str rec  error, ignored.)))
  (do (.println fout (str itm : rec))
(conj cum [itm rec])))
(catch Exception ex
  (do (.println fout (str itm : (.getMessage ex))) cum)))]
  (recur (next ll) (.readLine fin) cum))
cum

cat f1.txt
one
two
three
four
five

user= (lpx ['a 'b 'c 'd] f1.txt f2.txt)
[[a one] [b two] [c three] [d four]]
cat f2.txt
a:one
b:two
c:three
d:four

user= (lpx ['a 'b 'x 'd] f1.txt f2.txt)
[[a one] [b two] [d four]]
cat f2.txt
a:one
b:two
x:three error, ignored.
d:four

(There are functions in contrib which could also be used, but the
above illustrates reasonably core java interop, which is often
required in practice).

Just a clarification on the try/catch above - we're setting the local
cum to either the value calculated in the try or the one returned in
the catch. This is better illustrated below;

(defn xx [cum]
  (let [cum (try (if (= cum :x)
(throw (Exception. err))
cum)
(catch Exception ex [:err (.getMessage ex)]))]
cum))

user= (xx :a)
:a
user= (xx :x)
[:err err]

-Rgds, Adrian.

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


Re: Which do you prefer, expressing points in {:x 0, :y 0} or [0 0]?

2010-02-12 Thread Adrian Cuthbertson
I concur with Garth - structures like coordinates, points, etc are
non-changing in their structure and hence don't need mapped
references into their elements. Destructuring is the easy way to get
at the elements;
(let [[x y z] pt] ...
and they can be combined in collections, arrays, etc, and manipulated
a whole lot easier than equivalent hash maps.

My 2c.

On Sat, Feb 13, 2010 at 7:22 AM, Hozumi fat...@googlemail.com wrote:
 Hi,Gaarth.
 Thank you for helpful advice.


 On 2月13日, 午後1:03, Garth Sheldon-Coulson g...@mit.edu wrote:
 I have confronted a similar question in the past when deciding how to label
 the dimensions of vectors and multidimensional arrays.

 My tentative conclusion is that it's best to use raw vectors.

 = (def v [40 41 42])
 #'user/v

 If you need human-readable labels, build a separate index with constant
 lookup.

 = (def vindex {:x 0 :y 1 :z 2})
 #'user/vindex
 = (v (:z vindex))
 42

 You can put v and vindex in a single hashmap or class or type or whatever.

 There are all kinds of reasons for this. The main one is that your data
 proper remains in a pure array-like data structure and can easily be
 processed by high-performance algorithms for things like array slicing and
 transposition, not to mention mathematical routines. The fact that you're
 putting human-readable names on your indices is just a convenience.

 Moreover, every time you want to get a sequence of elements out of your
 vector, you don't want to have to loop through the hashmap pulling the
 elements out in the right order. Mathematical vectors are orderful things
 and should be represented in an orderful data structure. Clojure vectors are
 ordered. Hashmaps are unordered.

 That's the conclusion I have come to, at any rate.

 Garth



 On Fri, Feb 12, 2010 at 10:36 PM, Hozumi fat...@googlemail.com wrote:
  Hi,all
  Although there is no right answer, vector seem to be preferred in many
  cases.
  Which do you prefer map or vector?
  Thanks!

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

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

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