Re: Any ways to prevent protocol functions from being hardcoded in?

2011-07-01 Thread Meikel Brandmeyer
Hi,

Am Freitag, 1. Juli 2011 02:34:01 UTC+2 schrieb Chas Emerick:

 But, you'd never do that, right?  Each implementation of Vector and Map 
 would have their own idiosyncratic implementations of `get`, and you _want_ 
 (need) that bolted into the deftyped class.

 Brian was looking to be able to dynamically rebind a protocol fn, which is 
 simply impossible for classes that have inline implementations.  The 
 solution in such cases seems to be that such protocol fns should be 
 implemented via extend, which would then allow for any kind of rebinding or 
 HOF action you want.

 Unless I'm missing something, I'd revise the received wisdom to say 
 inlined protocol methods are a low-level implementation detail.  If you 
 want the perf, go for it, but know that you're giving up some of the 
 benefits of vars for instances of classes that have direct impls.  That 
 sounds like a perfectly reasonable tradeoff.


That's not what I understood. I know about the trade-offs between extend and 
inline methods. I blogged some time ago about it and voted for extend being 
the default until speed matters. However Stuart wrote protocols are a 
low-level implementation detail. And I don't think that this is reasonable. 
Take any of the collection functions: get, nth, peek, pop, seq, ... Each is 
a perfect candidate for a protocol function. Why (and how) would I hide 
this? I think this is a different question than using extend or inlining.

Re-reading Stuart's email, I may have actually misunderstood his second 
paragraph.

Sincerely
Meikel

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

Aw: Continuations or monads or something

2011-07-01 Thread Meikel Brandmeyer
Hi,

BTW, did you look at the monad package in contrib? (The new one is 
algo.monad, I think.) Maybe you could use the continuation monad (which this 
basically is) for the infrastructure.

Sincerely
Meikel

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

Current state of clojure-contrib?

2011-07-01 Thread Mark Derricutt
Hey all,

Whats the current state of clojure-contrib for 1.3?  I remember seeing a
wiki post or something awhile ago with new package layouts/maven settings
etc but can't seem to find it now ;(

Mark


-- 
Great artists are extremely selfish and arrogant things — Steven Wilson,
Porcupine Tree

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

Intresting project....Ozma: extending Scala with Oz concurrency

2011-07-01 Thread Base
Found at: http://lambda-the-ultimate.org/node/4300

Scala ported to run on the Mozart VM.

-- 
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: Continuations or monads or something

2011-07-01 Thread Dave Ray
I read about it and didn't see how to map my idea onto it so I stormed
ahead. I'll take another look thought. This is probably one of those
cases where you don't see the perfectly good wheel right in front of
you until you invent one of  your own. :)

Dave

On Fri, Jul 1, 2011 at 2:16 AM, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 BTW, did you look at the monad package in contrib? (The new one is
 algo.monad, I think.) Maybe you could use the continuation monad (which this
 basically is) for the infrastructure.

 Sincerely
 Meikel

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

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


Re: Current state of clojure-contrib?

2011-07-01 Thread Aaron Bedra

You can find your answers at

http://dev.clojure.org/display/design/Contrib+Library+Names

As to where things are going or have ended up.  The most used libs are 
logging and jdbc, so an project.clj file that used these would look like


[org.clojure/java.jdbc 0.0.2]
[org.clojure/tools.logging 0.1.2]

Cheers,

Aaron
--
Clojure/core
http://clojure.com

On 07/01/2011 07:27 AM, Mark Derricutt wrote:

Hey all,

Whats the current state of clojure-contrib for 1.3?  I remember seeing 
a wiki post or something awhile ago with new package layouts/maven 
settings etc but can't seem to find it now ;(


Mark


--
Great artists are extremely selfish and arrogant things — Steven 
Wilson, Porcupine Tree

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



--
Cheers,

Aaron Bedra
--
Clojure/core
http://clojure.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: Any ways to prevent protocol functions from being hardcoded in?

2011-07-01 Thread David McNeil
On Jun 30, 7:54 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 Recently the received wisdom has been: protocols are a low-level
 implementation detail. Actual APIs should be built with normal functions
 that call the protocol methods.

Stuart- I am a bit confused by this statement, and judging by this
thread others are as well. Any chance you could elaborate on the
received wisdom with respect to protocols and APIs?

Thank you.

-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


pretty-print by default?

2011-07-01 Thread Jeffrey Schwab
Is there any way to make the Clojure repl pretty-print by default?

I have a bunch of little functions that return things like directory
listings and git output, mostly as seqs of lines or Files.  I could
change the functions to pretty-print (rather than return) their
results, but I often want to pass the result of one function to
another.  The optimal solution (I think) would be if the Clojure
repl's printer would pretty-print function results by default.

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


Integrating Clojure-CLR w/ VS

2011-07-01 Thread Sean Devlin
I'm trying to use Clojure in the .NET world.  I've got the binary
distribution downloaded, and this VS plugin

http://visualstudiogallery.msdn.microsoft.com/fb895809-2ae0-48aa-8a96-3c0d5b8e1fdc/

installed.  I'm trying to build my first Hello World executable.
However, when I try to run I get he following error:

Could not resolve this reference.  Could not locate the assembly
Clojure, Version=1.0.0.0...  Check to make sure the assembly exists
on disk.  If this reference required by your code, you may get
compilation errors.

I'm a totally .NET noob, so any insight would be great.

Thanks,
Sean

-- 
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: pretty-print by default?

2011-07-01 Thread Sean Devlin
Or maybe the repl could have a *printer* variable

On Jul 1, 9:32 am, Jeffrey Schwab j...@schwabcenter.com wrote:
 Is there any way to make the Clojure repl pretty-print by default?

 I have a bunch of little functions that return things like directory
 listings and git output, mostly as seqs of lines or Files.  I could
 change the functions to pretty-print (rather than return) their
 results, but I often want to pass the result of one function to
 another.  The optimal solution (I think) would be if the Clojure
 repl's printer would pretty-print function results by default.

-- 
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: pretty-print by default?

2011-07-01 Thread David Powell
On Fri, Jul 1, 2011 at 2:32 PM, Jeffrey Schwab j...@schwabcenter.comwrote:

 Is there any way to make the Clojure repl pretty-print by default?

 I have a bunch of little functions that return things like directory
 listings and git output, mostly as seqs of lines or Files.  I could
 change the functions to pretty-print (rather than return) their
 results, but I often want to pass the result of one function to
 another.  The optimal solution (I think) would be if the Clojure
 repl's printer would pretty-print function results by default.


Try:

(clojure.main/repl :print pprint)

-- 
Dave

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

2011-07-01 Thread Jeffrey Schwab
Thank you!  That is exactly what I needed.

-- 
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: pretty-print by default?

2011-07-01 Thread Kevin Downey
pprint by default would be excellent, except it deref's vars

On Fri, Jul 1, 2011 at 8:59 AM, Jeffrey Schwab j...@schwabcenter.com wrote:
 Thank you!  That is exactly what I needed.

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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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: pretty-print by default?

2011-07-01 Thread Jeffrey Schwab
I tried adding (clojure.main/repl :print pprint) to my user.clj, but clojure 
then reports an error, because clojure.main/repl does not (yet) exist.  Is 
there any work-around for this?  Maybe a way to register onLoad style hooks 
that will be executed once the repl is running?  Here's my current 
(butt-ugly) work-around:

; user.clj -- to be run manually once repl prompt appears
(defn pretty [] (eval '(clojure.main/repl :print pprint)))

-- 
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: Any ways to prevent protocol functions from being hardcoded in?

2011-07-01 Thread Aaron Cohen
On Fri, Jul 1, 2011 at 9:20 AM, David McNeil mcneil.da...@gmail.com wrote:
 On Jun 30, 7:54 am, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 Recently the received wisdom has been: protocols are a low-level
 implementation detail. Actual APIs should be built with normal functions
 that call the protocol methods.

 Stuart- I am a bit confused by this statement, and judging by this
 thread others are as well. Any chance you could elaborate on the
 received wisdom with respect to protocols and APIs?

I think a great example of this is clojure.java.io. The api is
reader and writer, but the implementation is in the Coercions and
IOFactory protocols.

It's the largest real world usage of protocols I've seen so far, and
it's quite a nice, I think.

--Aaron

-- 
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: pretty-print by default?

2011-07-01 Thread David Powell
user.clj is old, and isn't ideally suited for pre-loading handy things into
a repl.

An alternative might be to put your repl init stuff in a file, such as:

/home/repl-init.clj:

(require 'clojure.pprint)
(clojure.main/repl :print clojure.pprint/pprint)

And then change your repl startup script to be:

java -cp clojure.jar clojure.main -i /home/repl-init.clj -r

Because this is loaded after the repl is inited, you can also add lines
which set repl-bound variables such as:

(set! *print-length* 5)

which was raised recently as being something that user.clj can't do.

-- 
Dave

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

org.clojure/java.jdbc 0.0.3 available on Maven Central

2011-07-01 Thread Sean Corfield
Includes a fix for generated keys on PostgreSQL / MS SQL Server:

http://dev.clojure.org/jira/browse/JDBC-10
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

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


Re: How To Supply Multiple Values To Function In Map

2011-07-01 Thread John Palgut
map actually accepts any number of collections, as show in the official 
documentationhttp://clojure.github.com/clojure/clojure.core-api.html#clojure.core/map.
 
Your function passed to map just needs to accept parameters equal to the 
number of collections passed. So you could write something like the 
following:

Clojure 1.2.0
user= (dorun (map #(println %1 %2) [1 2 3 4] [2 3 4 5]))
1 2
2 3
3 4
4 5
nil

The advantage to the above code is you don't need to create a vector of 
subvectors.

-- 
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: pretty-print by default?

2011-07-01 Thread Sean Corfield
If you use lein repl, is there an easy equivalent?

On Fri, Jul 1, 2011 at 9:53 AM, David Powell djpow...@djpowell.net wrote:

 user.clj is old, and isn't ideally suited for pre-loading handy things into
 a repl.
 An alternative might be to put your repl init stuff in a file, such as:
 /home/repl-init.clj:
 (require 'clojure.pprint)
 (clojure.main/repl :print clojure.pprint/pprint)
 And then change your repl startup script to be:
 java -cp clojure.jar clojure.main -i /home/repl-init.clj -r
 Because this is loaded after the repl is inited, you can also add lines
 which set repl-bound variables such as:
 (set! *print-length* 5)
 which was raised recently as being something that user.clj can't do.
 --
 Dave

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



-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Russ olsen's Clojure Book

2011-07-01 Thread Russ Olsen
Sayth,

First, imagine my surprise when I saw just the title
of your post show up in a search...

Second, thanks for the kind words about the books
that I actually have written (so far). For what it's worth,
I have thought about doing a clojure book, but so far
it is only in the back of the napkin stage.

At this point I don't know how I would approach clojure
but I do think that the classic design patterns are a good
jumping off point for any new language discussion, mostly
because we are all familiar with them to one degree or
another. Rather than simply saying 'Clojure is powerful',
you can say,  'Hey, you know that problem that
the XYZ pattern solves? Here's the 2 lines of clojure that
does the same thing.'  That's more or less the approach
that I took in Design Patterns In Ruby - with Ruby, obviously.

Critically, the clojure (or Ruby for that matter) approach
may be very different than the original 1990's solution that
you will find in the GoF: This is a good thing since it
means that we have actually made some progress.

Finally, one of the best things about following Clojure
from its very early days is watching the idioms develop
and spread through out the community. As I tried to say in Eloquent
Ruby, the community behind a language and the
techniques that it develops are as much a part
of the language as the syntax.

Russ


On Jun 29, 11:09 pm, flebber flebber.c...@gmail.com wrote:
 Just wanted to put a shout out to Russ Olsen to see what would be
 needed to get a Russ Olsen book on clojure to happen. I am reading
 design principles in Ruby and its a great read, I feel I am learning
 much moe than just Ruby which is why I am reading it.

 I woould absolutely love to read how Russ would apply these design
 principles to Clojure a more functional language. His books are all 5
 star reads(amazon ratings) and would greatly enjoy being able to read
 a Russ Olsen clojure book.

 Is there any way we could help this to happen? Is anyone else
 interested in such a book?

 Sayth

-- 
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: pretty-print by default?

2011-07-01 Thread Phil Hagelberg
Sean Corfield seancorfi...@gmail.com writes:

 If you use lein repl, is there an easy equivalent?

You can set :repl-options [:print clojure.contrib/pprint], but that
depends on pprint being required before the repl launches, and I can't
think of a straightforward way to do that. Perhaps adding an :eval-init
entry in project.clj which can contain needed requires like this?

-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: pretty-print by default?

2011-07-01 Thread Jeffrey Schwab
Thank!

Why -r? The (clojure.main/repl) call seems to start a new repl.  (In fact, 
it took me a minute to figure out that this really needs to be the last 
thing in repl-init.clj.)

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

2011-07-01 Thread logan
I don't know if ergo is the right name to describe this project.

Most of the default emacs key-bindings are very ergonomic, assuming
you remap your ctrl to your caps lock. Most of the commands that you
use most frequently can be entered in with just your left hand, with
your little finger on the ctrl key and the other key (or other 2 keys)
positioned so that they can be quickly typed with two different
fingers. The default mappings are a pain to learn but they make more
sense from a practical perspective.

On Jun 27, 8:47 pm, flebber flebber.c...@gmail.com wrote:
 Something I just discovered and thought it might be of benefit here.
 Since the main environment for clojure is currently emacs; clojure
 box, swank etc; and emacs has a learning curve it may be useful to
 reduce the emacs learning curve so that we can concentrate on learning
 clojure.

 Ergo Emacshttp://ergoemacs.org. Provides normal(expected) key
 bindings for emacs plus includes a lot of goodies and language support
 bundled in by default. This might even by very cool with clj 
 launcherhttp://clojure02.managed.contegix.com/display/design/CLJ+Launcher.

 Just some languages supported out of the box. From 
 herehttp://ergoemacs.org/features.html.

 Csharp
 JavaScript
 PHP
 Haskell
 Clojure
 Erlang
 Scala
 OCaml, F#
 Lua

 And some of the preinstalled features.
 Additional Conveniences - there are far more listed on the site.

 Template set for tens of languages (yasnippet)
 Enhanced feature of name completion. (AutoComplete)
 Enhanced directory viewer (DiredPlus)
 Enhanced bookmark (BookmarkPlus)
 Emacs Unicode Browser
 Emacs Math Symbols Input Mode (xmsi-mode)
 Tab bar GUI (TabBarMode)
 A Twitter mode (TwIt)
 PDF and Image files can be viewed inside emacs.
 Bundled all common unix commands that are used by emacs: grep, find,
 diff, patch, gzip ... (the whole MSYS component of MinGW.)
 Support 3 new shells: shell (cmd.exe), msys-shell (bash), eshell
 (elisp shell), powershell (PowerShell). All these are under the menu

 I am going to try and figure out what clojure box installs and see if
 I can merge it with ergo emacs. It might create a great ready to go
 environement out of the box.

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


Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread .Bill Smith
I want a concise function that, given an arbitrary length sequence, 
determines whether the sequence is of consecutive integers starting with 
one.  So:

 (f [1 2 3]) returns true

 (f [1 2 4]) returns false

 (f [0 1 2]) returns false

My first try, which I am not proud of, follows:

(defn f [numbers]
  (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1) 
numbers


Can someone suggest something better?

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Ken Wesson
On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith william.m.sm...@gmail.com wrote:
 I want a concise function that, given an arbitrary length sequence,
 determines whether the sequence is of consecutive integers starting with
 one.  So:
  (f [1 2 3]) returns true
  (f [1 2 4]) returns false
  (f [0 1 2]) returns false
 My first try, which I am not proud of, follows:

 (defn f [numbers]
   (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1)
 numbers

 Can someone suggest something better?

Fast:

(defn iseq? [numbers]
  (loop [i 1 s (seq numbers)]
(if s
  (if (== (first s) i)
(recur (inc i) (next s)))
  true)))

Possibly-unreadably clever:

(defn iseq?2 [numbers]
  (and
(= (count numbers) (count distinct numbers))
(every? identity (map #(get (into [] numbers) (dec %) nil) numbers

Simple:

(defn iseq?3 [numbers]
  (= numbers (range 1 (inc (count numbers)

All of these blow up on (iterate inc 1) of course and the first on any
infinite seq. The other two may stop at the first non-matching value
though.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Ken Wesson
The other way around, actually -- the second and third will hang (in
count) on infinite seqs, the first stopping on any non-matching
item. Sorry, in a hurry here.

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread David Nolen
On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith william.m.sm...@gmail.comwrote:

 I want a concise function that, given an arbitrary length sequence,
 determines whether the sequence is of consecutive integers starting with
 one.  So:

  (f [1 2 3]) returns true

  (f [1 2 4]) returns false

  (f [0 1 2]) returns false

 My first try, which I am not proud of, follows:

 (defn f [numbers]
   (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1)
 numbers


 Can someone suggest something better?


(defn f [xs] (every? #(apply = %) (map vector xs (iterate inc 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

Please stand firm against Steve Yegge's yes language push

2011-07-01 Thread James Keats

Hi all. I've been looking at Clojure for the past month, having had a
previous look at it a couple of years ago and then moved on to other
things only to return to it now.

Over the past decade I have looked at many languages and many ways of
doing things. People may say this language or that language is
general purpose, but the fact remains that languages have their
niches in which they excel and beyond which it'd be foolish to
venture.

Clojure should not attempt be a mass success language or worry about
its Tiobe index ranking.

Clojure, the way I see it, is most suitable for the advanced
independent developer. It is a language in the image of its creator,
Rich Hickey. It's not a language for the factory hen. It won't become
the next Java. Java already fills that niche, and despite what some
may say, I don't see it going away anytime soon.

I don't feel Clojure needs to grow - in terms of size of language.
In fact it would worry me enormously if Clojure's path is to grow in
size. It is fundamentally unsuited for that. If anything I wish for it
to shrink even further and further.

A Rich Hickey's quote comes to mind:
• (paraphrased) Most Clojure programmers go through an arc.  First
they think “eww, Java” and try to hide all the Java.  Then they think
“ooh, Java” and realize that Clojure is a powerful way to write Java
code
and As I've said in my talks, most Clojure users go from eww, Java
libs to ooh, Java libs, leveraging the fact there there is already
a lib for almost anything they need to do. And using the lib is
completely transparent, idiomatic and wrapper free. - Google verbatim
for sources.

Whereas when Steve Yegge writes: which means that everyone (including
me!) who is porting Java code to Clojure (which, by golly, is a good
way to get a lot of people using Clojure) is stuck having to rework
the code semantically rather than just doing the simplest possible
straight port.  The more they have to do this, the more you're going
to shake users off the tree. all I could think on reading this is
horror, horror, oh God, horror!!!; he really doesn't get it. First,
he shouldn't be porting Java code to clojure, Second, Clojure IS
fundamentally different from Java, and third, such said users who
don't want to touch Java should not touch Clojure.

Clojure shouldn't worry about growing; java already has innumerable
libs. Clojure, imho, should continue its - what I would dub -
middleware begone! path, in which it'd provide an end-to-end, down-
to-the-metal comprehensible system that an individual developer can
get his head round and know exactly what's happening with his code and
its environment here and everywhere.

I could write more, but I have to run. Regards.
J.

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Bhinderwala, Shoeb
Here is another way:

 

(defn f [xs]

  (and 

 (= 1 (first xs)) 

 (apply = (map - (rest xs) xs

 



From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On
Behalf Of David Nolen
Sent: Friday, July 01, 2011 3:51 PM
To: clojure@googlegroups.com
Subject: Re: Most concise way to determine that a sequence is
consecutive integers starting with one?

 

On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith william.m.sm...@gmail.com
wrote:

I want a concise function that, given an arbitrary length
sequence, determines whether the sequence is of consecutive integers
starting with one.  So:

 

 (f [1 2 3]) returns true

 

 (f [1 2 4]) returns false

 

 (f [0 1 2]) returns false

 

My first try, which I am not proud of, follows:

 

(defn f [numbers]
  (every? (fn [[x y]] (= x y)) (partition 2 (interleave
(iterate inc 1) numbers

 

Can someone suggest something better?

 

(defn f [xs] (every? #(apply = %) (map vector xs (iterate inc 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

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Chouser
On Fri, Jul 1, 2011 at 3:51 PM, David Nolen dnolen.li...@gmail.com wrote:
 On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith william.m.sm...@gmail.com
 wrote:

 I want a concise function that, given an arbitrary length sequence,
 determines whether the sequence is of consecutive integers starting with
 one.  So:
  (f [1 2 3]) returns true
  (f [1 2 4]) returns false
  (f [0 1 2]) returns false
 My first try, which I am not proud of, follows:

 (defn f [numbers]
   (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1)
 numbers

 Can someone suggest something better?

 (defn f [xs] (every? #(apply = %) (map vector xs (iterate inc 1

(defn f [xs] (every? true? (map = xs (iterate inc 1

--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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread David Nolen
On Fri, Jul 1, 2011 at 4:04 PM, Chouser chou...@gmail.com wrote:

 (defn f [xs] (every? true? (map = xs (iterate inc 1

 --Chouser


Hrm, shoulda thought 'o that :)

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: pretty-print by default?

2011-07-01 Thread Shantanu Kumar
 You can set :repl-options [:print clojure.contrib/pprint], but that
 depends on pprint being required before the repl launches, and I can't
 think of a straightforward way to do that. Perhaps adding an :eval-init
 entry in project.clj which can contain needed requires like this?

+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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Ken Wesson
I see some more clever ways have been posted.

Perhaps a more interesting, general problem: detect if the input is an
arithmetic sequence at all.

Here's a few implementations to get you started.

Straightforward:

(let [diffs (map - xs (rest xs))]
  (every? identity (map = diffs (rest diffs

Ultra-sneaky:

(= 1 (count (distinct (map - xs (rest xs)

Speedy Gonzales:

(let [r (next xs)
  s (first r)
  diff (- s (first xs))]
  (loop [f s r (next r)]
(if xs
  (let [s (first r)]
(if (== diff (- s f))
  (recur s (next r
  true)))

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread David Nolen
On Fri, Jul 1, 2011 at 4:04 PM, Chouser chou...@gmail.com wrote:

 (defn f [xs] (every? true? (map = xs (iterate inc 1

 --Chouser


Also,

(defn f [xs] (every? #{1} (map - xs (iterate inc 0

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread .Bill Smith
Thanks everyone.

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Alan Malloy
On Jul 1, 1:41 pm, David Nolen dnolen.li...@gmail.com wrote:
 On Fri, Jul 1, 2011 at 4:04 PM, Chouser chou...@gmail.com wrote:
  (defn f [xs] (every? true? (map = xs (iterate inc 1

  --Chouser

 Also,

 (defn f [xs] (every? #{1} (map - xs (iterate inc 0

This has problems before 1.3 if you go beyond Integer/MAX_VALUE:

(#{1} (- (long 1) (long 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: pretty-print by default?

2011-07-01 Thread Sean Corfield
In IRC I asked Phil about this and he suggested putting (require
'clojure.pprint) in ~/.lein/user.clj with :repl-options [:print
clojure.pprint/pprint] and that does indeed work for now.

Sean

On Fri, Jul 1, 2011 at 1:10 PM, Shantanu Kumar kumar.shant...@gmail.com wrote:
 You can set :repl-options [:print clojure.contrib/pprint], but that
 depends on pprint being required before the repl launches, and I can't
 think of a straightforward way to do that. Perhaps adding an :eval-init
 entry in project.clj which can contain needed requires like this?

 +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: Please stand firm against Steve Yegge's yes language push

2011-07-01 Thread Gregg Reynolds
On Fri, Jul 1, 2011 at 2:59 PM, James Keats james.w.ke...@gmail.com wrote:


 ...



 Whereas when Steve Yegge writes:


Who?

-- 
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: swank-clojure/lein/emacs

2011-07-01 Thread Adam
I have the identical problem to Shoeb. Toohey's suggestion did not
work for me. But I got it to work. What I found is that lein deps
downloaded the wrong version of swank-clojure.  Note that previous to
this I had done lein plugin install swank-clojure 1.3.1 That
installed swank-clojure-1.3.1.jar in ~/.lein/plugins .

My project.clj is...

(defproject incanter 0.0.1-SNAPSHOT
  :description Play with incanter
  :dependencies [[incanter 1.2.3]
 [clojure 1.2.0]
 [clojure-contrib 1.2.0]]
  :dev-dependencies  [[swank-clojure 1.3.1]])

I do lib deps

But in my lib directory, I see swank-
clojure-1.3.0-20110104.084027-21.jar .

Doing lein swank gives the error Shoeb described.

If I simply delete the file swank-
clojure-1.3.0-20110104.084027-21.jar from my project's lib directory,
then lein swank works.

Why am I getting this wrong version of swank-clojure.jar?

--- Adam


On Jun 6, 3:00 pm, John Toohey j...@parspro.com wrote:
 I had this problem on OSX. To fix it, I removed the swank dependency
 from my project.clj file, then I ranleindeps to clear any old
 copies. Follow that withleinplugin install clojure-swank 1.3.1 and
 finallyleinswank.

 On Sun, Jun 5, 2011 at 17:26, Bhinderwala, Shoeb









 sabhinderw...@wellington.com wrote:
  Yes it is 4005. But I am just using the defaults. Does the problem have
  anything to do with the number 4005?

  Again, I am just following simple instructions outlined to get swank running
  usinglein, so that I can connect to it using emacs. I am not doing anything
  special or different. As a newcomer to clojure I am just struggling with
  getting a basic setup so I can use a repl in emacs and connect to swank
  launched bylein.

  Did anybody face similar problem/error? Are there any more detailed clearer
  instructions anywhere else?

  Thanks
  Shoeb

  -Original Message-
  From: clojure@googlegroups.com on behalf of Ambrose Bonnaire-Sergeant
  Sent: Sun 6/5/2011 3:56 PM
  To: clojure@googlegroups.com
  Subject: Re: swank-clojure/lein/emacs

  On Mon, Jun 6, 2011 at 3:46 AM, Bhinderwala, Shoeb 
  sabhinderw...@wellington.com wrote:

  Exception in thread main java.lang.IllegalArgumentException: No value
  supplied for key: 4005 (NO_SOURCE_FILE:1)

  Might be a coincidence, isn't the swank port 4005?

  Ambrose

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

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

 --
 ~JT

-- 
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: Most concise way to determine that a sequence is consecutive integers starting with one?

2011-07-01 Thread Rob Lachlan
Using map-indexed:

(defn f [xs] (every? true? (map-indexed #(= (inc %1) %2) xs)))


On Jul 1, 12:28 pm, .Bill Smith william.m.sm...@gmail.com wrote:
 I want a concise function that, given an arbitrary length sequence,
 determines whether the sequence is of consecutive integers starting with
 one.  So:

  (f [1 2 3]) returns true

  (f [1 2 4]) returns false

  (f [0 1 2]) returns false

 My first try, which I am not proud of, follows:

 (defn f [numbers]
   (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1)
 numbers

 Can someone suggest something better?

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


about lazy-seq

2011-07-01 Thread kawas
Hi,

As a clojure beginner I'm practicing my understanding of the language
but at some point the use of lazy-seq get blurry.

Imagine that I want to write a lazy function to extract a slice of a
collection something like this :
  (defn slice [coll low high]
(drop (dec low) (take high coll)))

... but hand-made using lazy-seq and with the constraint to check
the boundaries (= 1 low high (count coll))

Of course I could write the check in lazy-seq but each call counts
the collection.
I could try to use arity to keep collection length, but I don't want
to expose this to the user.
I could use and outer helper function, but what if I want it all in
one function ?

(defn slice [coll low high]
  (when (= 1 low high (count coll))
(let [step (fn step [coll low high]
 (lazy-seq
   (cond
 ( low 1)
   (step (rest coll) (dec low) (dec high))
 (and (= low 1) (= high 1))
   (cons (first coll) (step (rest coll) low (dec
high)))
 :else nil)))]
  (step coll low high


Unexpectedly, this is not lazy, it seems like I'm hanging onto my
head.
Is lazy-seq creating some kind of closure with my collection in it ?
How about lazy-seq, tail call and closure clearing ?

regards,
--
kawas

-- 
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: Please stand firm against Steve Yegge's yes language push

2011-07-01 Thread .Bill Smith


Whereas when Steve Yegge writes: which means that everyone (including 
 me!) who is porting Java code to Clojure (which, by golly, is a good 
 way to get a lot of people using Clojure) is stuck having to rework 
 the code semantically rather than just doing the simplest possible 
 straight port.  The more they have to do this, the more you're going 
 to shake users off the tree. all I could think on reading this is 
 horror, horror, oh God, horror!!!; he really doesn't get it. First, 
 he shouldn't be porting Java code to clojure, 


Do you mean no one should port Java code to Clojure, or do you mean Steve 
Yegge in particular should not port Java code to Clojure?  I can think of 
several good reasons why someone (including Steve Yegge) might choose to do 
that.  Would you mind elaborating on that point?
 
Regardless, after reading all of Steve Yegge's comments in that thread, I do 
not get the impression he is asking for anyone to throw the kitchen sink 
into Clojure.  Rather, he is asking for the Clojure community to be more 
receptive toward feedback and questions.  Yes, he says, being more receptive 
may lead to additions to Clojure, but it may just as well lead to answering 
questions in a constructive way.

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

2011-07-01 Thread Alan Malloy
(count coll) needs to realize the whole sequence all at once in order
to see how big it is. Depending on how much of this you want to do by
hand, something like the following is how I would write it:

(defn slice [low high coll]
  (lazy-seq
   (cond (pos? low)
 (slice (dec low) (dec high) (rest coll))

 (zero? high)
 nil

 :else (cons (first coll)
 (slice 0 (dec high) (rest coll))

On Jul 1, 4:29 pm, kawas laurent.joi...@gmail.com wrote:
 Hi,

 As a clojure beginner I'm practicing my understanding of the language
 but at some point the use of lazy-seq get blurry.

 Imagine that I want to write a lazy function to extract a slice of a
 collection something like this :
   (defn slice [coll low high]
     (drop (dec low) (take high coll)))

 ... but hand-made using lazy-seq and with the constraint to check
 the boundaries (= 1 low high (count coll))

 Of course I could write the check in lazy-seq but each call counts
 the collection.
 I could try to use arity to keep collection length, but I don't want
 to expose this to the user.
 I could use and outer helper function, but what if I want it all in
 one function ?

 (defn slice [coll low high]
   (when (= 1 low high (count coll))
     (let [step (fn step [coll low high]
                  (lazy-seq
                    (cond
                      ( low 1)
                        (step (rest coll) (dec low) (dec high))
                      (and (= low 1) (= high 1))
                        (cons (first coll) (step (rest coll) low (dec
 high)))
                      :else nil)))]
       (step coll low high

 Unexpectedly, this is not lazy, it seems like I'm hanging onto my
 head.
 Is lazy-seq creating some kind of closure with my collection in it ?
 How about lazy-seq, tail call and closure clearing ?

 regards,
 --
 kawas

-- 
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: pretty-print by default?

2011-07-01 Thread Tom Faulhaber
To do this from a simple command line, just do:

java -cp path-to-clojure-jar clojure.main -e (require
'clojure.pprint) (clojure.main/repl :print clojure.pprint/pprint)

modify to taste.

I once figured how to do this in Slime, too, but when I look at my
(quite dated) copy, it looks like pr-str is hard-coded.

Tom

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