Re: run macro for executable namespaces

2009-06-02 Thread Adrian Cuthbertson

Thanks Steve! That's very neat. Pretty much a canonical macro example.

Adrian.

On Tue, Jun 2, 2009 at 5:50 AM, Stephen C. Gilardi squee...@mac.com wrote:
 Here's a macro I've found useful for loading and running Clojure programs
 from the REPL:

  (defmacro run
    Loads the specified namespace and invokes its \main\
    function with optional args. ns-name is not evaluated.
    [ns-name  args]
    `(do
       (require '~ns-name :reload-all)
       ((ns-resolve '~ns-name '~'main) ~...@args)))

 An example namespace that works with it (in hello.clj at a classpath root):

  (ns hello)

  (defn main
    [ args]
    (apply println hi args))

 and a REPL session:

  user= (run hello)
  hi
  nil
  user= (run hello :clojure is \#
           (.gcd (bigint 1169687) (bigint 311791)))
  hi :clojure is # 1
  nil
  user=

 I think the quoting on main in the ns-resolve call is quite interesting.
 macroexpand-ing variations on it is a heap of educational Clojure macro-fu
 fun!

 --Steve



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



Re: run macro for executable namespaces

2009-06-02 Thread Konrad Hinsen

On 02.06.2009, at 05:50, Stephen C. Gilardi wrote:

 Here's a macro I've found useful for loading and running Clojure  
 programs from the REPL:

   (defmacro run
 Loads the specified namespace and invokes its \main\
 function with optional args. ns-name is not evaluated.
 [ns-name  args]
 `(do
(require '~ns-name :reload-all)
((ns-resolve '~ns-name '~'main) ~...@args)))

That looks like a perfect candidate for clojure.contrib.repl-utils!

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



Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
I'm used to polymorphism in OO systems where everything in driven from
inheritance hierarchy.  Clojures defmulti style polymorphism seems powerful
but has left me wondering how to most effectively use it.  I'm looking for
some good real world examples of how people have used polymorphism in
clojure.
Regards,

Glen Stampoultzis

--~--~-~--~~~---~--~~
You 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: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Stefan Hübner

The upload bundle, which is found at
http://jira.codehaus.org/browse/MAVENUPLOAD-2464, promotes Clojure as
org.clojure:clojure:1.0.0. It hasn't received any atention from the
Upload team yet, but I do hope it gets uploaded within the next
weeks. Maybe voting could speed it up...

dysinger dysin...@gmail.com writes:

 I personally have used the -lang qualifier in my own POM work so as to
 have an (unspoken) consensus with Howard's POM work.

 However, I would rather clojure proper just be named
 org.clojure:clojure in maven/ivy-land myself and I have heard that
 from quite a few others.

 On May 10, 1:17 pm, d...@kronkltd.net (Daniel E. Renfer) wrote:
 Phil Hagelberg p...@hagelb.org writes:
  Howard Lewis Ship hls...@gmail.com writes:

  clojure-lang because there will be a clojure-contrib artifact for the
  same group.

  And this is ... a bad thing? I'm lost.

  -Phil

 Good, at least I'm not the only one.

 Why can't we have both clojure and clojure-contrib as Id's?

 Daniel E. Renfer


--~--~-~--~~~---~--~~
You 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: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Paul Stadig
I signed up and voted. Only took about 30 seconds.

Thanks for the work everyone. I would love to see Clojure get into the Maven
repo.


Paul

On Tue, Jun 2, 2009 at 6:04 AM, Stefan Hübner sthueb...@googlemail.comwrote:


 The upload bundle, which is found at
 http://jira.codehaus.org/browse/MAVENUPLOAD-2464, promotes Clojure as
 org.clojure:clojure:1.0.0. It hasn't received any atention from the
 Upload team yet, but I do hope it gets uploaded within the next
 weeks. Maybe voting could speed it up...

 dysinger dysin...@gmail.com writes:

  I personally have used the -lang qualifier in my own POM work so as to
  have an (unspoken) consensus with Howard's POM work.
 
  However, I would rather clojure proper just be named
  org.clojure:clojure in maven/ivy-land myself and I have heard that
  from quite a few others.
 
  On May 10, 1:17 pm, d...@kronkltd.net (Daniel E. Renfer) wrote:
  Phil Hagelberg p...@hagelb.org writes:
   Howard Lewis Ship hls...@gmail.com writes:
 
   clojure-lang because there will be a clojure-contrib artifact for the
   same group.
 
   And this is ... a bad thing? I'm lost.
 
   -Phil
 
  Good, at least I'm not the only one.
 
  Why can't we have both clojure and clojure-contrib as Id's?
 
  Daniel E. Renfer


 


--~--~-~--~~~---~--~~
You 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: Good examples of defmulti polymorphism

2009-06-02 Thread Konrad Hinsen

On 02.06.2009, at 12:01, Glen Stampoultzis wrote:

 I'm used to polymorphism in OO systems where everything in driven  
 from inheritance hierarchy.  Clojures defmulti style polymorphism  
 seems powerful but has left me wondering how to most effectively  
 use it.  I'm looking for some good real world examples of how  
 people have used polymorphism in clojure.

There are a couple of generic interfaces implemented as multimethods  
in clojure-contrib:

http://code.google.com/p/clojure-contrib/source/browse/#svn/trunk/ 
src/clojure/contrib/generic

An implementation of complex numbers based on these interfaces is  
there as well:

http://code.google.com/p/clojure-contrib/source/browse/trunk/src/ 
clojure/contrib/complex_numbers.clj

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: run macro for executable namespaces

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 3:35 AM, Adrian Cuthbertson wrote:
Thanks Steve! That's very neat. Pretty much a canonical macro  
example.


You're welcome! I'm glad you like it.

On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote:

That looks like a perfect candidate for clojure.contrib.repl-utils!


Thanks! After a little more discussion, I'd like to put it in there.

After thinking about other macro advice I've seen (from Meikel  
Brandmeyer and elsewhere), I came up with this version that does most  
of the work in a function and provides the macro just to control the  
evaluation of arguments:


  (defn run*
Loads the specified namespace and invokes its \main\
function with optional args.
[ns-sym  args]
(require ns-sym :reload-all)
(apply (ns-resolve ns-sym 'main) args))

  (defmacro run
Loads the specified namespace and invokes its \main\
function with optional args. ns-name is not evaluated.
[ns-name  args]
`(run* '~ns-name ~...@args))

I see the tradeoffs as:

possible negative:

- an extra name in the namespace

positives:

- the code is easier to understand
	- the function version composes better: it's easier to call from  
other code if that were desired.


Overall I like the function/macro pair version better.

Any thoughts?

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-06-02 Thread Stefan Hübner

Christian Vest Hansen karmazi...@gmail.com writes:

 On Mon, May 18, 2009 at 8:59 AM, Stefan Hübner sthueb...@googlemail.com 
 wrote:

 I've submitted the Maven bundle for Clojure 1.0.0 to
 http://jira.codehaus.org/browse/MAVENUPLOAD-2464. Processing the request
 might take a couple of days.

 The upload guide says four weeks. Repository synchronization is the
 long term solution, I think.

Thats probably true. If someone from the core team/contributors has the
resources to set this up, that would be cool. It would speed up
promotion to Maven Central alot (fully automatic) - for future releases.


--~--~-~--~~~---~--~~
You 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: Spider with clojure

2009-06-02 Thread Baishampayan Ghose
 just reading through the book (http://pragprog.com/titles/shcloj/
 programming-clojure) and having a lot of of fun learning. I was
 wondering if there are any examples out there like Dave Thomas'
 
 A First Erlang Program
 http://pragdave.pragprog.com/pragdave/2007/04/a_first_erlang_.html
 
 in Clojure. What I want to do is just read in a csv with a couple of
 hundred URLs and spider those in parallel (!) and save the results
 back to another file. The way I like to learn best is to find
 something and mold it to my needs. I tried searching, but couldn't
 find anything useful with spider clojure. Since clojure is touted as
 the perfect language for multi-threaded apps this would be a very nice
 and useful lesson for me. (Sorry, but I have no use at all for a
 versioning control system.)
 
 I am doing this with Ruby right now, but no in parallel.

This seems to be an ideal use-case for Clojure Agents
http://clojure.org/agents

Try it out and share the code :)

Regards,
BG
-- 
Baishampayan Ghose b.gh...@ocricket.com
oCricket.com



signature.asc
Description: OpenPGP digital signature


STM Resource transactions

2009-06-02 Thread Robert Campbell

I've been looking at using the clojure.set functions to create a
simple in-memory database cache. Basically when the app boost up, load
entire db into memory, work with it through the basic relational
algebra functions provided. Any mutations (create/update/delete) would
be wrapped in a simple function that 1) updates the cache and 2)
persists to the database in order to add the D to STM's ACI. So
for example, you could have:

(defn insert-product [product]
 (dosync (alter products conj product))
 (with-connection db (transaction (insert-values XXXstuff hereXXX)))

The dosync will run the alter within an STM transaction.
The transaction will run the insert within a local resource (database)
transaction.

In Java, if you have two transactional systems, you can bridge them
with JTA. STM, however, is a different beast. Has anyone done anything
towards bridging STM and resource transactions?

--~--~-~--~~~---~--~~
You 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: run macro for executable namespaces

2009-06-02 Thread Chouser

On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi squee...@mac.com wrote:

 On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote:

 That looks like a perfect candidate for clojure.contrib.repl-utils!

 Thanks! After a little more discussion, I'd like to put it in there.

I'm never sure what the etiquette is for adding to other people's files in
contrib, but please don't hesitate to add this to repl-utils on my account.

 I see the tradeoffs as:

 possible negative:

        - an extra name in the namespace

Eh... nobody cares.  :-)

 positives:

        - the code is easier to understand
        - the function version composes better: it's easier to call from
 other code if that were desired.

These are important, esp. the second one, at least in the general case.

 Overall I like the function/macro pair version better.

 Any thoughts?

Using gen-class you can have a namespace that is runnable from the Java command
line by providing a main() method.  This usually defers to a function named
-main that expects string arguments.  From my reading of your 'run', it looks
like you're using a function named main that expects symbol, string, etc.
args.  I assume this difference is intentional?

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



Re: ClojureCLR updated

2009-06-02 Thread Jeff Heon

On Jun 1, 1:57 pm, David Miller dmiller2...@gmail.com wrote:
 It's important in that it means that the generated MSIL is not
 completely junk, in that I'm not missing any important optimizations,
 that I'm taking full advantage of type hints, avoiding reflection,
 etc..  The JVM bytecodes are an important check for me. What's
 interesting is that the methods used to generate the IL in the each
 implementation are very different.  The two implementations generate
 AST from the clojure source that are pretty much identical.  From the
 ASTs, the JVM implementation generates bytecodes using the ASM
 bytecode library--essentially, it's close to hand-generated.  Rich and
 company have that code pretty finely tuned.  The CLR implementation
 transforms the ASTs into DLR-Expression-Tree-Version-2 expressions.
 The DLR code handles compiling those expressions into either dynamic
 methods or into static methods for saving in assemblies.  The DLR
 expression compiler should be generating decent MSIL.  I think the
 closeness of the results are encouraging.

I wonder if that project could be of some help/inspiration.
It implements a JVM in .NET
http://www.ikvm.net/


 The JVM implementation does pull some tricks, such as nulling method
 arguments before tail calls or storing some temp values on the stack,
 that I can't figure out how to duplicate with ExpressionTrees.  Also,
 the expression tree compiler can only generate static methods.
 Clojure functions are instances of a class implementing the IFn
 interface.  I have to hand-code the class definitions and code the
 'invoke' instance methods to call out to static methods in a base
 class.  That adds an extra method call in many places.  Whether all
 these little things add up to some of the performance differences is
 beyond my knowledge or the granularity of the profiling tools at my
 disposal.   Unless some MSIL expert surfaces to give advice, I'll be
 spending time hand-coding some alternatives to benchmark certain
 constructs to see what works better.  Worst case, I will end up
 discarding the MSIL and doing the MSIL generation myself.

 : It'd be much easier to play with if you provide a precompiled
 : executable :)

 I thought about that.  Adding assembilies of my code  as a download is
 easy enough.  However, to get the thing running, you also need vjslib
 from the J# Redistributatable library plus DLLs generated from the DLR
 source -- care to advise me about the legal ramifications of me doing
 that directly?  :)

 : Keep up the good work! I hope to someday use ClojureCLR for real
 : projects, so I can have all the functional, concurrent goodness of
 : Clojure in .NET.

 I think that day is not too far off.

 Thanks for the feedback.

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



Re: STM Resource transactions

2009-06-02 Thread Michael Reid

On Tue, Jun 2, 2009 at 8:12 AM, Robert Campbell rrc...@gmail.com wrote:

 I've been looking at using the clojure.set functions to create a
 simple in-memory database cache. Basically when the app boost up, load
 entire db into memory, work with it through the basic relational
 algebra functions provided. Any mutations (create/update/delete) would
 be wrapped in a simple function that 1) updates the cache and 2)
 persists to the database in order to add the D to STM's ACI. So
 for example, you could have:

 (defn insert-product [product]
     (dosync (alter products conj product))
     (with-connection db (transaction (insert-values XXXstuff hereXXX)))

 The dosync will run the alter within an STM transaction.
 The transaction will run the insert within a local resource (database)
 transaction.

 In Java, if you have two transactional systems, you can bridge them
 with JTA. STM, however, is a different beast. Has anyone done anything
 towards bridging STM and resource transactions?


There was a thread about this awhile back:

http://groups.google.com/group/clojure/browse_thread/thread/aa22a709501a64ac/b578f0915b55c4be?#b578f0915b55c4be

There is apparently an attachment to the list which modifies the
Clojure STM in the necessary ways, but it may not work with the latest
anymore.

Sounds like Rich may be willing to work with you to integrate it into
the trunk..

/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: Spider with clojure

2009-06-02 Thread Sasa Ebach

Hi BG,

 This seems to be an ideal use-case for Clojure Agents
 http://clojure.org/agents

This code is still a little too general for me. I guess if I stare at it long 
enough, I will eventually get it ;)

 Try it out and share the code :)

Will do, but I hope that someone has something more concrete. Here is what I 
do in Ruby (shortened and with all error handling stripped out).

require 'rubygems'
require 'mechanize'
require 'faster_csv'

urls = '...urls in csv format...'
fcsv_options = {:headers = true, :header_converters = :symbol}
FasterCSV.open('results.csv', 'w') do |csv|
   csv  %w[url acrank refdomain anchortext title body]
   FasterCSV.parse(urls, fcsv_options) do |line|
 page = WWW::Mechanize.new { |ag|
   ag.read_timeout = 10
 }.get(line[:url])
 # push result to csv
   end
end

a typical spider. I would love to read some source code of something similiar 
done in clojure. If it doesn't exist yet, I will eventually create it. Right 
now I would even know which libs to use or even if there are any. I guess even 
the parsing of the csv could be multithreaded. Feelin kinda frustrated right 
now, because I know how to do it in a couple other languages, but just got 
started with Clojure. I have done this in Ruby even multithreaded, which 
quickly became *very* complicated because of it's mutable variables.

-sasa

--~--~-~--~~~---~--~~
You 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: run macro for executable namespaces

2009-06-02 Thread Meikel Brandmeyer

Hi,

Am 02.06.2009 um 13:49 schrieb Stephen C. Gilardi:


I see the tradeoffs as:

possible negative:

- an extra name in the namespace


I don't see this as a big negative. I usually stick with the
convention that the function is named after the macro
with a star added. As in your example: run = run*.

This doesn't use up additional names since they are
either named with two stars (one on either side) or no
star at all.

So I can live with that trade-off..


positives:

- the code is easier to understand
	- the function version composes better: it's easier to call from  
other code if that were desired.


Overall I like the function/macro pair version better.

Any thoughts?


I think the advantages weight up the additional name.

Did you further think about your previous suggestion
to provide the functionality of calling a qualified
function from the command line of clojure.main?

I'd still like to suggest a '-E' flag, which basically specifies
the entry point to call. So one could do

clojure.main -E some.namespace/some-func

This would require some.namespace to be on the
classpath.

clojure.main some/file.clj

would just execute some/file.clj as a script.

clojure.main -E some.namespace/some-func some/namespace.clj

would first read some/namespace.clj and then execute
some.namespace/some-func. This would not require
some.namespace to be on the classpath, because it could
be defined in the given file.

This would allow to make the loading of script files side-effect
free, which would ease their use during debugging. And it
would allow different entry points in a single script. Finally
the script would not need to reside somewhere on the classpath.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


Re: run macro for executable namespaces

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 8:59 AM, Chouser wrote:
On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi  
squee...@mac.com wrote:

On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote:


That looks like a perfect candidate for clojure.contrib.repl-utils!


Thanks! After a little more discussion, I'd like to put it in there.


I'm never sure what the etiquette is for adding to other people's  
files in
contrib, but please don't hesitate to add this to repl-utils on my  
account.


I agree on the etiquette thing. I planned to track you down and ask  
you. Thanks for the permission! In clojure.contrib.core, Laurent put  
in a clause at the top giving blanket permission. In that case I  
marked off a section for my contribs (dissoc-in and new-by-name) so  
anyone who wants to ask about them can find me.



Any thoughts?


Using gen-class you can have a namespace that is runnable from the  
Java command
line by providing a main() method.  This usually defers to a  
function named
-main that expects string arguments.  From my reading of your  
'run', it looks
like you're using a function named main that expects symbol,  
string, etc.

args.  I assume this difference is intentional?


It is intentional. I see them as having slightly different roles given  
the more flexible types that main can see vs. the just strings that - 
main (prefixmain in the general case) would see. In cases where they  
can be unified it can be done easily with a small stub, a def, or a  
clojure.contrib.def/defalias.


I think it would be a cool idea for ns to support a :main clause  
that would let you specify the function to run when this namespace is  
executed using run. I would default it to main, but it could be  
specified as -main if that's appropriate or another name with more  
meaning in general.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Michael Reid

On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name wrote:
 You meant to type disclosure, but instead you typed disclojure.

 Paul

How about when you try to write code in other languages, and
reflexively place parentheses before function/method names?

(len 'Foo') -- not valid Python. :(

/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: run macro for executable namespaces

2009-06-02 Thread Laurent PETIT

2009/6/2 Stephen C. Gilardi squee...@mac.com:

 On Jun 2, 2009, at 8:59 AM, Chouser wrote:

 On Tue, Jun 2, 2009 at 7:49 AM, Stephen C. Gilardi squee...@mac.com
 wrote:

 On Jun 2, 2009, at 4:45 AM, Konrad Hinsen wrote:

 That looks like a perfect candidate for clojure.contrib.repl-utils!

 Thanks! After a little more discussion, I'd like to put it in there.

 I'm never sure what the etiquette is for adding to other people's files in
 contrib, but please don't hesitate to add this to repl-utils on my
 account.

 I agree on the etiquette thing. I planned to track you down and ask you.
 Thanks for the permission! In clojure.contrib.core, Laurent put in a clause
 at the top giving blanket permission. In that case I marked off a section
 for my contribs (dissoc-in and new-by-name) so anyone who wants to ask about
 them can find me.

There also still the possibility to have, per namespace, a file that
just loads other files (belonging to the same namespace) with one
contributor per file. But I see this as counter productive because
there will be a lot of little files per namespace, and sometimes there
will be problems with the orders of the functions definitions
eventually leading to the creation of several files per namespace per
contributo ... so not a so great idea after all :-)


 Any thoughts?

 Using gen-class you can have a namespace that is runnable from the Java
 command
 line by providing a main() method.  This usually defers to a function
 named
 -main that expects string arguments.  From my reading of your 'run', it
 looks
 like you're using a function named main that expects symbol, string,
 etc.
 args.  I assume this difference is intentional?

 It is intentional. I see them as having slightly different roles given the
 more flexible types that main can see vs. the just strings that -main
 (prefixmain in the general case) would see. In cases where they can be
 unified it can be done easily with a small stub, a def, or a
 clojure.contrib.def/defalias.

 I think it would be a cool idea for ns to support a :main clause that
 would let you specify the function to run when this namespace is executed
 using run. I would default it to main, but it could be specified as
 -main if that's appropriate or another name with more meaning in general.

 --Steve



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



Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Laurent PETIT

2009/6/2 Michael Reid kid.me...@gmail.com:

 On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name wrote:
 You meant to type disclosure, but instead you typed disclojure.

 Paul

 How about when you try to write code in other languages, and
 reflexively place parentheses before function/method names?

 (len 'Foo') -- not valid Python. :(

And when you're stuck with java, and have to implement the Visitor
design pattern yet again, instead of being able to use multimethods
:-( (that was my case the last two weeks !)

--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread Shawn Hoover
On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid kid.me...@gmail.com wrote:


 On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name wrote:
  You meant to type disclosure, but instead you typed disclojure.
 
  Paul
 
 How about when you try to write code in other languages, and
 reflexively place parentheses before function/method names?

 (len 'Foo') -- not valid Python. :(

 /mike.


Don't forget, commas are NOT optional!

irb(main) a = [1 2 3]
SyntaxError: compile error!

--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread Paul Stadig
On Tue, Jun 2, 2009 at 10:06 AM, Shawn Hoover shawn.hoo...@gmail.comwrote:

 On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid kid.me...@gmail.com wrote:

 On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name wrote:
  You meant to type disclosure, but instead you typed disclojure.
 
  Paul
 
 How about when you try to write code in other languages, and
 reflexively place parentheses before function/method names?

 (len 'Foo') -- not valid Python. :(

 /mike.


 Don't forget, commas are NOT optional!

 irb(main) a = [1 2 3]
 SyntaxError: compile error!


Hehe, yeah that one's gotten me before. :)

Paul

--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread tmountain

Same here with the commas. Since I've been neck deep in Clojure, I've
been pathologically forgetting to add them with other languages.

On Jun 2, 10:06 am, Shawn Hoover shawn.hoo...@gmail.com wrote:
 On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid kid.me...@gmail.com wrote:

  On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name wrote:
   You meant to type disclosure, but instead you typed disclojure.

   Paul

  How about when you try to write code in other languages, and
  reflexively place parentheses before function/method names?

  (len 'Foo') -- not valid Python. :(

  /mike.

 Don't forget, commas are NOT optional!

 irb(main) a = [1 2 3]
 SyntaxError: compile error!
--~--~-~--~~~---~--~~
You 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: run macro for executable namespaces

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 8:59 AM, Chouser wrote:

I'm never sure what the etiquette is for adding to other people's  
files in
contrib, but please don't hesitate to add this to repl-utils on my  
account.


Thanks again. I've checked in run*/run to clojure.contrib.repl-utils.

Cheers,

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Good examples of defmulti polymorphism

2009-06-02 Thread Stuart Halloway

Hi Glen,

(1) Real-world example:  I use polymorphism on the types of two  
different arguments to define implicit conversions:

(defmulti coerce
   (fn [dest-class src-inst] [dest-class (class src-inst)]))

(defmethod coerce [java.io.File String] [_ str]
   (java.io.File. str))

(defmethod coerce [Boolean/TYPE String] [_ str]
   (contains? #{on yes true} (.toLowerCase str)))

(2) Made-up, but realistic example: using polymorphism on two  
different inheritance hierarchies on a single argument:

(defmulti service-charge (fn [acct] [(account-level acct) (:tag acct)]))
(defmethod service-charge [::acc/Basic ::acc/Checking]   [_] 25)
(defmethod service-charge [::acc/Basic ::acc/Savings][_] 10)
(defmethod service-charge [::acc/Premium ::acc/Account] [_] 0)

(3) Example from inside Clojure itself: using external tags to layer a  
hierarchy onto existing objects without their knowledge (inspector.clj).

All of these are documented in the book [1] and you can view the  
sample code at [2].

Cheers,
Stu

[1] http://www.pragprog.com/titles/shcloj/programming-clojure
[2] http://github.com/stuarthalloway/programming-clojure/. See  
examples/multimethods*

 I'm used to polymorphism in OO systems where everything in driven  
 from inheritance hierarchy.  Clojures defmulti style polymorphism  
 seems powerful but has left me wondering how to most effectively use  
 it.  I'm looking for some good real world examples of how people  
 have used polymorphism in clojure.

 Regards,

 Glen Stampoultzis



 


--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread Stuart Halloway

People keep looking at me funny when I point out variables as code  
smells during code review...

Stu


 Same here with the commas. Since I've been neck deep in Clojure, I've
 been pathologically forgetting to add them with other languages.

 On Jun 2, 10:06 am, Shawn Hoover shawn.hoo...@gmail.com wrote:
 On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid kid.me...@gmail.com  
 wrote:

 On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name  
 wrote:
 You meant to type disclosure, but instead you typed disclojure.

 Paul

 How about when you try to write code in other languages, and
 reflexively place parentheses before function/method names?

 (len 'Foo') -- not valid Python. :(

 /mike.

 Don't forget, commas are NOT optional!

 irb(main) a = [1 2 3]
 SyntaxError: compile error!
 


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



feature request: docstring for defstruct

2009-06-02 Thread Stuart Halloway

I would like to see defstruct take an optional docstring. Would such a  
patch be welcome?

Stu

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



filter on sequence

2009-06-02 Thread Wilson MacGyver

Apologies in advance on a very newbie question.

I've constructed a sequence

(take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2
(Math/log 2))])

doing a take 10 on it, produce the pairs I expect.

what I like to know is, how do I filter for with value b is  X

for example, the first 10 produces.

([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268]
[16 3.8471867757039027] [32 5.7707801635558535] [64 9.233248261689365]
[128 15.38874710281561] [256 26.380709319112476] [512
46.16624130844683] [1024 82.07331788168325])

what if I want to filter so I only get pairs for which the 2nd value
is  10. I couldn't figure out how to get
filter to work for pair values.

a 2nd question is more of general clojure idiom, in trying to covert
the following java
code from michaelg's java 1 presentation

private int calcSize(){
  int max = 2;
  while ((max/Math.log(max))  size 
max  Integer.MAX_VALUE  max  0){
max *=2;
  }
  return max;
}

My first reaction was to do it using a sequence. Is this the clojure
idiomatic way to convert a
while loop from other languages?

Thanks,
Mac

-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: feature request: docstring for defstruct

2009-06-02 Thread Sean Devlin

This would encourage documenting structs, so I think this is a good
idea.

Sean

On Jun 2, 11:31 am, Stuart Halloway stuart.hallo...@gmail.com wrote:
 I would like to see defstruct take an optional docstring. Would such a  
 patch be welcome?

 Stu
--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote:


what I like to know is, how do I filter for with value b is  X



You can use destructuring in your predicate's arg list:

(filter (fn [[_ x]] ( x 10)) *1)

In English, the function takes an argument which can be accessed  
sequentially. Destruture it such that its first two elements are named  
_ (a conventional name for I don't care) and x. Then the body of  
the predicate can operate on x.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: filter on sequence

2009-06-02 Thread Konrad Hinsen

On 02.06.2009, at 17:35, Wilson MacGyver wrote:

 for example, the first 10 produces.

 ([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268]
 [16 3.8471867757039027] [32 5.7707801635558535] [64 9.233248261689365]
 [128 15.38874710281561] [256 26.380709319112476] [512
 46.16624130844683] [1024 82.07331788168325])

 what if I want to filter so I only get pairs for which the 2nd value
 is  10. I couldn't figure out how to get
 filter to work for pair values.

Try this:

(take 3
   (filter #( (second %) 10)
  (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))])
   [2 (/ 2 (Math/log 2))])))

If you try to take 10 values, you will create an endless loop because  
with the given parameters your sequence actually has less than ten  
elements that satisfy the condition!

 a 2nd question is more of general clojure idiom, in trying to covert
 the following java code from michaelg's java 1 presentation

 private int calcSize(){
   int max = 2;
   while ((max/Math.log(max))  size 
 max  Integer.MAX_VALUE  max  0){
 max *=2;
   }
   return max;
 }

 My first reaction was to do it using a sequence. Is this the clojure
 idiomatic way to convert a while loop from other languages?

Clojure has loops as well:

(let [size 10]  ;made up
   (loop [max 2]
 (if (or (= (/ max (Math/log max)) size)
(= max Integer/MAX_VALUE)
(= max 0))
   max
   (recur (* 2 max)

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: filter on sequence

2009-06-02 Thread Andrew Wagner

 You can use destructuring in your predicate's arg list:


 Not to hijack the thread but...is there some reason clojure doesn't just
just call this pattern-matching? Is it different somehow?

--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Michael Wood

On Tue, Jun 2, 2009 at 5:35 PM, Wilson MacGyver wmacgy...@gmail.com wrote:

 Apologies in advance on a very newbie question.

 I've constructed a sequence

 (take 10 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))]) [2 (/ 2
 (Math/log 2))])

 doing a take 10 on it, produce the pairs I expect.

 what I like to know is, how do I filter for with value b is  X

 for example, the first 10 produces.

 ([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268]
 [16 3.8471867757039027] [32 5.7707801635558535] [64 9.233248261689365]
 [128 15.38874710281561] [256 26.380709319112476] [512
 46.16624130844683] [1024 82.07331788168325])

 what if I want to filter so I only get pairs for which the 2nd value
 is  10. I couldn't figure out how to get
 filter to work for pair values.

How about:

(take-while (fn [[a b]] ( b 10))
  (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))])
   [2 (/ 2 (Math/log 2))]))

 a 2nd question is more of general clojure idiom, in trying to covert
 the following java
 code from michaelg's java 1 presentation

 private int calcSize(){
  int max = 2;
  while ((max/Math.log(max))  size 
    max  Integer.MAX_VALUE  max  0){
    max *=2;
  }
  return max;
 }

 My first reaction was to do it using a sequence. Is this the clojure
 idiomatic way to convert a
 while loop from other languages?

I suppose it would depend on the loop, but yes, I think so.

-- 
Michael Wood esiot...@gmail.com

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



Re: filter on sequence

2009-06-02 Thread Wilson MacGyver

ah, got it. thanks!

On Tue, Jun 2, 2009 at 11:48 AM, Stephen C. Gilardi squee...@mac.com wrote:

 On Jun 2, 2009, at 11:35 AM, Wilson MacGyver wrote:

 what I like to know is, how do I filter for with value b is  X


 You can use destructuring in your predicate's arg list:

        (filter (fn [[_ x]] ( x 10)) *1)

 In English, the function takes an argument which can be accessed
 sequentially. Destruture it such that its first two elements are named _
 (a conventional name for I don't care) and x. Then the body of the
 predicate can operate on x.

 --Steve





-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Wilson MacGyver

actually I had the exact same reaction. So I'd echo Andrew's comment.
Is this different than pattern-matching in say haskell/scala?

On Tue, Jun 2, 2009 at 11:55 AM, Andrew Wagner wagner.and...@gmail.com wrote:
 You can use destructuring in your predicate's arg list:


  Not to hijack the thread but...is there some reason clojure doesn't just
 just call this pattern-matching? Is it different somehow?
 




-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Stuart Halloway

Ditto what everyone else said, plus let's get rid of the duplicated  
call to Math/log by splitting the iterate into an iterate + a map:

(take-while
   (fn [[_ second]] ( second 10))
   (map (fn [x] [x (/ x (Math/log x))])
(iterate #(* % 2) 2)))

Stu


 On 02.06.2009, at 17:35, Wilson MacGyver wrote:

 for example, the first 10 produces.

 ([2 2.8853900817779268] [4 2.8853900817779268] [8 2.8853900817779268]
 [16 3.8471867757039027] [32 5.7707801635558535] [64  
 9.233248261689365]
 [128 15.38874710281561] [256 26.380709319112476] [512
 46.16624130844683] [1024 82.07331788168325])

 what if I want to filter so I only get pairs for which the 2nd value
 is  10. I couldn't figure out how to get
 filter to work for pair values.

 Try this:

 (take 3
   (filter #( (second %) 10)
 (iterate (fn [[a b]] [(* 2 a) (/ a (Math/log a))])
  [2 (/ 2 (Math/log 2))])))

 If you try to take 10 values, you will create an endless loop because
 with the given parameters your sequence actually has less than ten
 elements that satisfy the condition!

 a 2nd question is more of general clojure idiom, in trying to covert
 the following java code from michaelg's java 1 presentation

 private int calcSize(){
  int max = 2;
  while ((max/Math.log(max))  size 
max  Integer.MAX_VALUE  max  0){
max *=2;
  }
  return max;
 }

 My first reaction was to do it using a sequence. Is this the clojure
 idiomatic way to convert a while loop from other languages?

 Clojure has loops as well:

 (let [size 10]  ;made up
   (loop [max 2]
 (if (or (= (/ max (Math/log max)) size)
   (= max Integer/MAX_VALUE)
   (= max 0))
   max
   (recur (* 2 max)

 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: filter on sequence

2009-06-02 Thread Wilson MacGyver

I saw that clojure has loop. But in other functional languages,
using loops are always discouraged. So I didn't know if loop
was the clojure idiomatic way of doing this.

On Tue, Jun 2, 2009 at 11:52 AM, Konrad Hinsen
konrad.hin...@laposte.net wrote:
 My first reaction was to do it using a sequence. Is this the clojure
 idiomatic way to convert a while loop from other languages?

 Clojure has loops as well:

 (let [size 10]  ;made up
   (loop [max 2]
     (if (or (= (/ max (Math/log max)) size)
            (= max Integer/MAX_VALUE)
            (= max 0))
       max
       (recur (* 2 max)

 Konrad.

 




-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Michael Wood

On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wagner.and...@gmail.com wrote:
 You can use destructuring in your predicate's arg list:

  Not to hijack the thread but...is there some reason clojure doesn't just
 just call this pattern-matching? Is it different somehow?

Why doesn't Ruby just call it destructuring like Lisp has been doing
for decades?  ;)

(Actually I know next to nothing about Ruby and its pattern matching
and not much more about Lisp.)

-- 
Michael Wood esiot...@gmail.com

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



Re: filter on sequence

2009-06-02 Thread Michael Wood

On Tue, Jun 2, 2009 at 6:02 PM, Michael Wood esiot...@gmail.com wrote:
 On Tue, Jun 2, 2009 at 5:55 PM, Andrew Wagner wagner.and...@gmail.com wrote:
 You can use destructuring in your predicate's arg list:

  Not to hijack the thread but...is there some reason clojure doesn't just
 just call this pattern-matching? Is it different somehow?

 Why doesn't Ruby just call it destructuring like Lisp has been doing
 for decades?  ;)

 (Actually I know next to nothing about Ruby and its pattern matching
 and not much more about Lisp.)

Or was that Haskell?  Sorry, I'll shut up now.

-- 
Michael Wood esiot...@gmail.com

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



Re: filter on sequence

2009-06-02 Thread Andrew Wagner

 Why doesn't Ruby just call it destructuring like Lisp has been doing
 for decades?  ;)

 So that non-academics have a prayer at not getting scared away by an
unnecessarily-technical name?

--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 11:55 AM, Andrew Wagner wrote:

 Not to hijack the thread but...is there some reason clojure doesn't  
just just call this pattern-matching? Is it different somehow?



This thread has some info on that:

http://groups.google.com/group/clojure/browse_frm/thread/0aa57ab265f7474a/074428b031af70ac#074428b031af70ac

(Rich Hickey's messages especially)

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: filter on sequence

2009-06-02 Thread Konrad Hinsen

On 02.06.2009, at 18:00, Wilson MacGyver wrote:

 actually I had the exact same reaction. So I'd echo Andrew's comment.
 Is this different than pattern-matching in say haskell/scala?

The difference is that a pattern match can fail, and in that case  
other patterns are tried. Clojure's destructuring assumes that the  
value has the right structure. If it doesn't, then you will get an  
exception thrown.


On 02.06.2009, at 18:02, Wilson MacGyver wrote:

 I saw that clojure has loop. But in other functional languages,
 using loops are always discouraged. So I didn't know if loop
 was the clojure idiomatic way of doing this.


Loops in Clojure are purely functional. They are in fact equivalent  
to an embedded recursive function. Unlike the typical use of loops  
in, say, Java, nothing is changed inside a loop, so there are no side  
effects.

Here's your example with the loop rewritten as an explicit recursive  
function:

(let [size 10
   loop-fn (fn [max]
(if (or (= (/ max (Math/log max)) size)
(= max Integer/MAX_VALUE)
(= max 0))
  max
  (recur (* 2 max]
   (loop-fn 2))

As you can see, the differences are cosmetic. There is no need to  
have a bad functional conscience for using loops!

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: filter on sequence

2009-06-02 Thread Wilson MacGyver

I see. very clever. I'm not used to loop constructs with
no side effect.

On Tue, Jun 2, 2009 at 12:21 PM, Konrad Hinsen
konrad.hin...@laposte.net wrote:
 I saw that clojure has loop. But in other functional languages,
 using loops are always discouraged. So I didn't know if loop
 was the clojure idiomatic way of doing this.


 Loops in Clojure are purely functional. They are in fact equivalent
 to an embedded recursive function. Unlike the typical use of loops
 in, say, Java, nothing is changed inside a loop, so there are no side
 effects.

 Here's your example with the loop rewritten as an explicit recursive
 function:

 (let [size 10
       loop-fn (fn [max]
                (if (or (= (/ max (Math/log max)) size)
                        (= max Integer/MAX_VALUE)
                        (= max 0))
                  max
                  (recur (* 2 max]
   (loop-fn 2))

 As you can see, the differences are cosmetic. There is no need to
 have a bad functional conscience for using loops!

 Konrad.

 




-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread Max Suica

people in math discussions raise their eyebrow at my new comma-less
tuple and set notation:

(a_1 a_2 ... a_n a_(n+1) .. ) in R^|N|

{1 2 3 4 5} = {a in N+ | a  6}

Haskel hated it that time I wrote:

fold:: (b a b) b [a]

or

sum x y  zs = fold (+) 0 x:y:zs, where:

sum 1 2 3 4 5 6 7 = haskell compiler smacks yo momma.

And finally, in C, I caught this line before I tried to do anything
silly:

defmacro();

Cheers!
~max

On Jun 2, 11:27 am, Stuart Halloway stuart.hallo...@gmail.com wrote:
 People keep looking at me funny when I point out variables as code  
 smells during code review...

 Stu



  Same here with the commas. Since I've been neck deep in Clojure, I've
  been pathologically forgetting to add them with other languages.

  On Jun 2, 10:06 am, Shawn Hoover shawn.hoo...@gmail.com wrote:
  On Tue, Jun 2, 2009 at 9:52 AM, Michael Reid kid.me...@gmail.com  
  wrote:

  On Fri, May 29, 2009 at 2:51 PM, Paul Stadig p...@stadig.name  
  wrote:
  You meant to type disclosure, but instead you typed disclojure.

  Paul

  How about when you try to write code in other languages, and
  reflexively place parentheses before function/method names?

  (len 'Foo') -- not valid Python. :(

  /mike.

  Don't forget, commas are NOT optional!

  irb(main) a = [1 2 3]
  SyntaxError: compile error!
--~--~-~--~~~---~--~~
You 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: feature request: docstring for defstruct

2009-06-02 Thread thearthur

it would conform to the clojure way.

On Jun 2, 8:45 am, Sean Devlin francoisdev...@gmail.com wrote:
 This would encourage documenting structs, so I think this is a good
 idea.

 Sean

 On Jun 2, 11:31 am, Stuart Halloway stuart.hallo...@gmail.com wrote:

  I would like to see defstruct take an optional docstring. Would such a  
  patch be welcome?

  Stu
--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread CuppoJava

I now write all my Java code without any types... and then realize I
have to go back and add them in later.


--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Tassilo Horn

Wilson MacGyver wmacgy...@gmail.com writes:

Hi Wilson,

 I saw that clojure has loop. But in other functional languages, using
 loops are always discouraged.  So I didn't know if loop was the
 clojure idiomatic way of doing this.

Clojure's `loop' (with `recur') is no real loop in an imperative
sense.  It's a form of (non-mutual) recursion optimized to be space
efficient on the JVM which lacks tail call optimization.  Using it is
perfectly idiomatic, although it's not the way to go for each and every
problem.

Bye,
Tassilo

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



Re: how would I do this functionally? (internally mutable state)

2009-06-02 Thread ronen

As mentioned before, most file systems have the ability of providing
callback to changes in files/directories, at SE 6 using this ability
requires resorting to native code (JNA or JNI, see 
http://jnotify.sourceforge.net/)
, in SE 7 this will be implemented in NIO 2 (http://java.sun.com/
developer/technicalArticles/javase/nio/).

I would look into rsync, as far as i know it implements a very
efficient algorithm for comparing folders, there is a Java
implementation http://jarsync.sourceforge.net/

On May 29, 4:09 pm, Korny Sietsma ko...@sietsma.com wrote:
 I keep reading this thread when I should be going to bed :)  Sadly,
 this stuff is in what I call my 0.2% time so I'm not working very
 hard on it right now.

 The ruby code, which basically works (but is rather ugly in parts)
 relies on reading the whole file tree into memory, and then traversing
 the tree, saving each node (file or dir) in a repostory, which
 internally detects duplicates as they are added.

 The repository stores all known nodes, indexed by size, and then
 grouped into clumps of identical nodes.  When you add a new node, it
 compares it to all clumps of the same size as the node, looking for an
 identical clump; if it finds one, the new node is added to the clump,
 otherwise it forms a new clump.
 (sorry if this is a bit of a vague description, I haven't worked on
 this code for a while so all the details are a bit vague)

 Once the repository is built, it's pretty easy to throw away all
 non-duplicate nodes, and report on the duplicates.

 This works, but has some issues:
 - it's got some kind-of ugly handling for some special cases, like
 making sure a directory doesn't match it's own children if it only has
 one child
 - it's a bit slow, and uses a lot of memory
 - it *only* handles exact matches.

 I've been playing with shingling and sketching algorithms that are
 used by search engines to identify nearly-identical documents, and I
 think they could be applied to this problem; in fact I suspect they
 could speed it up considerably.  (If you want to know more about this
 the best reference online seems to be the book Introduction to
 Information Retrieval which is 
 athttp://www-csli.stanford.edu/~hinrich/information-retrieval-book.html
 - the chapter most relevant is 
 athttp://nlp.stanford.edu/IR-book/html/htmledition/near-duplicates-and-...
 )

 But, like I said, this is my 0.2% time project, so it might be some
 time before I really do more than think about this. :)

 - Korny



 On Fri, May 29, 2009 at 4:51 PM, Daniel Lyons fus...@storytotell.org wrote:

  For whatever reason I just can't seem to put this problem down.

  I have rewritten the code substantially. A major bottleneck was using
  Java's MD5 classes. The Fast MD5 library really is, and that helped
  a lot. I did get the - notation to work and I have a reasonable HOF
  now for doing the winnowing, which might even be applicable to another
  program someday, maybe.

  Anyway I uploaded it here: 
  http://clojure.googlegroups.com/web/dupfinder.clj
    and again I'd love any feedback anyone cares to give.

  Just to add insult to injury, I went ahead and programmed it again in
  Ruby. The good news is that I can't seem to get Ruby to find all the
  files the Clojure one finds, but the bad news is that the Ruby version
  is like four times faster. I'd love to understand that. So I uploaded
  that too: http://clojure.googlegroups.com/web/dupfinder.rb. Of
  course it must be benefiting to some extent from the fact that the
  Ruby version has a lot less abstraction, but I don't see how the
  approach is fundamentally any different or why there would be such a
  large performance disparity. I must be missing something big.

  On May 28, 2009, at 6:50 AM, Korny Sietsma wrote:
  By the way, in response to whoever suggested pre-sorting files; I
  sort-of do this (in the old ruby version) but actually, mostly the
  program is looking for duplicate *directories* of files - the goal is
  to point it at my archive disk, and have it find the biggest identical
  subdirectories.  Duplicate file checking is needed for this, but it's
  only a tiny part.

  And I'm playing with sketching algorithms at work right now, which
  look very handy for the next phase, which is to find the biggest
  *similar* subdirectories.  That's the real goal - point a program at a
  terabyte archive disk, and have it spit out :
  /archive/old_disks/laptop_2007a is 312gb and 99% similar to
  /archive/misc/stuff_from_2007
  ... or sorting by file count:
  /archive/source/old_projects/c_stuff/1996 is 20,324 files and 97%
  similar to /archive/old/disks/laptop2006/unsorted/old_drives/
  old_archive/c_cpp_stuff/90s

  I can think of three ways to approach this, none of which are
  particularly easy.

  The first is to take the duplicate file finding function and look for
  common suffixes of paths. It could almost be like running a fuzzy
  duplicate finder against your duplicates. I suspect the performance
  

swing-utils: patch - returning the listeners

2009-06-02 Thread Roland Sadowski
May I suggest a small change in the add-*-listener functions in
contrib.swing-utils?
It's handy to have them return the listeners (and be able to
disable/remove them later etc). Patch attached.

-Roland
-- 
[ http://www.haltingproblem.net/  - my homepage ]

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



swing_utils_patch.diff
Description: Binary data


Re: swing-utils: patch - returning the listeners

2009-06-02 Thread Stephen C. Gilardi


On Jun 2, 2009, at 7:31 PM, Roland Sadowski wrote:


May I suggest a small change in the add-*-listener functions in
contrib.swing-utils?
It's handy to have them return the listeners (and be able to
disable/remove them later etc). Patch attached.


Nice change, Roland. I see that you're on the list at clojure.org/ 
contributing .


Patch applied.

Thanks!

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Good examples of defmulti polymorphism

2009-06-02 Thread Richard Newman

Some work in which I'm currently engaged uses ad hoc hierarchies for
dispatching on a handler and either a message method or a method and
response code. In the realm of HTTP clients -- imagine that the
response arrives as a method invocation -- the equivalent would be
writing something like

(defmethod do-response [MyHandler :post :ok]
  ;; Handle a success response to my POST request
  )

(defmethod do-response [MyHandler :any-method :failure]
  ;; Handle any kind of failure response to any method (GET, POST,
PUT...).
  )

The dispatch function can introspect the message itself to extract the
method, code, etc. etc. -- this is basically polymorphism over any
facet of the arguments, with full programmatic power to extract those
facets. Most importantly, applications can themselves augment the
hierarchy to include meaningful groupings -- in my example above, the
various methods all derive from :any-method, and you could easily
imagine a server having a :methods-i-cant-handle node in its
hierarchy, making that piece of logic explicit in the tree.

This example doesn't look that compelling, except that my real domain
has a rich hierarchy of message and response types, which allows a
great deal of abstraction in message handling.

(I hope one day to be able to unveil what I'm doing. It's not that
innovative, but it's not done yet!)
--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Richard Newman

 Not to hijack the thread but...is there some reason clojure doesn't just
 just call this pattern-matching? Is it different somehow?

I guess the simplest answer is because it's destructuring, not
pattern-matching :)

As Rich explained in the thread to which Stephen linked, pattern
matching (at least as I know it in Erlang) is usually used primarily
for dispatch -- a structure-analyzing switch, basically.

Clojure's destructuring is a logical extension of Common Lisp's
destructuring-bind, which takes an input list and binds variables to
parts of the list. Clojure's destructuring does exactly what its name
implies: it takes some structure and de-structures it into its
constituents. The pattern matching that Clojure does is just to
correctly map the matching structure (and its variables) against the
input. It's not used to match as part of a switch.
--~--~-~--~~~---~--~~
You 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: You know you've been writing too much Clojure when...

2009-06-02 Thread Richard Newman

 I now write all my Java code without any types... and then realize I
 have to go back and add them in later.

Heh, very often I allow the IDE to fill them in, because I'm too lazy
to type that much!
--~--~-~--~~~---~--~~
You 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: filter on sequence

2009-06-02 Thread Vagif Verdi

On Jun 2, 7:55 am, Andrew Wagner wagner.and...@gmail.com wrote:
  You can use destructuring in your predicate's arg list:

  Not to hijack the thread but...is there some reason clojure doesn't just
 just call this pattern-matching? Is it different somehow?

Pattern matching matches not only structure but also values.

For example
 foo 5 = 0
 foo 7 = 1
 foo x = x * 2


--~--~-~--~~~---~--~~
You 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: Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
Some good examples from everyone.  Thank you.

2009/6/3 Richard Newman holyg...@gmail.com


 Some work in which I'm currently engaged uses ad hoc hierarchies for
 dispatching on a handler and either a message method or a method and
 response code. In the realm of HTTP clients -- imagine that the
 response arrives as a method invocation -- the equivalent would be
 writing something like

 (defmethod do-response [MyHandler :post :ok]
  ;; Handle a success response to my POST request
  )

 (defmethod do-response [MyHandler :any-method :failure]
  ;; Handle any kind of failure response to any method (GET, POST,
 PUT...).
  )

 The dispatch function can introspect the message itself to extract the
 method, code, etc. etc. -- this is basically polymorphism over any
 facet of the arguments, with full programmatic power to extract those
 facets. Most importantly, applications can themselves augment the
 hierarchy to include meaningful groupings -- in my example above, the
 various methods all derive from :any-method, and you could easily
 imagine a server having a :methods-i-cant-handle node in its
 hierarchy, making that piece of logic explicit in the tree.

 This example doesn't look that compelling, except that my real domain
 has a rich hierarchy of message and response types, which allows a
 great deal of abstraction in message handling.

 (I hope one day to be able to unveil what I'm doing. It's not that
 innovative, but it's not done yet!)
 


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



unit testing private methods?

2009-06-02 Thread Allen Rohner

I have a namespace with some public functions, and some private
functions. I would like to write unit tests for the functions, and put
them in a separate file from the main name space. I would also like to
have an (ns) declaration in my tests file, because the tests require
several libraries. Of course, if I have private methods in namespace
A, I can't call them from namespace B. Right now, it seems I have
several options:

1) put the unit tests in the same file
2) put the unit tests in a separate file, in the same namespace
3) make the private functions public
4) ???

I don't really like the first three options. Ideally, the private
functions would remain private to every namespace except the testing
name space. Is there a good solution for this?

Allen

--~--~-~--~~~---~--~~
You 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: unit testing private methods?

2009-06-02 Thread Stuart Halloway

Hi Allen,

You could write a function that uses the clojure.contrib.with-ns/with- 
ns macro to dip into the namespace being tested and return the private  
function, assigning it to a local name in the test namespace.

I need this too, and have been meaning to ping the other Stuart about  
either (a) adding something like this to test-is, or (b) creating a  
new test-helpers library in contrib that would include this function.

Stu


 I have a namespace with some public functions, and some private
 functions. I would like to write unit tests for the functions, and put
 them in a separate file from the main name space. I would also like to
 have an (ns) declaration in my tests file, because the tests require
 several libraries. Of course, if I have private methods in namespace
 A, I can't call them from namespace B. Right now, it seems I have
 several options:

 1) put the unit tests in the same file
 2) put the unit tests in a separate file, in the same namespace
 3) make the private functions public
 4) ???

 I don't really like the first three options. Ideally, the private
 functions would remain private to every namespace except the testing
 name space. Is there a good solution for this?

 Allen

 


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



subtractng sequence?

2009-06-02 Thread Wilson MacGyver

More newbie questions. :)

If I have two sequences as follow:

(2 3 4 5 6 7 8 9 10)
(4 6 8 10)

what's the best way to subtract the 2nd sequence from the first one?

The best I can come up with was to do (first) on 2nd sequence  and turn around
and do a (remove) on the first sequence, etc until I exhaust the 2nd sequence.

is there a better way?

Thanks,

-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You 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: Good examples of defmulti polymorphism

2009-06-02 Thread Glen Stampoultzis
Actually considering I'm currently writing a game in clojure that contains a
lot of state this _is_ a good real world example for me.  Thanks very much
Laurent.

2009/6/3 Laurent PETIT laurent.pe...@gmail.com


 Hi,

 Here is an example of the implementation of the Visitor design
 pattern in clojure.
 Multimethods are sufficiently powerfull and there is nothing explictly
 named xxVisitor in the code example, since with clojure the Visitor
 pattern is a non-issue and solved by the more general multimethod
 concept.

 Find the code in the files section of clojure google group :
 http://clojure.googlegroups.com/web/state.clj

 And find here an example of using the code :

 1:6 designpatterns.state= (- (create-photo-booth 3) insert-coin
 button-identity-photo insert-coin button-release-coin)
 Insert coin
 Select your photo
 Take your identity photo
 Select your photo
 liberer piece
 {:photos 2, :state :needs-coin}
 1:7 designpatterns.state=

 It's more a tutorial-like example than a real life example, but I
 hope it will help,

 Regards,

 --
 Laurent

 2009/6/2 Glen Stampoultzis gst...@gmail.com:
  I'm used to polymorphism in OO systems where everything in driven from
  inheritance hierarchy.  Clojures defmulti style polymorphism seems
 powerful
  but has left me wondering how to most effectively use it.  I'm looking
 for
  some good real world examples of how people have used polymorphism in
  clojure.
  Regards,
  Glen Stampoultzis
 
 
 
  
 

 


--~--~-~--~~~---~--~~
You 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: subtractng sequence?

2009-06-02 Thread Christophe Grand

Wilson MacGyver a écrit :
 More newbie questions. :)

 If I have two sequences as follow:

 (2 3 4 5 6 7 8 9 10)
 (4 6 8 10)

 what's the best way to subtract the 2nd sequence from the first one?
   

Is the order of the second sequence important? If not:
(defn subtract [a b]
  (remove (into #{} b) a)) ; turns b into a set for efficient 
(logarithmic) lookup
; user= (subtract [2 3 4 5 6 7 8 9 10] [4 6 8 10])
; (2 3 5 7 9)

It works well as long as you don't have nil or false values in the 
second seq (in such cases you'll have to use 'contains?).

Christophe


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (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
-~--~~~~--~~--~--~---