Re: best way to make use of association lists

2009-09-08 Thread kyle smith

Why not just use http://clojure.org/api#sorted-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
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: best way to make use of association lists

2009-09-08 Thread Richard Newman

 Why not just use http://clojure.org/api#sorted-map ?

Because an association list keeps insertion order, whilst a sorted-map  
keeps sorted order.

--~--~-~--~~~---~--~~
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: minor grievance with arithmetic on characters

2009-09-08 Thread Timothy Pratley

According to the docstring compare returns -1, 0 or 1:
user= (compare \b \g)
-5


Regards,
Tim.


On Sep 8, 2:02 pm, Adrian Cuthbertson adrian.cuthbert...@gmail.com
wrote:
 Clojure's compare;

 (compare \a \b)
 -1

 user= (doc compare)
 -
 clojure.core/compare
 ([x y])
   Comparator. Returns 0 if x equals y, -1 if x is logically 'less
   than' y, else 1. Same as Java x.compareTo(y) except it also works
   for nil, and compares numbers and collections in a type-independent
   manner. x must implement Comparable

 Rgds, Adrian.

 On Tue, Sep 8, 2009 at 5:50 AM, Timothy Pratleytimothyprat...@gmail.com 
 wrote:

  Is there a way to deal with this:
  user= ( \a \b)
  java.lang.ClassCastException: java.lang.Character cannot be cast to
  java.lang.Number (NO_SOURCE_FILE:0)

  So far the only things I know are to coerce or use interop eg:
  user= (.compareTo \a \b)
  -1
--~--~-~--~~~---~--~~
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 quickstart maven archetype

2009-09-08 Thread Scott Fleckenstein

Thanks Stuart,

Just an FYI, I added repl support to the clojure-maven-plugin here:
http://github.com/nullstyle/clojure-maven-plugin/tree/master

Rather than taking clojureshell's approach, I start a separate process
similar to how the rest of the plugin works.  In fact, I just needed
to refactory the abstract mojo used so that it can support an
interactive child process, and it came together super simply.  I think
it is a much more understandable approach than running clojure inside
the maven process, but that's just IMO.

Next on my list is to add jline support onto the archetype, and figure
out how best I want to support AOT along with Script execution.

-Scott

On Sep 7, 9:40 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 Also look at the ClojureShell Maven 
 plugin,http://github.com/fred-o/clojureshell-maven-plugin/tree/master
 which runs a REPL or Swank server.

 -SS

 On Sep 7, 10:41 pm, Mark Derricutt m...@talios.com wrote:

  Most definitely - I did have a repl goal for awhile but had issues with the
  input/output streams.  Looking at my github forkqueue I see someones pulled
  it back out (or added a new one, I've not yet had a look at it) which might
  be a starting point for you...
  But by all means - patches galore are welcome ;)

  --
  Pull me down under...

  Sent from Auckland, Auk, New Zealand

  On Tue, Sep 8, 2009 at 2:09 PM, Scott Fleckenstein 
  nullst...@gmail.comwrote:

   If I'm able to get a repl goal working, are you open to patches?
--~--~-~--~~~---~--~~
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-mode survey

2009-09-08 Thread Konrad Hinsen

On 8 Sep 2009, at 02:36, Phil Hagelberg wrote:

 However, now that clojure-mode has the M-x clojure-install command  
 that
 sets up SLIME etc, I don't know if the built-in subprocess features  
 are
 worth keeping around any more. Personally I have never used them or
 heard of anyone using them; I wonder if they are just legacy baggage.

 Would anyone be opposed to their removal?

What would the consequences be? Do I understand correctly that clojure- 
mode would no longer support Lisp interaction, and that installing  
SLIME would be required for every Emacs user?

Until now I have never even looked at SLIME, considering the number of  
difficulties I see reported by lots of people. Life is too short to  
waste on configuration problems... and in that category I am still  
busy dealing with Clojure's move to github. I still use clojure-mode  
with its basic interaction commands for all my Clojure hacking.

On the other hand, if SLIME installation is painless now, that would  
be fine with me as well.

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: dynamic :use

2009-09-08 Thread Chris Kent

James Sofra james.sofra at gmail.com writes:

 
 
 I know that this has come up before on the group and but is this not
 essentially dependency injection where the dependency being injected
 is a name space that presumably follows a particular convention in
 terms of what functions it provides?
 
 I remember people making it pretty clear that they didn't see the need
 for DI in Clojure so my question is, is this a useful approach? is
 there a better way?
 
 Cheers,
 James
 

Hi

I've often wondered about this in the context of testing, particular testing
code with side effects.  In an OO language I'd create an interface for the side
effecting code (I'm thinking of things like DAOs or messaging systems) and
create a mock or dummy implementation for my tests.

Selectively importing different namespaces that define the same set of functions
is treating namespaces like classes / interfaces.  I've never been sure whether
I should feel uncomfortable about this and whether there's a more idiomatic way
to achieve the same thing.  It feels like such a common requirement I'm
surprised there isn't a standard approach.  Although maybe that's the years of
OO programming clouding my thinking.

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



refer from inside of ns macro?

2009-09-08 Thread tmountain

Is it possible to refer from inside of the ns macro rather than doing
it after the fact? I've browsed the docs and don't see an obvious way
to do this. Right now I'm doing something like the following.

(ns foo
  (:require [bar]))

(refer 'bar)

-Travis
--~--~-~--~~~---~--~~
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: Looping idiom

2009-09-08 Thread songoku

On Sep 8, 5:39 am, Timothy Pratley timothyprat...@gmail.com wrote:
 Yet another way :)

 user= (map + (rest a) a)
 (3 5 7 9 11)

wow! i like your solution!

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

2009-09-08 Thread Rickard Bennekom

I only use SLIME for inf-Lisp jobs.
Clojure-update is a sensible complement to clojure-install, I'd
strongly vote for keeping it.


--~--~-~--~~~---~--~~
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: ns :require vs import

2009-09-08 Thread Kid Meier

On Sep 7, 10:40 pm, Sean Devlin francoisdev...@gmail.com wrote:
 Okay, syntax question.  When defining a namespace

 (ns my-ns
   (:require [clojure.contrib [str-utils2 :as s]])
   (:import (java.util Regex Date Etc)))

 Why does the require use a vector, and the import statement use a
 list?  Could they both be vectors? This confused me when using imports
 for a while.


Using vectors in import seems to work:

Clojure 1.1.0-alpha-SNAPSHOT
user= (ns blah (:import [java.util Collection Date]))
java.util.Date
blah= Collection
java.util.Collection
blah= Date
java.util.Date
blah=

I think the Clojure idiom is to prefer vectors over lists when
representing ordered data--this provides a semantic cue that we are
dealing with data and not a function call. It also prevents the need
for quoting (although in this example it is unnecessary because ns is
macro).

My guess is that the prevalence of using lists for the :import clause
is a legacy of the many former Lispers that have now become Clojure
users.

Or maybe there was a time when only a list was accepted?

/mike
--~--~-~--~~~---~--~~
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: refer from inside of ns macro?

2009-09-08 Thread tmountain

Nevermind... stupidly simple solution:

(ns foo
  (:use bar))

-Travis

On Sep 8, 8:11 am, tmountain tinymount...@gmail.com wrote:
 Is it possible to refer from inside of the ns macro rather than doing
 it after the fact? I've browsed the docs and don't see an obvious way
 to do this. Right now I'm doing something like the following.

 (ns foo
   (:require [bar]))

 (refer 'bar)

 -Travis
--~--~-~--~~~---~--~~
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: best way to make use of association lists

2009-09-08 Thread Conrad

Ah! ArrayMap! I missed that structure in the documentation!

That was exactly what I'm looking for.

On Sep 8, 1:09 am, Chouser chou...@gmail.com wrote:
 On Sep 7, 2009, at 5:19 PM, Conrad drc...@gmail.com wrote:



  Hi everyone! I have some data that consists of key/value pairs, but
  that need to maintain their order, in terms of when they were added to
  the list. In most lisps you'd do this with an association list, with a
  performance penalty of course if the alist gets too large.

 I've used array-map in a couple cases like this.  You can build it  
 with (apply array-map my-key-val-seq) and it will keep the order you  
 give it.  If you use assoc you're likly to get back a randomly-ordered  
 hash map, but sometimes you just don't need to do that.  This has the  
 same O(n) perf as alists.

 Another option to keep in mind is a struct map, which will give you  
 faster lookups and keep the order of the set of keys in the initial  
 definition.

 Between the two you may be able to get what you need for a lot of cases.

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



VimClojure - OpenSolaris - What am I doing wrong?

2009-09-08 Thread Michael Aldred

G'day,

I'm having a bit of trouble getting VimClojure working under
OpenSolaris 2009.06 (I'm currently using the development IPS
repository, however I still got the problem with the release
repository).

I'm compiled and installed vimclojure.jar, and ng.

Vim correctly detects and highlights .clj files as clojure files, and
I can start the ng server just fine:

java -cp /export/home/aldredmr/local/clojure/clojure.jar:/export/home/
aldredmr/local/clojure/clojure-contrib.jar:/export/home/aldredmr/local/
clojure/vimclojure.jar com.martiansoftware.nailgun.NGServer 127.0.0.1
NGServer started on 127.0.0.1, port 2113.

However, when start vim, e.g.:

gvim test.clj

vim starts up, and I get the following from the ng server:

java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readFully(DataInputStream.java:152)
at com.martiansoftware.nailgun.NGSession.run(Unknown Source)
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readFully(DataInputStream.java:152)
at com.martiansoftware.nailgun.NGSession.run(Unknown Source)

Entering in :nmap in vim, I get the following:

n  \K:call SNR2_PreGetPage(0)CR
n  gxPlugNetrwBrowseX
n  PlugNetrwBrowseX * :call netrw#NetrwBrowseX(expand(cWORD),0)
CR

So it seems I'm unable to start the REPL.

I've tried setting my CLASSPATH:

echo $CLASSPATH
/export/home/aldredmr/local/clojure/clojure.jar:/export/home/aldredmr/
local/clojure/clojure-contrib.jar:/export/aldredmr/local/clojure/
vimclojure.jar

I think I've narrowed the problem down to the ng client, when I try
ng ng-alias I get a core dump, so it appears that the ng client
doesn't like OpenSolaris.

--~--~-~--~~~---~--~~
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: VimClojure - OpenSolaris - What am I doing wrong?

2009-09-08 Thread Michael Aldred

I've found the problem.

The NailGun client assumes that the strlen function will handle a null
pointer for the argument.
Under Solaris this is not the case (http://technopark02.blogspot.com/
2006/04/solaris-null-pointer-bugs-usrlib00so1.html)

The problem is in sendText.

With Nailgun 0.7.1, this starts at line 203.

I did a quick check for a null:

void sendText(char chunkType, char *text) {
  int len = 0;
  if ( text ) {
len = strlen(text);
  }
  sendHeader(len, chunkType);
  sendAll(nailgunsocket, text, len);
}

and it seems to have fixed the problem, I've now got my REPL in
Vim. :)

On Sep 8, 9:10 pm, Michael Aldred mike.ald...@gmail.com wrote:
 G'day,

 I'm having a bit of trouble getting VimClojure working under
 OpenSolaris 2009.06 (I'm currently using the development IPS
 repository, however I still got the problem with the release
 repository).

 I'm compiled and installed vimclojure.jar, and ng.

 Vim correctly detects and highlights .clj files as clojure files, and
 I can start the ng server just fine:

 java -cp /export/home/aldredmr/local/clojure/clojure.jar:/export/home/
 aldredmr/local/clojure/clojure-contrib.jar:/export/home/aldredmr/local/
 clojure/vimclojure.jar com.martiansoftware.nailgun.NGServer 127.0.0.1
 NGServer started on 127.0.0.1, port 2113.

 However, when start vim, e.g.:

 gvim test.clj

 vim starts up, and I get the following from the ng server:

 java.io.EOFException
         at java.io.DataInputStream.readFully(DataInputStream.java:180)
         at java.io.DataInputStream.readFully(DataInputStream.java:152)
         at com.martiansoftware.nailgun.NGSession.run(Unknown Source)
 java.io.EOFException
         at java.io.DataInputStream.readFully(DataInputStream.java:180)
         at java.io.DataInputStream.readFully(DataInputStream.java:152)
         at com.martiansoftware.nailgun.NGSession.run(Unknown Source)

 Entering in :nmap in vim, I get the following:

 n  \K            :call SNR2_PreGetPage(0)CR
 n  gx            PlugNetrwBrowseX
 n  PlugNetrwBrowseX * :call netrw#NetrwBrowseX(expand(cWORD),0)
 CR

 So it seems I'm unable to start the REPL.

 I've tried setting my CLASSPATH:

 echo $CLASSPATH
 /export/home/aldredmr/local/clojure/clojure.jar:/export/home/aldredmr/
 local/clojure/clojure-contrib.jar:/export/aldredmr/local/clojure/
 vimclojure.jar

 I think I've narrowed the problem down to the ng client, when I try
 ng ng-alias I get a core dump, so it appears that the ng client
 doesn't like OpenSolaris.
--~--~-~--~~~---~--~~
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: best way to make use of association lists

2009-09-08 Thread Conrad

Thanks again everyone for the helpful replies- The clojure community
is definitely one of the languages's strengths.

On Sep 7, 5:19 pm, Conrad drc...@gmail.com wrote:
 Hi everyone! I have some data that consists of key/value pairs, but
 that need to maintain their order, in terms of when they were added to
 the list. In most lisps you'd do this with an association list, with a
 performance penalty of course if the alist gets too large.

 I was wondering if there's any consensus on how to deal with this type
 of data in Clojure yet. Clearly there is a partial alist support,
 since you can write things like (seq {:a 1 :b 2}) which essentially
 creates an alist- But no lookup function exists for this, I think.

 Alternatively, I suppose it would be possible to create a new type of
 map that performs better than an alist but can return items in the
 order they were added to the list, if desired (given the way maps are
 implemented in Clojure, this info may already be available internally
 as part of the implementation I would imagine- Is this exposed
 anywhere?)

 Anyway, I was just curious what people's thoughts were on this
 issue...

 -Conrad
--~--~-~--~~~---~--~~
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: best way to make use of association lists

2009-09-08 Thread B Smith-Mannschott

On Tue, Sep 8, 2009 at 15:22, Conraddrc...@gmail.com wrote:

 Ah! ArrayMap! I missed that structure in the documentation!

Well, I suspect there's a reason for that.

 That was exactly what I'm looking for.

Be aware that ArrayMap is something that Clojure uses internally only
to represent very small maps. Basically, it's an efficiency hack for
small maps and probably not so great for larger maps. More
importantly: the fact that it remembers the insertion order of keys is
just an artifact of its implementation, not part of a public contract
as far as I can tell.

// Ben

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



Re: Looping idiom

2009-09-08 Thread Sean Devlin

Very very slick :)

 On Sep 7, 11:39 pm, Timothy Pratley timothyprat...@gmail.com wrote:
  Yet another way :)
 
  user= (map + (rest a) a)
  (3 5 7 9 11)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



For Vimclojure users

2009-09-08 Thread Konrad Scorciapino

Hello, there!

Do you rebind vimclojure's default commands? I'm currently remapping
the most used ones, using [F9 F10 F11 F12] as [\et \p \ef \sr], and I
wonder if there is a more productive key scheme.

Cheers!

-- 
Et Forum delendum est!

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

2009-09-08 Thread Tom Faulhaber

Hi Phil,

Speaking for myself, I only use SLIME  emacs 23, though I certainly
wouldn't want to force anyone to do those things.

Also, one thing that I (and others) have noticed is that clojure mode
chokes on the #^{} form metadata on namespaces. (See any of the files
in clojure-contrib for an example.) I'm not able to reproduce the
problem now, so if you don't already know what it is, I'll keep my eye
out for it and send you a proper report when I have it happening.

Thanks for all your work on clojure-emacs integration. It makes all
the difference to us emacs heads!

Tom

On Sep 7, 5:36 pm, Phil Hagelberg p...@hagelb.org wrote:
 I'm working on cleaning up the code for clojure-mode.el, which provides
 Clojure support for Emacs.

 It includes some functionality for interacting with subprocesses. This
 is a small subset of the functionality of the functionality included in
 SLIME, but it's simpler and easier to configure.

 However, now that clojure-mode has the M-x clojure-install command that
 sets up SLIME etc, I don't know if the built-in subprocess features are
 worth keeping around any more. Personally I have never used them or
 heard of anyone using them; I wonder if they are just legacy baggage.

 Would anyone be opposed to their removal?

 thanks,
 Phil

 http://technomancy.us
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Unsupported binding form

2009-09-08 Thread Gorsal

#CompilerException java.lang.Exception: Unsupported binding form:
(G__1852 2) (NO_SOURCE_FILE:1182)
So, I'm porting Paul Grahm's condlet macro to clojure. I've done it
except when i evaluate it it gives me the above error. However, when I
macroexpand-1 it it evaluates fine.

The only difference between evaluating the macroexpansion vs the other
way is that the (gensym) vars are now regular variables in the
macroexpanded version. However, i don't see how this can affect it.

(condlet [((= 2 2) (a 2) (b 3))
 ((= 3 4) (a 1) (b 4) (c 34))]
  (print a)) -- throws error

macroexpanded version where lcond is equivalent to a lisp cond and
same for llet. This evaluates
just fine!

(clojure.core/letfn
  ((G__1840 [a b c] (print a)))
  (user/lcond
((= 2 2)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet ((G__1841 2) (G__1842 3)) (G__1840 G__1841 G__1842
G__1843
((= 3 4)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet
  ((G__1841 1) (G__1842 4) (G__1843 34))
  (G__1840 G__1841 G__1842 G__1843))

What am i missing here? I've heard of this same error with cond-let
and the guy changed it due to the 'new everything that lets must have
bracket regime'? What's this?
--~--~-~--~~~---~--~~
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: dynamic :use

2009-09-08 Thread Laurent PETIT
Hello,

So far there have been mentions of several techniques :

= using macro against *db-adapter* :
 * will work if *db-adapter* is set at compile-time (in a top level
expression before the macro call, or as a side effect of the invocation of
another macro before the macro call).
 * if you AOT-compile your code, you will not be able to change the choice
of the db in those environments that will use your lib (may be a feature or
a bug, depending on your use case, and whether your lib is meant to be
general or is the final artifact of a specific product).

= using (use) at runtime
 * much more dynamic
 * works as the one static singleton per JVM/clojure instance pattern in
java world

= using polymorphism
I would like to add this solution to the sandbox, since it seems to be even
more dynamic than the others, and much closer to a-la springframework
dependency injection for at least one use case:
 * you want to talk to different databases at the same time

I imagine that if you talk to different databases, you have some object that
holds the information concerning each database (holding connection string,
... I don't know what ...).
And that this object is used either implicitly (via dynamic binding), either
explicitly (presumably as their first argument) by the functions.

The idea is just to make these functions multimethods that will dispatch on
some type placed on the object representing the database.

First case : your API design uses a dynamic var to get the database object.
Your old code may look like :

(ns oracle)
(defn connect [...] (... ( *db*)))

(ns mysql)
(defn connect [...] (... (... *db*)))
;
; later in user code
; some magic with 'use

With multimethods and polymorphism, your new code may then look like :

(ns clj-database)
(defmulti connect-impl #(type %1))
(defn connect [ more] (apply connect-impl *db* more))

(ns oracle)
(defmethod connect-impl :oracle [*db* ...] )

(ns mysql)
(defmethod connect-impl :mysql [*db* ...] )

; later in user code
; in initialization code
(require 'mysql) ; or (require 'oracle) or whatever more dynamic way you may
want
; what you gain is that you can 'require several db impls at the same time !
(def *mysql-db* ...) ; somehow this code will add a :type metadata on the
object (just an example, multimethods allow you to do the dispatch
_as_you_want_)
(def *oracle-db* ...)
; in regular code
(require 'clj-database)
(binding [*db* *mysql-db*]
  (connect ..))

Few.

HTH,

-- 
Laurent


2009/9/8 Chris Kent cjk...@gmail.com


 James Sofra james.sofra at gmail.com writes:

 
 
  I know that this has come up before on the group and but is this not
  essentially dependency injection where the dependency being injected
  is a name space that presumably follows a particular convention in
  terms of what functions it provides?
 
  I remember people making it pretty clear that they didn't see the need
  for DI in Clojure so my question is, is this a useful approach? is
  there a better way?
 
  Cheers,
  James
 

 Hi

 I've often wondered about this in the context of testing, particular
 testing
 code with side effects.  In an OO language I'd create an interface for the
 side
 effecting code (I'm thinking of things like DAOs or messaging systems) and
 create a mock or dummy implementation for my tests.

 Selectively importing different namespaces that define the same set of
 functions
 is treating namespaces like classes / interfaces.  I've never been sure
 whether
 I should feel uncomfortable about this and whether there's a more idiomatic
 way
 to achieve the same thing.  It feels like such a common requirement I'm
 surprised there isn't a standard approach.  Although maybe that's the years
 of
 OO programming clouding my thinking.

 Cheers
 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
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: Unsupported binding form

2009-09-08 Thread Laurent PETIT
What's your current condlet definition ?

2009/9/8 Gorsal s...@tewebs.com


 #CompilerException java.lang.Exception: Unsupported binding form:
 (G__1852 2) (NO_SOURCE_FILE:1182)
 So, I'm porting Paul Grahm's condlet macro to clojure. I've done it
 except when i evaluate it it gives me the above error. However, when I
 macroexpand-1 it it evaluates fine.

 The only difference between evaluating the macroexpansion vs the other
 way is that the (gensym) vars are now regular variables in the
 macroexpanded version. However, i don't see how this can affect it.

 (condlet [((= 2 2) (a 2) (b 3))
 ((= 3 4) (a 1) (b 4) (c 34))]
  (print a)) -- throws error

 macroexpanded version where lcond is equivalent to a lisp cond and
 same for llet. This evaluates
 just fine!

 (clojure.core/letfn
  ((G__1840 [a b c] (print a)))
  (user/lcond
((= 2 2)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet ((G__1841 2) (G__1842 3)) (G__1840 G__1841 G__1842
 G__1843
((= 3 4)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet
  ((G__1841 1) (G__1842 4) (G__1843 34))
  (G__1840 G__1841 G__1842 G__1843))

 What am i missing here? I've heard of this same error with cond-let
 and the guy changed it due to the 'new everything that lets must have
 bracket regime'? What's this?
 


--~--~-~--~~~---~--~~
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: Unsupported binding form

2009-09-08 Thread Gorsal

(set! *print-level* 8) ;;so you can see all of macroexpand-1
;;MISC Utilities
;;
;;
(defn mklst [item] (if (list? item) item (list item)))

(defn lassoc [item lst]
  (first (filter #(= (first (mklst %)) item) lst)))

(defmacro llet [bind  body]
  `(let ~(vec
   (mapcat #(if-not (list? %) (list % nil) %) bind))
 ~...@body))

(defmacro lcond [ cond]
  (let [bindings
(mapcat
  #(list (first %) `(do ~@(rest %)))
  cond)]
`(cond ~...@bindings)))
;;
;;
;;


(defn condlet-binds [vars cl]
  (map (fn [bindform]
 (if (list? bindform)
   (cons
 (second (lassoc (first bindform) vars))
 (rest bindform
(rest cl)))

(defn condlet-clauses [vars cl bodfn]
  `(~(first cl) (llet ~(map second vars)
  (llet ~(condlet-binds vars cl)
(~bodfn ~@(map second vars))

(defmacro condlet [clauses  body]
  (let [vars (map #(list % (gensym))
   (distinct
 (map first
   (mapcat rest clauses
bodfn (gensym)]
`(letfn ((~bodfn ~(vec (map first vars))
   ~...@body))
   (lcond ~@(map #(condlet-clauses vars  % bodfn)
  clauses)

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



Library problem: SWT and Emacs

2009-09-08 Thread recent596

Hey everyone,

I would really appreciate it if you guys could help me out:  I've
gotten really spoilt by LispWorks and now it's taking me forever to
get sort these library loading issues out.

Okay, so I've download clojure in a box, and the swt.jar library from
the eclipse website and have the following line in my .emacs:


(setq swank-clojure-extra-classpaths
  (list C:/Documents and Settings/recent596/My Documents/Clojure/
swt-3.5-win32-win32-x86/swt.jar
   C:/Documents and Settings/recent596/My Documents/Clojure/
code))

I want to be able to try out some SWT examples from the REPL.  Now
when I try the first example from this blog:
http://www.li-am.com/2009/08/button-in-eclipse-swt-clojure.html
nothing happens (no nil response).

That is, when I type in the first form:
  user (import 'org.eclipse.swt.SWT
 'org.eclipse.swt.layout.FillLayout
 '(org.eclipse.swt.events SelectionAdapter SelectionEvent)
 '(org.eclipse.swt.widgets Button Display Shell))

I don't get a response.  Any sort of hints, tips or suggestion?

Thanks in advance,
R596

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

2009-09-08 Thread Phil Hagelberg

Tom Faulhaber tomfaulha...@gmail.com writes:

 Also, one thing that I (and others) have noticed is that clojure mode
 chokes on the #^{} form metadata on namespaces. (See any of the files
 in clojure-contrib for an example.) I'm not able to reproduce the
 problem now, so if you don't already know what it is, I'll keep my eye
 out for it and send you a proper report when I have it happening.

Yeah, I've seen this. I don't use this style myself, but I want to
support it. I've opened a ticket for this, though it's for swank-clojure
rather than clojure-mode itself:

http://github.com/technomancy/swank-clojure/issues/#issue/1

Speaking of which, I've heard rumors that a nicer docstring syntax for
namespaces is planned. Has there been any work on this? I think it's a
great idea and may implement it myself if nobody else has.

-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: Unsupported binding form

2009-09-08 Thread Laurent PETIT
Without digging into the implementation code:

shouldn't the expansion for e.g. clojure.core/letfn return a vector and not
a list for the binding ?

((G__1840 [a b c] (print a)))
should be
(vector (G__1840 [a b c] (print a)))
or [(G__1840 [a b c] (print a))]

?

Maybe clojure.core/letfn is currently permissive on this, but this is an
undocumented implementation detail (the doc for letfn says : Takes a vector
of function specs and a body, and generates a set of bindings of functions
to their names. All of the names are available in all of the definitions of
the functions, as well as the body.)

Your maybe doing a similar error in other parts of the code where the
implementation detail are closer to the public API, and that may explain
your error ?

2009/9/8 Gorsal s...@tewebs.com


 #CompilerException java.lang.Exception: Unsupported binding form:
 (G__1852 2) (NO_SOURCE_FILE:1182)
 So, I'm porting Paul Grahm's condlet macro to clojure. I've done it
 except when i evaluate it it gives me the above error. However, when I
 macroexpand-1 it it evaluates fine.

 The only difference between evaluating the macroexpansion vs the other
 way is that the (gensym) vars are now regular variables in the
 macroexpanded version. However, i don't see how this can affect it.

 (condlet [((= 2 2) (a 2) (b 3))
 ((= 3 4) (a 1) (b 4) (c 34))]
  (print a)) -- throws error

 macroexpanded version where lcond is equivalent to a lisp cond and
 same for llet. This evaluates
 just fine!

 (clojure.core/letfn
  ((G__1840 [a b c] (print a)))
  (user/lcond
((= 2 2)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet ((G__1841 2) (G__1842 3)) (G__1840 G__1841 G__1842
 G__1843
((= 3 4)
  (user/llet
(G__1841 G__1842 G__1843)
(user/llet
  ((G__1841 1) (G__1842 4) (G__1843 34))
  (G__1840 G__1841 G__1842 G__1843))

 What am i missing here? I've heard of this same error with cond-let
 and the guy changed it due to the 'new everything that lets must have
 bracket regime'? What's this?
 


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



Another Clojure Box - Version 1.4 Fix!!!

2009-09-08 Thread Darmac

Hi,

In the last version of ACB I make a mistake with SciTE version!!
Thanks to all the people that have been using ACB from the very
beginning that warn me that SciTE version wasn't the wright one.

If you have download ACB1.4, please download SciTE.exe from this URL
(http://www.teradepot.com/didnmqw3mze7/SciTE.exe.html) and replace the
one that is inside bin\scite to fix ACB.

Sorry for this and thanks again!!
--~--~-~--~~~---~--~~
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-mode survey

2009-09-08 Thread Phil Hagelberg

Konrad Hinsen konrad.hin...@fastmail.net writes:

 On 8 Sep 2009, at 02:36, Phil Hagelberg wrote:
 However, now that clojure-mode has the M-x clojure-install command
 that sets up SLIME etc, I don't know if the built-in subprocess
 features are worth keeping around any more. Personally I have never
 used them or heard of anyone using them; I wonder if they are just
 legacy baggage.

 Would anyone be opposed to their removal?

 Until now I have never even looked at SLIME, considering the number of  
 difficulties I see reported by lots of people. Life is too short to  
 waste on configuration problems... and in that category I am still  
 busy dealing with Clojure's move to github. I still use clojure-mode  
 with its basic interaction commands for all my Clojure hacking.

Most of these are caused by people manually installing SLIME rather than
using M-x clojure-install. I would rather focus on having one method of
subprocess interaction so we can make that work as smoothly as possible
than keep this vestigal functionality in here that only a handful of
people use.

 On the other hand, if SLIME installation is painless now, that would  
 be fine with me as well.

Please give it a try and let me know if you have any problems. M-x
clojure-install should pull in everything you need, including its own
copy of Clojure 1.0.

 Clojure-update is a sensible complement to clojure-install, I'd
 strongly vote for keeping it.

I think the value-add here is pretty minimal. Before Clojure 1.0 if a
change in Clojure broke swank-clojure, we'd have to scramble to get it
fixed in swank-clojure, and everyone would update. But now that there's
a stable target, I haven't been tracking master closely, so staying
up-to-date is much less important. 

Plus it's just a wrapper around a handful of shell commands.  If more
people use it I may keep it around, otherwise I'd suggest switching over
to a shell script.

-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: minor grievance with arithmetic on characters

2009-09-08 Thread Stephen C. Gilardi


On Sep 8, 2009, at 2:14 AM, Timothy Pratley wrote:


According to the docstring compare returns -1, 0 or 1:
user= (compare \b \g)
-5


We could fix the doc along the lines of:

Comparator. Returns a negative number, zero, or a positive number  
when x is logically 'less than', 'equal to', or 'greater than' y.   
Same as Java x.compareTo(y) except it also works for nil, and compares  
numbers and collections in a type-independent manner. x must implement  
Comparable


or fix the implementation to conform to the current doc.

My current thought is that we should fix the implementation and make a  
minor mod to the doc to replace Same as with something like Works  
like because compareTo only guarantees the sign of the return value.


Other thoughts?

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: clojure-mode survey

2009-09-08 Thread Rick Moynihan

Hi,

I just wanted to say thanks on the M-x clojure-install feature of
clojure-mode!  I like some others on this thread used to use
clojure-mode sans SLIME, (because SLIME and the need to upgrade didn't
seem worth the installation hassle).  However last week I saw
clojure-mode's M-x clojure-install mentioned and thought I'd give it a
try...  I have to say it worked flawlessly for me on Ubuntu... So
thanks to Phil and everyone who made clojure-mode so great!

I'm not yet sure of all the features SLIME brings to the table above
clojure-mode with an inferior-lisp buffer, but given that it *just
worked* I see no reason not to use SLIME now that the install is
painless and clojure 1.0 is out the door.

One problem I do have with clojure-mode/clojure is managing the
classpaths for clojure projects...  It seems that the typical elisp
config only has one variable (which is then shared across all clojure
files) for specifying the classpath...

Personally I'd like to maintain the required classpath with the
project and outside of my .emacs files and was wondering if anyone had
any elisp setups to work around this  I was thinking maybe having
clojure-mode search every directory up from the file your editing for
a .classpath file to pass to a clj bash script for evaluation...  How
does everyone else do this?

R.



2009/9/8 Phil Hagelberg p...@hagelb.org:

 Konrad Hinsen konrad.hin...@fastmail.net writes:

 On 8 Sep 2009, at 02:36, Phil Hagelberg wrote:
 However, now that clojure-mode has the M-x clojure-install command
 that sets up SLIME etc, I don't know if the built-in subprocess
 features are worth keeping around any more. Personally I have never
 used them or heard of anyone using them; I wonder if they are just
 legacy baggage.

 Would anyone be opposed to their removal?

 Until now I have never even looked at SLIME, considering the number of
 difficulties I see reported by lots of people. Life is too short to
 waste on configuration problems... and in that category I am still
 busy dealing with Clojure's move to github. I still use clojure-mode
 with its basic interaction commands for all my Clojure hacking.

 Most of these are caused by people manually installing SLIME rather than
 using M-x clojure-install. I would rather focus on having one method of
 subprocess interaction so we can make that work as smoothly as possible
 than keep this vestigal functionality in here that only a handful of
 people use.

 On the other hand, if SLIME installation is painless now, that would
 be fine with me as well.


 Please give it a try and let me know if you have any problems. M-x
 clojure-install should pull in everything you need, including its own
 copy of Clojure 1.0.

 Clojure-update is a sensible complement to clojure-install, I'd
 strongly vote for keeping it.

 I think the value-add here is pretty minimal. Before Clojure 1.0 if a
 change in Clojure broke swank-clojure, we'd have to scramble to get it
 fixed in swank-clojure, and everyone would update. But now that there's
 a stable target, I haven't been tracking master closely, so staying
 up-to-date is much less important.

 Plus it's just a wrapper around a handful of shell commands.  If more
 people use it I may keep it around, otherwise I'd suggest switching over
 to a shell script.

 -Phil

 




-- 
Rick Moynihan
http://twitter.com/RickMoynihan
http://delicious.com/InkyHarmonics
http://sourcesmouth.co.uk/

--~--~-~--~~~---~--~~
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: Library problem: SWT and Emacs

2009-09-08 Thread Laurent PETIT
Seems like you've been bitten by a lock during the loading of the swt
library/swt native library.

I remember this happened to me, but I'm not quite sure what the solution was
at that time (if I even found one, which, the more I think about it, was
certainly not the case ...)

2009/9/8 recent596 recent...@gmail.com


 Hey everyone,

 I would really appreciate it if you guys could help me out:  I've
 gotten really spoilt by LispWorks and now it's taking me forever to
 get sort these library loading issues out.

 Okay, so I've download clojure in a box, and the swt.jar library from
 the eclipse website and have the following line in my .emacs:


 (setq swank-clojure-extra-classpaths
  (list C:/Documents and Settings/recent596/My Documents/Clojure/
 swt-3.5-win32-win32-x86/swt.jar
   C:/Documents and Settings/recent596/My Documents/Clojure/
 code))

 I want to be able to try out some SWT examples from the REPL.  Now
 when I try the first example from this blog:
 http://www.li-am.com/2009/08/button-in-eclipse-swt-clojure.html
 nothing happens (no nil response).

 That is, when I type in the first form:
  user (import 'org.eclipse.swt.SWT
 'org.eclipse.swt.layout.FillLayout
 '(org.eclipse.swt.events SelectionAdapter SelectionEvent)
 '(org.eclipse.swt.widgets Button Display Shell))

 I don't get a response.  Any sort of hints, tips or suggestion?

 Thanks in advance,
 R596

 


--~--~-~--~~~---~--~~
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: explode a string to a list

2009-09-08 Thread Conrad

Although this shows how to convert a string into a seq of chars, for
the life of me I can't find a function in any libraries (or any info
in the newsgroup) to do the reverse, i.e.  (\t \e \s \t) = test...
The closest I can find is (print-str [\t \e \s \t])=t e s t

...can anyone give me a pointer?

Thanks in advance!

On Aug 22, 8:20 am, Sean Devlin francoisdev...@gmail.com wrote:
 Welcome to Clojure!

 A String is a form of a Sequence, so the correct function is seq.

 user=(seq test)
 (\t \e \s \t)

 The sequence abstraction is on of may favorite things about Clojure.
 It is an interface most collections implement, and it makes it very
 consistent to manipulate any collection-like object.  For mroe read
 here:

 http://clojure.org/sequences

 Also, watching Rich's presentation for Java and/or Lisp developers
 will help a lot.

 I hope this helps.
 Sean

 On Aug 22, 4:54 am, clint.laskowski clint.laskow...@gmail.com
 wrote:

  Sorry if this is a FAQ. I'm a Clojure newbie.

  What is the best way to iterate through thecharactersof a string? Is
  there some kind of EXPLODE function such that:

  = (explode test)
  (\t \e \s \t)

  I did a Google search but the closest thing I found was SUBS:

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



Re: explode a string to a list

2009-09-08 Thread Conrad

Never mind- I figured it out looking at the str-utils source...

the answer is (apply str [\t \e \s \t])

On Sep 8, 6:05 pm, Conrad drc...@gmail.com wrote:
 Although this shows how to convert a string into a seq of chars, for
 the life of me I can't find a function in any libraries (or any info
 in the newsgroup) to do the reverse, i.e.  (\t \e \s \t) = test...
 The closest I can find is (print-str [\t \e \s \t])=t e s t

 ...can anyone give me a pointer?

 Thanks in advance!

 On Aug 22, 8:20 am, Sean Devlin francoisdev...@gmail.com wrote:

  Welcome to Clojure!

  A String is a form of a Sequence, so the correct function is seq.

  user=(seq test)
  (\t \e \s \t)

  The sequence abstraction is on of may favorite things about Clojure.
  It is an interface most collections implement, and it makes it very
  consistent to manipulate any collection-like object.  For mroe read
  here:

 http://clojure.org/sequences

  Also, watching Rich's presentation for Java and/or Lisp developers
  will help a lot.

  I hope this helps.
  Sean

  On Aug 22, 4:54 am, clint.laskowski clint.laskow...@gmail.com
  wrote:

   Sorry if this is a FAQ. I'm a Clojure newbie.

   What is the best way to iterate through thecharactersof a string? Is
   there some kind of EXPLODE function such that:

   = (explode test)
   (\t \e \s \t)

   I did a Google search but the closest thing I found was SUBS:

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



Printing to be read

2009-09-08 Thread Brian Hurt
So I have a situation where I want to spool out a data structure as a file
where I want to be able for a human to read  modify this structure, and
then be able to read it back in.  At first I thought this was going to be
easy- just use print to write out the structure, and then use read to read
it back in.  Unfortunately, this doesn't work- see, the structure contains
strings, and print drops the quote marks off the strings.  I don't think
setting *print-readably* is what I want either, although I'm not sure-
playing around with it, it doesn't seem to affect the behavior of print at
all (that I can tell).

So, my question is this: is there a way to print a structure out in a
fashion that it can be read back in correctly (i.e. with strings being
quoted), and without having to write my own print function?

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: Printing to be read

2009-09-08 Thread Richard Newman

 So, my question is this: is there a way to print a structure out in  
 a fashion that it can be read back in correctly (i.e. with strings  
 being quoted), and without having to write my own print function?

prn.

user= (prn {:foo [bar 5.0]})
{:foo [bar 5.0]}
nil


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



Re: Example of using ANTLR from Clojure?

2009-09-08 Thread psf

Thanks for the information.  Once I bit the bullet and learned a bit
of Java, it was actually pretty easy to call ANTLR from clojure, after
getting all the package naming figured out.

Paul

On Sep 6, 6:22 am, Laurent PETIT laurent.pe...@gmail.com wrote:
 2009/9/5 Mike Hinchey hinche...@gmail.com

  I don't know anything about it, but counterclockwise uses antlr.

 http://groups.google.com/group/clojuredev-devel/browse_thread/thread/...

 That's true. To be more precise, we have a clojure lexer which is
 extensively used in Counterclockwise clojure source editor for syntax
 coloration. There is also the lexer part but it was developed a long time
 ago (so may not be still accurate), and is not used yet (so maybe the way
 the AST is constructed is nood in the good shape for most purpose).

 But to come back to your concern of using antlr from clojure : no,
 Counterclockwise is not yet written in clojure (just the client/server part
 for communicating with running projects instances) and so you wil not be
 able to find examples for that, sorry :-(

 --
 Laurent
--~--~-~--~~~---~--~~
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: Unsupported binding form

2009-09-08 Thread Gorsal

Dang. I did indeed have to read the fine print. Sequences vs. lists.
All look the same , don't they. Those macroexpanded things which
looked
like lists were actually sequences. This is because map and mapcat and
such return ... sequences! (list? seq) returns false on a sequence...
So.

(defn mkseq [item]
  (cond
(symbol? item) (seq (list item))
:default (seq item)))

(defn lassoc [item lst]
  (first (filter #(= (first (mkseq %)) item) lst)))
;;;CHANGING to symbol? works, or i could of used if-not (seq? ..) i
guess...
(defmacro llet [bind  body]
  `(let ~(vec
   (mapcat #(if (symbol? %) (list % nil) %) bind))
 ~...@body))

;;or you could use my new favorite test function for macros..
(defn aseq? [item] (or (vector? item) (list? item) (seq? item)))


Thanks for the help!


On Sep 8, 3:34 pm, Laurent PETIT laurent.pe...@gmail.com wrote:
 Without digging into the implementation code:

 shouldn't the expansion for e.g. clojure.core/letfn return a vector and not
 a list for the binding ?

 ((G__1840 [a b c] (print a)))
 should be
 (vector (G__1840 [a b c] (print a)))
 or [(G__1840 [a b c] (print a))]

 ?

 Maybe clojure.core/letfn is currently permissive on this, but this is an
 undocumented implementation detail (the doc for letfn says : Takes a vector
 of function specs and a body, and generates a set of bindings of functions
 to their names. All of the names are available in all of the definitions of
 the functions, as well as the body.)

 Your maybe doing a similar error in other parts of the code where the
 implementation detail are closer to the public API, and that may explain
 your error ?

 2009/9/8 Gorsal s...@tewebs.com



  #CompilerException java.lang.Exception: Unsupported binding form:
  (G__1852 2) (NO_SOURCE_FILE:1182)
  So, I'm porting Paul Grahm's condlet macro to clojure. I've done it
  except when i evaluate it it gives me the above error. However, when I
  macroexpand-1 it it evaluates fine.

  The only difference between evaluating the macroexpansion vs the other
  way is that the (gensym) vars are now regular variables in the
  macroexpanded version. However, i don't see how this can affect it.

  (condlet [((= 2 2) (a 2) (b 3))
              ((= 3 4) (a 1) (b 4) (c 34))]
   (print a)) -- throws error

  macroexpanded version where lcond is equivalent to a lisp cond and
  same for llet. This evaluates
  just fine!

  (clojure.core/letfn
   ((G__1840 [a b c] (print a)))
   (user/lcond
     ((= 2 2)
       (user/llet
         (G__1841 G__1842 G__1843)
         (user/llet ((G__1841 2) (G__1842 3)) (G__1840 G__1841 G__1842
  G__1843
     ((= 3 4)
       (user/llet
         (G__1841 G__1842 G__1843)
         (user/llet
           ((G__1841 1) (G__1842 4) (G__1843 34))
           (G__1840 G__1841 G__1842 G__1843))

  What am i missing here? I've heard of this same error with cond-let
  and the guy changed it due to the 'new everything that lets must have
  bracket regime'? What's this?


--~--~-~--~~~---~--~~
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: minor grievance with arithmetic on characters

2009-09-08 Thread Timothy Pratley

Hi Steve,

I find the -1, 0, 1 result more useful, but am also wary it hides some
useful information. My preference would be to have the doc-string
changed to what you proposed and keep the neg/pos behaviour
of .compareTo in place. To get -1, 0, 1 requires a 'sign' operator
which is handy to have as a separate function - might be a candidate
for contrib?

(defn sign
  Returns 1 if x is positive, -1 if x is negative, else 0
  [x]
  (cond (pos? x) 1, (neg? x) -1, :else 0))

user= ((comp sign compare) \a \g)
-1

hmmm bit verbose, but lets the user choose if they want compareTo or
-1, 0, 1



Regards,
Tim.



On Sep 9, 7:35 am, Stephen C. Gilardi squee...@mac.com wrote:
 On Sep 8, 2009, at 2:14 AM, Timothy Pratley wrote:

  According to the docstring compare returns -1, 0 or 1:
  user= (compare \b \g)
  -5

 We could fix the doc along the lines of:

 Comparator. Returns a negative number, zero, or a positive number  
 when x is logically 'less than', 'equal to', or 'greater than' y.  
 Same as Java x.compareTo(y) except it also works for nil, and compares  
 numbers and collections in a type-independent manner. x must implement  
 Comparable

 or fix the implementation to conform to the current doc.

 My current thought is that we should fix the implementation and make a  
 minor mod to the doc to replace Same as with something like Works  
 like because compareTo only guarantees the sign of the return value.

 Other thoughts?

 --Steve

  smime.p7s
 3KViewDownload
--~--~-~--~~~---~--~~
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-mode survey

2009-09-08 Thread Phil Hagelberg

Rick Moynihan rick.moyni...@gmail.com writes:

 One problem I do have with clojure-mode/clojure is managing the
 classpaths for clojure projects...  It seems that the typical elisp
 config only has one variable (which is then shared across all clojure
 files) for specifying the classpath...

 Personally I'd like to maintain the required classpath with the
 project and outside of my .emacs files and was wondering if anyone had
 any elisp setups to work around this  I was thinking maybe having
 clojure-mode search every directory up from the file your editing for
 a .classpath file to pass to a clj bash script for evaluation...  How
 does everyone else do this?

The solution I've settled on is the clojure-project function:

(defun clojure-project (path)
  Setup classpaths for a clojure project and starts a new SLIME session.
  Kills existing SLIME session, if any.
  (interactive (list
(ido-read-directory-name
 Project root: 
 (locate-dominating-file default-directory src
  (require 'swank-clojure)
  (when (get-buffer *inferior-lisp*)
(kill-buffer *inferior-lisp*))
  (add-to-list 'swank-clojure-extra-vm-args
   (format -Dclojure.compile.path=%s
   (expand-file-name target/classes/ path)))
  (setq swank-clojure-binary nil
swank-clojure-jar-path (expand-file-name target/dependency/ path)
swank-clojure-extra-classpaths
(append (mapcar (lambda (d) (expand-file-name d path))
'(src/ target/classes/ test/))
(let ((lib (expand-file-name lib path)))
  (if (file-exists-p lib)
  (directory-files lib t .jar$
slime-lisp-implementations
(cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
  (remove-if #'(lambda (x) (eq (car x) 'clojure))
 slime-lisp-implementations)))
  (save-window-excursion
(slime)))

This just resets the classpath to include target/dependency/ as well as
any jars in the lib/ directory of your project. I've included this in
the Emacs Starter Kit but haven't included it in clojure-mode yet since
I haven't quite decided if it's suitable for everyone. But it seems
there's a demand for it; so I guess I'll include it.

Another option is to use directory-local variables using a
.dir-locals.el file in your project root, but that can only set values
for variables, it can't do things like add a value to an existing list,
so its utility is limited.

-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: Clojure quickstart maven archetype

2009-09-08 Thread Daniel Renfer

I'm really glad someone finally got this working. I gave it a shot a
couple of months ago and I was tearing my hair out trying to get a two
way communication with the repl and the outside world.

On Tue, Sep 8, 2009 at 2:41 AM, Scott Fleckensteinnullst...@gmail.com wrote:

 Thanks Stuart,

 Just an FYI, I added repl support to the clojure-maven-plugin here:
 http://github.com/nullstyle/clojure-maven-plugin/tree/master

 Rather than taking clojureshell's approach, I start a separate process
 similar to how the rest of the plugin works.  In fact, I just needed
 to refactory the abstract mojo used so that it can support an
 interactive child process, and it came together super simply.  I think
 it is a much more understandable approach than running clojure inside
 the maven process, but that's just IMO.

 Next on my list is to add jline support onto the archetype, and figure
 out how best I want to support AOT along with Script execution.

 -Scott

 On Sep 7, 9:40 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 Also look at the ClojureShell Maven 
 plugin,http://github.com/fred-o/clojureshell-maven-plugin/tree/master
 which runs a REPL or Swank server.

 -SS

 On Sep 7, 10:41 pm, Mark Derricutt m...@talios.com wrote:

  Most definitely - I did have a repl goal for awhile but had issues with the
  input/output streams.  Looking at my github forkqueue I see someones pulled
  it back out (or added a new one, I've not yet had a look at it) which might
  be a starting point for you...
  But by all means - patches galore are welcome ;)

  --
  Pull me down under...

  Sent from Auckland, Auk, New Zealand

  On Tue, Sep 8, 2009 at 2:09 PM, Scott Fleckenstein 
  nullst...@gmail.comwrote:

   If I'm able to get a repl goal working, are you open to patches?
 


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