Re: why the def of run-jetty looks like "defn #^Server run-jetty"

2010-08-09 Thread j-g-faustus
On Aug 9, 8:25 am, limux  wrote:
> what's the meaning of
> #^Server in the defn and let?
> (defn #^Server run-jetty
...
>   (let [#^Server s (create-server (dissoc options :configurator))]

It's a type hint. In the defn it specifies the type of the return
value, in the let it gives the type of the var.
#^... is the Clojure 1.1 syntax, in 1.2 it has changed to ^...

Type hints are optional. See 
http://clojure.org/java_interop#Java%20Interop-Type%20Hints


Regards

jf

-- 
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: looking for a simpler implementation of a function I'm using

2010-08-09 Thread Meikel Brandmeyer
Hi,

On Aug 9, 8:06 am, gary ng  wrote:

> Assuming vector is implemented in some form of array(well it seems to
> have the characteristic of an array where accessing any element would
> be O(1)), appending one element can be O(1) if there are space
> reserved for some extra items but if that action is repeated till the
> slack is filled up, some form of re-shuffling is needed.

It doesn't use arrays underneath (not in the "one big array" sense),
but a tree. So copying of array contents is limited to arrays sizes of
32 elements, which still counts as O(1). So it is in general faster
than using cons + reverse, which is O(n) and doesn't work with
infinite input.

See here for more info:
http://blog.higher-order.net/2009/02/01/understanding-clojures-persistentvector-implementation/

Accessing an element in a vector is actually O(log32 n), not O(1).

Sincerely
Meikel

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


Re: why the def of run-jetty looks like "defn #^Server run-jetty"

2010-08-09 Thread limux
I see, heartly thanks, and there is no any words about it in API doc
of clojure.org yet!

Regards
limux.


On 8月9日, 下午3时04分, j-g-faustus  wrote:
> On Aug 9, 8:25 am, limux  wrote:
>
> > what's the meaning of
> > #^Server in the defn and let?
> > (defn #^Server run-jetty
> ...
> >   (let [#^Server s (create-server (dissoc options :configurator))]
>
> It's a type hint. In the defn it specifies the type of the return
> value, in the let it gives the type of the var.
> #^... is the Clojure 1.1 syntax, in 1.2 it has changed to ^...
>
> Type hints are optional. 
> Seehttp://clojure.org/java_interop#Java%20Interop-Type%20Hints
>
> Regards
>
> jf

-- 
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: why the def of run-jetty looks like "defn #^Server run-jetty"

2010-08-09 Thread limux
The type hint can be placed on function parameters, let-bound names,
var names, and expressions.

And it can be placed behind or ahead of them. Isn't it?

On 8月9日, 下午3时31分, limux  wrote:
> I see, heartly thanks, and there is no any words about it in API doc
> of clojure.org yet!
>
> Regards
> limux.
>
> On 8月9日, 下午3时04分, j-g-faustus  wrote:
>
>
>
> > On Aug 9, 8:25 am, limux  wrote:
>
> > > what's the meaning of
> > > #^Server in the defn and let?
> > > (defn #^Server run-jetty
> > ...
> > >   (let [#^Server s (create-server (dissoc options :configurator))]
>
> > It's a type hint. In the defn it specifies the type of the return
> > value, in the let it gives the type of the var.
> > #^... is the Clojure 1.1 syntax, in 1.2 it has changed to ^...
>
> > Type hints are optional. 
> > Seehttp://clojure.org/java_interop#Java%20Interop-Type%20Hints
>
> > Regards
>
> > jf

-- 
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: why the def of run-jetty looks like "defn #^Server run-jetty"

2010-08-09 Thread Nicolas Oury
I am not 100% sure, but it seems they are always ahead.

(defn ^Bar foo ...)

tells that function foo returns something of class Bar.

(f ^Bar expr)  says that expr is of type Bar.

(let [ ^Bar e expr] ... says that e is of type Bar.

(Bar can be a class or an interface.)

The main usage (at least for me) is avoiding reflection in the context
of direct call to a Java method.

if you write:
(defn foo [x]
  (.clone x))

For Clojure, x is an object and so it does not know anything about its
interface (the methods it understands). So it cannot do better than a
"dynamic dispatch", looking at x class by reflection and searching for
a method named clone with the right signature.
It can be long, and so should be avoided on code that is called more
than rarely.
To avoid that:

(defn foo [^Clonable x]
   (.clone x))
Now, Clojure knows at compile-time that x is Clonable.
It can check that clone is in the known interface and use a direct
method call, which is faster.

(set! *warn-on-reflection* true)
makes the compiler emit a warning in the first case.

You should remark that this kind of problem only occurs when
interfacing directly with the host language.

Other usages may happen, like when a specific signatures is needed for
interoperability.


Hope I am not too wrong and that helps.

Nicolas

-- 
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: slow raw io

2010-08-09 Thread David Powell


On Sat 07/08/10 14:02 , "Stuart Halloway" stuart.hallo...@gmail.com sent:
> No. We want to collect more information and do more comparisons before
> moving away from the recommended Java buffering. 
> Stu

This isn't an issue with the buffering, it is an issue with the massive 
overhead of doing character at a time i/o - it is something that you really 
should never ever do.  I'd say something somewhere doing character at a time 
i/o is probably the number one cause of crippling performance problems 
that I've seen in Java.

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


zipping sequences

2010-08-09 Thread Nicolas Oury
Dear all,

I can't find a function in the library and don't see any easy way to write it.

I am looking for something like (zip & seqs)

such that (zip [a1  an] [b1  bn]) = [[a1 b1] . [an bn]]

Any function like that or easy way to construct it?

Best regards,

Nicolas.

-- 
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: zipping sequences

2010-08-09 Thread Meikel Brandmeyer
Hi,

On Aug 9, 12:21 pm, Nicolas Oury  wrote:

> (zip [a1  an] [b1  bn]) = [[a1 b1] . [an bn]]

(map vector [a1 ... an] [b1 ... bn])

Sincerely
Meikel

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


Re: slow raw io

2010-08-09 Thread David Powell


> This isn't an issue with the buffering, it is an issue with the massive
> overhead of doing character at a time i/o - it is something that you really
> should never ever do.  I'd say something somewhere doing character at a
> time i/o is probably the number one cause of crippling performance problems
> that I've seen in Java.

Just to add, the implementation really ought to use the stream copy stuff from 
clojure.java.io, which copies streams using a 1k buffer by default.

-- 
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: zipping sequences

2010-08-09 Thread Nicolas Oury
Thank you very much, it works great.

On Mon, Aug 9, 2010 at 11:23 AM, Meikel Brandmeyer  wrote:
> Hi,
>
> On Aug 9, 12:21 pm, Nicolas Oury  wrote:
>
>> (zip [a1  an] [b1  bn]) = [[a1 b1] . [an bn]]
>
> (map vector [a1 ... an] [b1 ... bn])
>
> 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: slow raw io

2010-08-09 Thread cageface
On Aug 7, 5:43 am, Peter Schuller  wrote:
> Interesting. Why do you consider it recommended to read one character
> at a time in a case like this? Maybe there is such a recommendation
> that I don't know about, but in general I would consider it contrary
> to expected practice when doing I/O if performance is a concern.

That's not a practice I'm familiar with either. Everything I've ever
read on I/O tuning suggests that reading single char is worst-case
performance, which seems borne out here.

Maybe this seems like a low-priority issue but I think slurp is likely
to be very commonly used. For instance, the Riak tutorial just posted
to Hacker News uses it:
http://mmcgrana.github.com/2010/08/riak-clojure.html

--
miles

-- 
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: TextMate users, what bundle are you using?

2010-08-09 Thread frou
David - Thanks for the tip.

I look forward to your REPL interaction; I think this is important for
TextMate users to have a good time.

On Aug 7, 11:38 pm, David Nolen  wrote:
> On Sat, Aug 7, 2010 at 4:47 PM, frou  wrote:
> > Searching Google, I see there are several TextMate bundles for Clojure
> > support. Some old, some new-ish. I'm sure there are others I didn't
> > find.
>
> > Who's using TextMate for Clojure? What's your tip for the best
> > bundle / auxiliary tools?
>
> > Thank you
>
> I don't think there are any that are satisfactory beyond syntax
> highlighting. For that I've find Mark McGranaghan's to be the 
> best:http://github.com/mmcgrana/textmate-clojure.
>
> I've forked it and have been working on adding decent REPL interactions via
> cake:http://github.com/ninjudd/cake. cake supports persistent REPLs and
> allows for quickly eval'ing sexprs from the command line. This makes
> TextMate integration pretty straightforward.
>
> Been a bit busy so it might a be a week or two before I have anything worth
> using.
>
> 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: slow raw io

2010-08-09 Thread David Powell

> Maybe this seems like a low-priority issue but I think slurp is likely
> to be very commonly used. For instance, the Riak tutorial just posted
> to Hacker News uses it:
> http://mmcgrana.github.com/2010/08/riak-clojure.html

In the past I've steered clear of using slurp because it didn't hand character 
encodings, so I had 
to write my own version (which did do block at a time copying), but now that 
the API has been 
fixed, I'd hope to be able to use the version in core, but only if the 
implementation is usable.

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


ANN : random-hash-tries SNAPSHOT

2010-08-09 Thread Nicolas Oury
Dear all,

I have made a very small library, which is very preliminary but usable.

It allows to create a distribution and draw from it.

Insertions, deletions, drawing are in O(log n).

example:

(def dist (distribution-from-seqable {:a 1 :b 2}))

(draw dist) => :a with proba 1/3, :b with proba 2/3

There is still a lot of work to do. It is currently slower than
Clojure hash-maps, for insertions, but not ridiculously so.
It takes more memory too, but it will improve.

User, suggestions and contributions are more than welcome.
You can mail me if you have any question on how to use it.

It is on clojars: nicolasoury.random-hash-tries.
There is also a public repository:

git://nicolasoury.repositoryhosting.com/nicolasoury/random-hash-tries.git

Best regards,

Nicolas.

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


jna Java Native Acess and clojure ....

2010-08-09 Thread Sunil Nandihalli
Hello everybody,
 I have been trying to use the native libraries in clojure. I have
found clj-native and clojure-jna which may serve the purposes. I would
like to get a feed back from the community .. Which of these is good
to use .. Or do you have any other suggestions..
Thanks in advances...
Sunil.

-- 
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: jna Java Native Acess and clojure ....

2010-08-09 Thread Chouser
On Mon, Aug 9, 2010 at 10:55 AM, Sunil Nandihalli
 wrote:
> Hello everybody,
>  I have been trying to use the native libraries in clojure. I have
> found clj-native and clojure-jna which may serve the purposes. I would
> like to get a feed back from the community .. Which of these is good
> to use .. Or do you have any other suggestions..

I wrote clojure-jna, but although I haven't had a chance to use
clj-native yet I understand it's significantly more advanced and
efficient than clojure-jna.  So I'd recommend at least starting with
clj-native to see if it will meet your needs.

--Chouser
http://joyofclojure.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: System calls

2010-08-09 Thread Dave
Thanks jf, that worked:

(ns msms
  (:gen-class)
  (:use [clojure.contrib.shell-out :only (sh)]))

(defn get-msms-pts-OSX
  [{pdb-file :pdb-file density :density radius :radius :as all :or
{density "1.0" radius "1.5"}}]
  (if (contains? all :pdb-file)
(sh "bash" :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
pdb_to_xyzr " pdb-file
" > 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr && "
"msms.MacOSX.2.6.1"
" -if 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
" -of 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold -
no_header -density "
density " -probe_radius " radius " && "
"rm -f 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
" 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.face"))
(println "No pdb-file provided in get-msms-pts-OSX.")))

Without the && in the system call:

(defn get-msms-pts-OSX
  [{pdb-file :pdb-file density :density radius :radius :as all :or
{density "1.0" radius "1.5"}}]
  (if (contains? all :pdb-file)
((sh "bash" :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
pdb_to_xyzr " pdb-file
  " > 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"))
 (sh "bash" :in (str "msms.MacOSX.2.6.1"
 " -if 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
 " -of 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold -
no_header -density "
 density " -probe_radius " radius))
 (sh "bash" :in (str "rm -f /Users/daviddreisigmeyer/lisps/clojure/
dpa/src/hold.xyzr"
 " 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.face")))
(println "No pdb-file provided in get-msms-pts-OSX.")))

I'd get the error:

java.lang.String cannot be cast to clojure.lang.IFn

Here it would only call the first command.  If I added a println
statement

(defn get-msms-pts-OSX
((println "Hi")
 (sh "bash" :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
pdb_to_xyzr " pdb-file
  " > 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"))
 (sh "bash" :in (str "msms.MacOSX.2.6.1"
 " -if 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
 " -of 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold -
no_header -density "
 density " -probe_radius " radius))
 (sh "bash" :in (str "rm -f /Users/daviddreisigmeyer/lisps/clojure/
dpa/src/hold.xyzr"
 " 
/Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.face")))
(println "No pdb-file provided in get-msms-pts-OSX.")))

it would run all three commands, and then print this error:

No message.
  [Thrown class java.lang.NullPointerException]

Can you see why this would be?

Thanks again for your help,

-Dave


On Aug 8, 12:00 am, j-g-faustus  wrote:
> On Aug 7, 4:46 pm, Dave  wrote:
>
> >   (execute (str "/../pdb_to_xyzr " pdb-file " > /..")))
>
> > Here it seemed to run (the above error isn't shown) but nothing
> > happened and the REPL become unresponsive again.  
>
> I think the issue is that Runtime.exec doesn't start a shell, just a
> subprocess, so things that are normally handled by the shell (like
> redirection and pipes) doesn't work.
> On
> (execute "env | grep PATH")
> I get "env: |: no such file or directory" - pipes and redirections are
> passed as arguments to the first command rather than being handled by
> the shell.
>
> > When I try:
> >   (sh :in (str "/...pdb_to_xyzr" pdb-file " > /...hold.xyzr")))
> > I get the following:
> > No matching method found: exec for class java.lang.Runtime
>
> :in is the "standard in" for a command, but you haven't specified
> which command.
>
> If you use "sh" as the command you get a shell and can use normal
> shell syntax for the :in parameter.
>
> So this works:
> user=> (sh "sh" :in "env | grep PATH")
> "PATH=/usr/bin:/bin:/usr/sbin:/sbin\n"
> user=> (sh "sh" :in "env > tmp.txt")
> ""
>
> > Does anyone know why this doesn't seem to work:
>
> > (defn test-execute [ls-arg1 ls-arg2]
> >   (execute (str "ls -" ls-arg1))
> >   (execute (str "ls -" ls-arg2)))
>
> As far as I can tell it does - it executes both commands, but returns
> only the result of the last one.
> If you want both, wrap them in a list or vector:
> (defn test-execute [ls-arg1 ls-arg2]
>   (list
>     (execute (str "ls -" ls-arg1))
>     (execute (str "ls -" ls-arg2
>
> Regards
> jf

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

Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Hello everyone,
Just for educational purposes, I'm writing a simple lisp compiler and
am stuck on a small problem.

I'm trying to write a function called (compile-function), which will
take a function as input and compile it.

If that function calls other functions, I would like (compile-
function) to automatically compile the called functions as well.

But I'm stuck on how to tell whether a function will be called or not.
Particularly when functions are passed around as objects.

So the question is this: Given a function f, how can I find all the
functions that f depends on?

Thanks a lot for your help
  -Patrick

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


Re: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Jarkko Oranen


On Aug 9, 7:54 pm, CuppoJava  wrote:
> Hello everyone,
> Just for educational purposes, I'm writing a simple lisp compiler and
> am stuck on a small problem.
>
> I'm trying to write a function called (compile-function), which will
> take a function as input and compile it.
>
> If that function calls other functions, I would like (compile-
> function) to automatically compile the called functions as well.
>
> But I'm stuck on how to tell whether a function will be called or not.
> Particularly when functions are passed around as objects.
>
> So the question is this: Given a function f, how can I find all the
> functions that f depends on?

I don't think that's feasible, if it's even possible in the first
place.

Functions that the parent function calls directly you can of course
try to compile whatever you encounter in a function call form; just
check if the operator is a known global function, and compile it.
However, if the operator is a local variable (ie. a function passed as
a parameter) there's no reliable way to find out what function it is.
It might even be a runtime-generated function (by eval)

Since you can't know what functions will be called, the generated code
must somehow verify that it's calling a function in the first place,
perhaps invoke the compiler (if all functions must be compiled), and
then execute it.

--
Jarkko

-- 
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: System calls

2010-08-09 Thread Mike Meyer
On Mon, 9 Aug 2010 09:37:14 -0700 (PDT)
Dave  wrote:

> Thanks jf, that worked:
> 
> (ns msms
>   (:gen-class)
>   (:use [clojure.contrib.shell-out :only (sh)]))
> 
> (defn get-msms-pts-OSX
>   [{pdb-file :pdb-file density :density radius :radius :as all :or
> {density "1.0" radius "1.5"}}]
>   (if (contains? all :pdb-file)
> (sh "bash" :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
> pdb_to_xyzr " pdb-file
>   " > 
> /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr && "
>   "msms.MacOSX.2.6.1"
>   " -if 
> /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
>   " -of 
> /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold -
> no_header -density "
>   density " -probe_radius " radius " && "
>   "rm -f 
> /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"
>   " 
> /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.face"))
> (println "No pdb-file provided in get-msms-pts-OSX.")))
> 
> Without the && in the system call:
> 
> (defn get-msms-pts-OSX
>   [{pdb-file :pdb-file density :density radius :radius :as all :or
> {density "1.0" radius "1.5"}}]
>   (if (contains? all :pdb-file)
> ((sh "bash" :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
  ^

You've got an extra open paren here, so it's trying to use the value
returned by "sh" (presumably a string) as a function - which fails
with this message:

> java.lang.String cannot be cast to clojure.lang.IFn
> 
> Here it would only call the first command.  If I added a println
> statement
> 
> (defn get-msms-pts-OSX
> ((println "Hi")
  ^

Same problem. In this case, println returns a null, so the error is:

> No message.
>   [Thrown class java.lang.NullPointerException]
> 
> Can you see why this would be?

   http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread CuppoJava
Thanks for the reply Jarkko. That helps quite a lot. I have some hacks
in place that works most of the time, but was stuck trying to figure
out a general solution. Knowing that there isn't one puts my mind at
ease.
  -Patrick

On Aug 9, 1:56 pm, Jarkko Oranen  wrote:
> On Aug 9, 7:54 pm, CuppoJava  wrote:
>
> > Hello everyone,
> > Just for educational purposes, I'm writing a simple lisp compiler and
> > am stuck on a small problem.
>
> > I'm trying to write a function called (compile-function), which will
> > take a function as input and compile it.
>
> > If that function calls other functions, I would like (compile-
> > function) to automatically compile the called functions as well.
>
> > But I'm stuck on how to tell whether a function will be called or not.
> > Particularly when functions are passed around as objects.
>
> > So the question is this: Given a function f, how can I find all the
> > functions that f depends on?
>
> I don't think that's feasible, if it's even possible in the first
> place.
>
> Functions that the parent function calls directly you can of course
> try to compile whatever you encounter in a function call form; just
> check if the operator is a known global function, and compile it.
> However, if the operator is a local variable (ie. a function passed as
> a parameter) there's no reliable way to find out what function it is.
> It might even be a runtime-generated function (by eval)
>
> Since you can't know what functions will be called, the generated code
> must somehow verify that it's calling a function in the first place,
> perhaps invoke the compiler (if all functions must be compiled), and
> then execute it.
>
> --
> Jarkko

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


Eclipse and Compojure

2010-08-09 Thread scott
I was going to try out a compojure tutorial in Eclipse. It appears
that only .clj files and not the .class files are included in the
compojure jar file.

I'm seeing the following error:
java.io.FileNotFoundException: Could not locate compojure/
core__init.class or compojure/core.clj on classpath:core.clj/web-
app-adder/src/adder line 1  Clojure Compilation Problem

I assume the problem is that there are no .class files in the jar. I
tried to rebuild the compojure jar using "lein jar" but still didn't
get .class files, even though:

lein help jar
Create a $PROJECT.jar file containing the compiled .class files as
well as the source .clj files.

Any suggestions would be appreciated - thanks.

Scott Hickey

-- 
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: Eclipse and Compojure

2010-08-09 Thread Laurent PETIT
Hi,

How could I help you from the Eclipse side ? I don't totally understand the
steps you're following in Eclipse / counterclockwise (but maybe it's not an
eclipse / counterclockwise problem ?)

2010/8/9 scott 

> I was going to try out a compojure tutorial in Eclipse. It appears
> that only .clj files and not the .class files are included in the
> compojure jar file.
>
> I'm seeing the following error:
> java.io.FileNotFoundException: Could not locate compojure/
> core__init.class or compojure/core.clj on classpath:core.clj
>  /web-
> app-adder/src/adder line 1  Clojure Compilation Problem
>
> I assume the problem is that there are no .class files in the jar. I
> tried to rebuild the compojure jar using "lein jar" but still didn't
> get .class files, even though:
>
> lein help jar
> Create a $PROJECT.jar file containing the compiled .class files as
> well as the source .clj files.
>
> Any suggestions would be appreciated - thanks.
>
> Scott Hickey
>
> --
> 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: Generics in PersistentXXX classes

2010-08-09 Thread Krukow


On Aug 4, 5:33 pm, Alex Tkachman  wrote:
> Guys,
>
> Thanks fo reference. I am still be curious if it should be done
> directly in Clojure runtime and available if clojure.jar is in
> classpath
>

Hello Alex,

You can easily use clojure.jar but there are a number of disadvantages
when all you use from clojure.jar are the data structures. See the
companion blog post:

http://blog.higher-order.net/2010/06/11/clj-ds-clojures-persistent-data-structures-for-java/

/Karl

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


drop-while for noobs

2010-08-09 Thread Alan
Hi all, I'm new to the group; I have some experience with both CL and
Java, though it's been a while for each. Anyway I really like Clojure
as a way of combining the best parts of the two languages, but I'm
still getting the hang of it and there are often things that confuse
me.

For example, I wanted to define a ring function, which takes as input
N objects, and returns a hash table mapping object N to object N+1
(mod N). I intended to use this to describe a compass object:
(ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.

I could have done this with basic recursion or as a list comprehension
using (for), (count), and (rem), but it seemed there must be a more
elegant solution with lazy sequences, like maybe combining cycle and
map to gloss over the N==0 wraparound issue. What I came up with was
frankly a monstrosity; I don't have the source with me at work, but it
looked roughly like:

(defn ring [& elts]
  (apply assoc {}
  (map #(list
   %1
   (fnext (drop-while
  (comp (partial or
 
(partial not= %1)
 
nil))
  (cycle elts))
elts

Since then I've realized I could have used nth and map-indexed to get
a less ugly result, but I was baffled by the awkwardness of drop-
while: is there a reason it demands nil or not-nil, instead of
treating false and nil as logical false? Converting false to nil was a
real bear (and retyping this from memory I'm pretty sure my syntax for
comp/partial/or is wrong somewhere), and in my experience clojure is
too clever make me do crap like this; what am I missing?

-- 
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: Generics in PersistentXXX classes

2010-08-09 Thread Krukow

On Aug 4, 3:51 pm, Matt Fowles  wrote:
> Alex~
>
> There is a project on github that does exactly this.
>
> http://github.com/krukow/clj-ds
>
> I don't know much about the current state of it, but I have plans in the
> next month or so to try it out at work.
>
> Matt
>

Matt,

If you find any problems, please don't drop clj-ds :) report them as
issues in the github project. I will strive for clj-ds to be as stable
as Clojure itself.

/Karl

-- 
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: drop-while for noobs

2010-08-09 Thread Wilson MacGyver
you can do this using partition.

let's assume I first define a

user=> (def a [:w :n :e :s])
#'user/a

user=> (partition 2 1 (conj a (first a)))
((:w :n) (:n :e) (:e :s) (:s :w))

gives you the pairs you need.

then you just need to turn it into hash-map
by doing

(map #(apply hash-map %)  (partition 2 1 (conj a (first a

On Mon, Aug 9, 2010 at 3:09 PM, Alan  wrote:
> Hi all, I'm new to the group; I have some experience with both CL and
> Java, though it's been a while for each. Anyway I really like Clojure
> as a way of combining the best parts of the two languages, but I'm
> still getting the hang of it and there are often things that confuse
> me.
>
> For example, I wanted to define a ring function, which takes as input
> N objects, and returns a hash table mapping object N to object N+1
> (mod N). I intended to use this to describe a compass object:
> (ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.
>
> I could have done this with basic recursion or as a list comprehension
> using (for), (count), and (rem), but it seemed there must be a more
> elegant solution with lazy sequences, like maybe combining cycle and
> map to gloss over the N==0 wraparound issue. What I came up with was
> frankly a monstrosity; I don't have the source with me at work, but it
> looked roughly like:
>
> (defn ring [& elts]
>  (apply assoc {}
>                      (map #(list
>                                   %1
>                                   (fnext (drop-while
>                                              (comp (partial or
>
> (partial not= %1)
>
> nil))
>                                              (cycle elts))
>                                            elts
>
> Since then I've realized I could have used nth and map-indexed to get
> a less ugly result, but I was baffled by the awkwardness of drop-
> while: is there a reason it demands nil or not-nil, instead of
> treating false and nil as logical false? Converting false to nil was a
> real bear (and retyping this from memory I'm pretty sure my syntax for
> comp/partial/or is wrong somewhere), and in my experience clojure is
> too clever make me do crap like this; what am I missing?
>
> --
> 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



-- 
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: Bug: contains? doesn't work on transient maps or sets

2010-08-09 Thread Nicolas Oury
Does someone know if there is a ticket open for this already?

Best,

Nicolas.

-- 
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: Eclipse and Compojure

2010-08-09 Thread scott
I have the tutorial described below working, using Emacs and
Leiningen.

http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html

I created a new Clojure project in Eclipse. I created a "lib"
directory, imported the dependent jar files that Leiningen pulled from
a repo into the lib directory, and added all of the jars to the
project build path.

When I imported the core.clj into the Eclipse project src folder, I
got:
java.io.FileNotFoundException: Could not locate compojure/
core__init.class or compojure/core.clj on classpath:
core.clj/web-
app-adder/src/adder line 1  Clojure Compilation Problem

It just occurred to me to start the REPL and see if the error still
shows up in the error console; it doesn't - the error disappears.

I shut down Eclipse and restarted, and I don't see the error in the
error console anymore - irregardless of the REPL running.

I assumed the problem had to do with the JDT finding no .class files
in the compojure jar file, but there is no error in the error console
now.

Thanks for offering to help - it seems to work now.

Scott Hickey



On Aug 9, 1:41 pm, Laurent PETIT  wrote:
> Hi,
>
> How could I help you from the Eclipse side ? I don't totally understand the
> steps you're following in Eclipse / counterclockwise (but maybe it's not an
> eclipse / counterclockwise problem ?)
>
> 2010/8/9 scott 
>
> > I was going to try out a compojure tutorial in Eclipse. It appears
> > that only .clj files and not the .class files are included in the
> > compojure jar file.
>
> > I'm seeing the following error:
> > java.io.FileNotFoundException: Could not locate compojure/
> > core__init.class or compojure/core.clj on classpath:    core.clj
> >  /web-
> > app-adder/src/adder     line 1  Clojure Compilation Problem
>
> > I assume the problem is that there are no .class files in the jar. I
> > tried to rebuild the compojure jar using "lein jar" but still didn't
> > get .class files, even though:
>
> > lein help jar
> > Create a $PROJECT.jar file containing the compiled .class files as
> > well as the source .clj files.
>
> > Any suggestions would be appreciated - thanks.
>
> > Scott Hickey
>
> > --
> > 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: drop-while for noobs

2010-08-09 Thread Armando Blancas
It works with booleans:

user=> (drop-while neg? [-3 -2 -1 0 1 2 3 ])
(0 1 2 3)
user=> (class (neg? -5))
java.lang.Boolean

On Aug 9, 12:09 pm, Alan  wrote:
> Hi all, I'm new to the group; I have some experience with both CL and
> Java, though it's been a while for each. Anyway I really like Clojure
> as a way of combining the best parts of the two languages, but I'm
> still getting the hang of it and there are often things that confuse
> me.
>
> For example, I wanted to define a ring function, which takes as input
> N objects, and returns a hash table mapping object N to object N+1
> (mod N). I intended to use this to describe a compass object:
> (ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.
>
> I could have done this with basic recursion or as a list comprehension
> using (for), (count), and (rem), but it seemed there must be a more
> elegant solution with lazy sequences, like maybe combining cycle and
> map to gloss over the N==0 wraparound issue. What I came up with was
> frankly a monstrosity; I don't have the source with me at work, but it
> looked roughly like:
>
> (defn ring [& elts]
>   (apply assoc {}
>                       (map #(list
>                                    %1
>                                    (fnext (drop-while
>                                               (comp (partial or
>
> (partial not= %1)
>
> nil))
>                                               (cycle elts))
>                                             elts
>
> Since then I've realized I could have used nth and map-indexed to get
> a less ugly result, but I was baffled by the awkwardness of drop-
> while: is there a reason it demands nil or not-nil, instead of
> treating false and nil as logical false? Converting false to nil was a
> real bear (and retyping this from memory I'm pretty sure my syntax for
> comp/partial/or is wrong somewhere), and in my experience clojure is
> too clever make me do crap like this; what am I missing?

-- 
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: drop-while for noobs

2010-08-09 Thread jv-li...@tx.rr.com
On Aug 9, 2:09 pm, Alan  wrote:
> Hi all, I'm new to the group

Welcome!

> I wanted to define a ring function, which takes as input
> N objects, and returns a hash table mapping object N to object N+1
> (mod N). I intended to use this to describe a compass object:
> (ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.

Here's a quick way that seems pretty close to your original:

user> (def x [:w :n :e :s])
#'user/x

user> (zipmap x (rest (cycle x)))
{:s :w, :e :s, :n :e, :w :n}

- Jeff

-- 
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: leiningen-war

2010-08-09 Thread Saul Hazledine
On Aug 9, 5:08 am, rob  wrote:
> As far as I can tell, based on using it so far, the war plugin for
> leiningen requires writing a web.xml file.  I was just wondering why
> it doesn't generate that xml file for you based on the information
> you've specified already in leiningen.  Would that be a good
> contribution to make, or are there reasons why it is preferable to
> write out the xml file?

I hadn't thought about that. If you can come up with a way of doing it
that would be supercool and I'd be happy to pull in your changes. One
thing to look out for is that some people (me included) mix Java and
Clojure servlets and so there still needs to be a way of manually
writing a web.xml for people that want it.

Possible approaches I can think of are:
1. making automatic generation only happen if there is no web.xml
2. add automatic generation as an option (either in project.clj or on
the command line)
3. write an alternative plugin (e.g lein-webxml) that uses the hooks
feature of leiningen to produce a web.xml when lein war is called.

Saul

-- 
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: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Daniel Gagnon
As far as I know, the book "Lisp In Small Pieces" should be a tremendous
help for anyone who builds a Lisp interpreter or compiler. You might want to
check it out.

On Mon, Aug 9, 2010 at 2:21 PM, CuppoJava wrote:

> Thanks for the reply Jarkko. That helps quite a lot. I have some hacks
> in place that works most of the time, but was stuck trying to figure
> out a general solution. Knowing that there isn't one puts my mind at
> ease.
>  -Patrick
>
> On Aug 9, 1:56 pm, Jarkko Oranen  wrote:
> > On Aug 9, 7:54 pm, CuppoJava  wrote:
> >
> > > Hello everyone,
> > > Just for educational purposes, I'm writing a simple lisp compiler and
> > > am stuck on a small problem.
> >
> > > I'm trying to write a function called (compile-function), which will
> > > take a function as input and compile it.
> >
> > > If that function calls other functions, I would like (compile-
> > > function) to automatically compile the called functions as well.
> >
> > > But I'm stuck on how to tell whether a function will be called or not.
> > > Particularly when functions are passed around as objects.
> >
> > > So the question is this: Given a function f, how can I find all the
> > > functions that f depends on?
> >
> > I don't think that's feasible, if it's even possible in the first
> > place.
> >
> > Functions that the parent function calls directly you can of course
> > try to compile whatever you encounter in a function call form; just
> > check if the operator is a known global function, and compile it.
> > However, if the operator is a local variable (ie. a function passed as
> > a parameter) there's no reliable way to find out what function it is.
> > It might even be a runtime-generated function (by eval)
> >
> > Since you can't know what functions will be called, the generated code
> > must somehow verify that it's calling a function in the first place,
> > perhaps invoke the compiler (if all functions must be compiled), and
> > then execute it.
> >
> > --
> > Jarkko
>
> --
> 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: Basic Lisp Compiler: How to tell which functions to compile?

2010-08-09 Thread Jules
It is impossible (undecidable) to tell precisely which functions a
function will call. Therefore you will need to consider not exactly
set of functions that a function will call, but some superset of that.
Why not take as your superset all functions? That is, always compile
all functions.

On Aug 9, 6:54 pm, CuppoJava  wrote:
> Hello everyone,
> Just for educational purposes, I'm writing a simple lisp compiler and
> am stuck on a small problem.
>
> I'm trying to write a function called (compile-function), which will
> take a function as input and compile it.
>
> If that function calls other functions, I would like (compile-
> function) to automatically compile the called functions as well.
>
> But I'm stuck on how to tell whether a function will be called or not.
> Particularly when functions are passed around as objects.
>
> So the question is this: Given a function f, how can I find all the
> functions that f depends on?
>
> Thanks a lot for your help
>   -Patrick

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


Re: drop-while for noobs

2010-08-09 Thread Alan
Also sorry the indentation is so awful. How do I get Google to let me
compose/edit in a fixed-width font?

On Aug 9, 12:09 pm, Alan  wrote:
> Hi all, I'm new to the group; I have some experience with both CL and
> Java, though it's been a while for each. Anyway I really like Clojure
> as a way of combining the best parts of the two languages, but I'm
> still getting the hang of it and there are often things that confuse
> me.
>
> For example, I wanted to define a ring function, which takes as input
> N objects, and returns a hash table mapping object N to object N+1
> (mod N). I intended to use this to describe a compass object:
> (ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.
>
> I could have done this with basic recursion or as a list comprehension
> using (for), (count), and (rem), but it seemed there must be a more
> elegant solution with lazy sequences, like maybe combining cycle and
> map to gloss over the N==0 wraparound issue. What I came up with was
> frankly a monstrosity; I don't have the source with me at work, but it
> looked roughly like:
>
> (defn ring [& elts]
>   (apply assoc {}
>                       (map #(list
>                                    %1
>                                    (fnext (drop-while
>                                               (comp (partial or
>
> (partial not= %1)
>
> nil))
>                                               (cycle elts))
>                                             elts
>
> Since then I've realized I could have used nth and map-indexed to get
> a less ugly result, but I was baffled by the awkwardness of drop-
> while: is there a reason it demands nil or not-nil, instead of
> treating false and nil as logical false? Converting false to nil was a
> real bear (and retyping this from memory I'm pretty sure my syntax for
> comp/partial/or is wrong somewhere), and in my experience clojure is
> too clever make me do crap like this; what am I missing?

-- 
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: drop-while for noobs

2010-08-09 Thread Alan
Weird. I wonder if I was using an outdated version of Clojure or (more
likely) assumed from (doc drop-while) that it wouldn't handle false
the way I wanted. When doc says "not nil" should I assume it means
"neither nil nor false", or should the doc for drop-while be updated?

user=> (doc drop-while)
-
clojure.core/drop-while
([pred coll])
  Returns a lazy sequence of the items in coll starting from the first
  item for which (pred item) returns nil.

On Aug 9, 1:01 pm, Armando Blancas  wrote:
> It works with booleans:
>
> user=> (drop-while neg? [-3 -2 -1 0 1 2 3 ])
> (0 1 2 3)
> user=> (class (neg? -5))
> java.lang.Boolean
>
> On Aug 9, 12:09 pm, Alan  wrote:
>
> > Hi all, I'm new to the group; I have some experience with both CL and
> > Java, though it's been a while for each. Anyway I really like Clojure
> > as a way of combining the best parts of the two languages, but I'm
> > still getting the hang of it and there are often things that confuse
> > me.
>
> > For example, I wanted to define a ring function, which takes as input
> > N objects, and returns a hash table mapping object N to object N+1
> > (mod N). I intended to use this to describe a compass object:
> > (ring :w :n :e :s) should result in {:w :n, :n :e, :e :s, :s :w}.
>
> > I could have done this with basic recursion or as a list comprehension
> > using (for), (count), and (rem), but it seemed there must be a more
> > elegant solution with lazy sequences, like maybe combining cycle and
> > map to gloss over the N==0 wraparound issue. What I came up with was
> > frankly a monstrosity; I don't have the source with me at work, but it
> > looked roughly like:
>
> > (defn ring [& elts]
> >   (apply assoc {}
> >                       (map #(list
> >                                    %1
> >                                    (fnext (drop-while
> >                                               (comp (partial or
>
> > (partial not= %1)
>
> > nil))
> >                                               (cycle elts))
> >                                             elts
>
> > Since then I've realized I could have used nth and map-indexed to get
> > a less ugly result, but I was baffled by the awkwardness of drop-
> > while: is there a reason it demands nil or not-nil, instead of
> > treating false and nil as logical false? Converting false to nil was a
> > real bear (and retyping this from memory I'm pretty sure my syntax for
> > comp/partial/or is wrong somewhere), and in my experience clojure is
> > too clever make me do crap like this; what am I missing?
>
>

-- 
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 help! Really simple function not working.

2010-08-09 Thread Carlos Torres
Hi to everyone,

I'm trying to create a function that takes a simple list and returns the
number of zeros in the list.
So I'm assuming that they will enter a list containing only numbers.
This is what I have so far, but it only works when the list empty. Can
somebody tell me what I'm missing?

(defn count-zeros
  "Returns the numbers of zero in a simple sequence of numbers"
  [list1]
  (cond
(empty? list1) 0
(not (zero? (first list1))) 0
:else
(recur (+ 1 (count-zeros (rest list1))

--Carlos

-- 
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 help! Really simple function not working.

2010-08-09 Thread Michael Gardner
On Aug 9, 2010, at 7:24 PM, Carlos Torres wrote:

> I'm trying to create a function that takes a simple list and returns the 
> number of zeros in the list.

user=> (count (filter zero? [0 1 2 3 0 4 5 6 0 7 8 9]))
3

-- 
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 help! Really simple function not working.

2010-08-09 Thread gary ng
On Mon, Aug 9, 2010 at 5:24 PM, Carlos Torres  wrote:
> Hi to everyone,
> I'm trying to create a function that takes a simple list and returns the
> number of zeros in the list.
> So I'm assuming that they will enter a list containing only numbers.
> This is what I have so far, but it only works when the list empty. Can
> somebody tell me what I'm missing?
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
>     (empty? list1) 0
>     (not (zero? (first list1))) 0
>     :else
>     (recur (+ 1 (count-zeros (rest list1))
> --Carlos

I believe your second codition break the recursion but in general,
don't write your own unless you are learning how to write recursive
code in clojure. this is textbook filter then count or foldl(i.e.
reduce).

-- 
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 help! Really simple function not working.

2010-08-09 Thread Laurent PETIT
2010/8/10 Carlos Torres 

> Hi to everyone,
>
> I'm trying to create a function that takes a simple list and returns the
> number of zeros in the list.
> So I'm assuming that they will enter a list containing only numbers.
> This is what I have so far, but it only works when the list empty. Can
> somebody tell me what I'm missing?
>
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
> (empty? list1) 0
> (not (zero? (first list1))) 0
> :else
> (recur (+ 1 (count-zeros (rest list1))
>


Hi Carlos, your function can be written:

(defn count-zeros [l] (reduce #(if (zero? %2) (inc %1) %1) 0 l))
or less cryptic with variable names
(defn count-zeros [l] (reduce (fn [nb-zeros elem] (if (zero? elem) (inc
nb-zeros) nb-zeros)) 0 l))

But if you really want to write it recursively, then you must understand you
cannot recur with the partial sum when your function expects a list. And it
does not make sense to recur and call count-zeros at the same time.

here is a working version, using recur:
(defn count-zeros [list1]
  (loop [list1 (seq list1) nb-zeros 0]
(if list1
  (recur (next list1) (if (zero? (first list1)) (inc nb-zeros)
nb-zeros))
  nb-zeros)))

HTH,

-- 
Laurent

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

Re: Please help! Really simple function not working.

2010-08-09 Thread Phil Hagelberg
On Mon, Aug 9, 2010 at 5:24 PM, Carlos Torres  wrote:
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
>     (empty? list1) 0
>     (not (zero? (first list1))) 0
>     :else
>     (recur (+ 1 (count-zeros (rest list1))

Michael's solution works too, but the problem here is that you're
calling recur in a way that doesn't make sense. You'd want to replace
the call to count-zeros with recur rather than calling both, but it's
not in the tail-position, so it can't be TCO'd.

Just remove the call to recur and it will work, albeit only for lists
small enough to not blow the stack.

-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: Please help! Really simple function not working.

2010-08-09 Thread Mark Engelberg
On Mon, Aug 9, 2010 at 6:00 PM, Phil Hagelberg  wrote:
> Just remove the call to recur and it will work, albeit only for lists
> small enough to not blow the stack.

I'm assuming from the tone of the original post that the author is
trying to generally understand how to write recursive functions in
Clojure, rather than use built-ins, and that processing
arbitrary-sized lists is a primary goal.  The posted code (minus the
call to recur), is an elegant recursive formulation that is idiomatic
in Scheme because Scheme is (typically) implemented in a way that
makes stack limitations (mostly) a non-issue.

In Clojure, you have to work around stack limitations imposed by Java,
and recursive functions must be "translated" to work on largish lists
in Clojure.  There is no one recipe to make that translation, but
there are several common patterns.  If the recursive call is in tail
position, you can usually write the function the same way, but replace
the self-call with the word "recur".  If not in tail position and the
function is a list-building function, you may be able to solve the
stack problem with a call to lazy-seq -- I touched on this topic in a
recent blog post:
http://programming-puzzler.blogspot.com/2010/07/translating-code-from-python-and-scheme.html

The solution to most recursive problems in Clojure is to build your
answer in an accumulator, so you must learn how to design and develop
accumulator-style recursive functions.  For an in-depth look at this
process (in Scheme), I recommend:
http://www.htdp.org/2001-11-21/Book/node156.htm

For mutually recursive problems, a trampoline may be an option.

If none of these options work, you may have to simulate your own call
stack (ugh).

It can sometimes be frustrating to write code in a language that is
built around recursion rather than iteration constructs, and then has
such severe limitations on how and when recursion can be safely used,
but with practice, the vast majority of code can be easily rewritten
in a manner conducive to Clojure.

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


Re: Please help! Really simple function not working.

2010-08-09 Thread Carlos Torres
On Mon, Aug 9, 2010 at 9:00 PM, Phil Hagelberg  wrote:

> On Mon, Aug 9, 2010 at 5:24 PM, Carlos Torres 
> wrote:
> > (defn count-zeros
> >   "Returns the numbers of zero in a simple sequence of numbers"
> >   [list1]
> >   (cond
> > (empty? list1) 0
> > (not (zero? (first list1))) 0
> > :else
> > (recur (+ 1 (count-zeros (rest list1))
>
> Michael's solution works too, but the problem here is that you're
> calling recur in a way that doesn't make sense. You'd want to replace
> the call to count-zeros with recur rather than calling both, but it's
> not in the tail-position, so it can't be TCO'd.
>
> Just remove the call to recur and it will work, albeit only for lists
> small enough to not blow the stack.
>
> -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
>

I totally forgot about how to use recur. Thanks to all for the fast help and
for pointing out my errors, and even suggesting corrections and
alternatives.
This is by far the best mailing list I've ever participated in. As you can
see I'm still learning Clojure, and I've a long way to go to master it.
Again thank you all for your help.

--Carlos

-- 
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: drop-while for noobs

2010-08-09 Thread Armando Blancas
> When doc says "not nil" should I assume it means
> "neither nil nor false"

Nope, false won't be taken as nil; in boolean expressions nil
evaluates to false. drop-while's doc mentions only nil but since it's
the predicate's return value it should be clear enough, I think.

-- 
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: Running on .Net

2010-08-09 Thread eyeris
I was able to build ClojureCLR using the DLR 1.0 source and the latest
clojure-clr in VS 2010. I am able to run Clojure.Main.exe and
Clojure.Compile.exe. Is there a way to integrate these into VS, so
that I can add .clj files to a project and set the build action to
"Build" or "Build with Clojure.Compile.exe" and get a .dll out the
other side?



On Aug 4, 8:45 pm, dmiller  wrote:
> the 7/23 date is, as they say, not operational. I've edited that out.
> I'll go as far as 'soon'.  (The new PC I was going supposed to move to
> and install VS2010 on has to be replaced due to the possibility that
> the hard disk will fry.)
>
> You cannot use DLR 1.0.   I need things that are not in that release.
> As stated on the wiki page:
>
> 'For the time being go "http://dlr.codeplex.com/SourceControl/
> changeset/changes/48032":here to get version 48032.'
>
> With a binary distribution, at least I can package an approved version
> of the DLR.
>
> -David
>
> On Aug 4, 1:59 pm, eyeris  wrote:
>
>
>
> > I tried to build the latest ClojureCLR using VS 2008. I used the DLR
> > 1.0 release. I successfully replaced your DLR project references and
> > built them:
>
> >http://imgur.com/SgUmu.jpg
>
> > Then I added a DLR reference to the Clojure project and built it,
> > resulting in these two errors "The extern alias MSC was not specified
> > in a /reference option":
>
> >http://imgur.com/LWjOs.jpg
>
> > Your installing-clojureclr page says "I know for sure that will work.
> > I hope to bring everything up to VS2010 (and because of DLR, no more
> > VS2008 for building) by 7/23/2010." but I didn't see anything in the
> > commit history to suggest that you've done this.
>
> > On Aug 4, 12:25 am, eyeris  wrote:
>
> > > I would like a zip of DLLs that are as widely compatible as possible
> > > across CLR/DLR versions accompanied by a clear list of which versions
> > > are compatible.
>
> > > Regarding releases, I'm glad to lag behind the bleeding edge by a lot
> > > in order to have a stable platform. What I want to be able to do is
> > > grab the DLLs, add them as references to my VS project, and compile,
> > > much like I do with NetBeans and the JVM clojure.
>
> > > I have to admit that I haven't tried ClojureCLR since right around the
> > > 1.1 release, so I don't remember the details of the problems that I
> > > encountered. I am in the process of migrating a lot of stuff from VS
> > > 2008 to VS 2010. Once I finish that I will try ClojureCLR again and
> > > get back to you regarding embedding and AOT.
>
> > > On Aug 3, 3:11 pm, dmiller  wrote:
>
> > > > I can move creating a binary distribution to the to top of the list.
>
> > > > I could use some guidance from the interested on what would serve the
> > > > purpose on this and other things mentioned here.
>
> > > > on the distribution:  Do you want just a zip of of DLLs?  An
> > > > installer?  Do you want installation to the GAC?
>
> > > > on 'stable, dependable': Is there any strategy on creating new
> > > > releases that makes sense?  Assume anyone wanting to stay on the
> > > > bleeding edge will build for themselves?
>
> > > > start-up speed:  I'mrunningsome experiments on that.   The problem
> > > > is mostly the monolithic nature of the assemblies created and the
> > > > amount of environment initialization.  Suggestions welcomed.
>
> > > > Ease of embeddability: please elaborate on the problems.
>
> > > > AOT'ing clj files:  Ditto.
>
> > > > -David
>
> > > > On Aug 3, 12:47 pm, Timothy Baldridge  wrote:
>
> > > > > > I really wish that ClojureCLR had a binary distribution. I like
> > > > > > clojure a lot but I have a .Netbackground and a lot of .Netcode to
> > > > > > interact with. If ClojureCLR had a stable, dependable binary
> > > > > > distribution I would be able to use it at work much more than I
> > > > > > already do. I don't care much about 1.2 features like defrecord. 
> > > > > > What
> > > > > > I care about is start-up speed, ease of embeddability, and Visual
> > > > > > Studio integration (not Intellisense, just AOT'ing .clj files).
>
> > > > >  +1 for all of that
>
> > > > > That paragraph basically explains why I haven't started using clojure
> > > > > at my work yet.
>
> > > > > Timothy Baldridge

-- 
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 help! Really simple function not working.

2010-08-09 Thread David Sletten
Carlos,

I think this is pretty much what you had in mind:
(defn count-zeros [l]
  (cond (empty? l) 0
(zero? (first l)) (inc (count-zeros (rest l)))
:else (count-zeros (rest l

(count-zeros '(9 8 6 0 1 2 0 5)) => 2
(count-zeros '(9 8 6)) => 0
(count-zeros '()) => 0

Of course the above version is not tail-recursive. However, once you're written 
a straightforward recursive function it is often easy to see how to rewrite it 
(using an accumulator here) to take advantage of Clojure's recur:
(declare count-zeros-aux)

(defn count-zeros [l]
  (count-zeros-aux l 0))

(defn- count-zeros-aux [l result]
  (cond (empty? l) result
(zero? (first l)) (recur (rest l) (inc result))
:else (recur (rest l) result)))

Here the base function presents the same interface to the user, and the private 
auxiliary function takes an additional accumulator argument.

You could accomplish pretty much the same thing by defining two versions with 
different arities:
(defn count-zeros
  ([l] (count-zeros l 0))
  ([l result]
 (cond (empty? l) result
   (zero? (first l)) (recur (rest l) (inc result))
   :else (recur (rest l) result

Or you could simplify things by using loop:
(defn count-zeros [l]
  (loop [num-list l
 result 0]
(cond (empty? num-list) result
  (zero? (first num-list)) (recur (rest num-list) (inc result))
  :else (recur (rest num-list) result

Have all good days,
David Sletten

On Aug 9, 2010, at 8:24 PM, Carlos Torres wrote:

> Hi to everyone,
> 
> I'm trying to create a function that takes a simple list and returns the 
> number of zeros in the list.
> So I'm assuming that they will enter a list containing only numbers.
> This is what I have so far, but it only works when the list empty. Can 
> somebody tell me what I'm missing?
> 
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
> (empty? list1) 0
> (not (zero? (first list1))) 0
> :else
> (recur (+ 1 (count-zeros (rest list1))
> 
> --Carlos
> 
> -- 
> 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: Please help! Really simple function not working.

2010-08-09 Thread Laurent PETIT
Hi,

2010/8/10 David Sletten 

> Carlos,
>
> I think this is pretty much what you had in mind:
> (defn count-zeros [l]
>   (cond (empty? l) 0
> (zero? (first l)) (inc (count-zeros (rest l)))
> :else (count-zeros (rest l
>
> (count-zeros '(9 8 6 0 1 2 0 5)) => 2
> (count-zeros '(9 8 6)) => 0
> (count-zeros '()) => 0
>
> Of course the above version is not tail-recursive. However, once you're
> written a straightforward recursive function it is often easy to see how to
> rewrite it (using an accumulator here) to take advantage of Clojure's recur:
> (declare count-zeros-aux)
>
> (defn count-zeros [l]
>   (count-zeros-aux l 0))
>
> (defn- count-zeros-aux [l result]
>   (cond (empty? l) result
>  (zero? (first l)) (recur (rest l) (inc result))
> :else (recur (rest l) result)))
>
> Here the base function presents the same interface to the user, and the
> private auxiliary function takes an additional accumulator argument.
>
> You could accomplish pretty much the same thing by defining two versions
> with different arities:
> (defn count-zeros
>   ([l] (count-zeros l 0))
>   ([l result]
>  (cond (empty? l) result
>(zero? (first l)) (recur (rest l) (inc result))
>:else (recur (rest l) result
>

Though here, the version with different arities "exposes as API for the
user" the 2-arity version, but it may not make sense for the user of your
function to know about this 2-arity version. I personally prefer the first
approach (with a private helper function via defn-) or the last approach
(with an embedded loop).

Cheers,

-- 
Laurent


>
> Or you could simplify things by using loop:
> (defn count-zeros [l]
>   (loop [num-list l
>  result 0]
> (cond (empty? num-list) result
>   (zero? (first num-list)) (recur (rest num-list) (inc result))
>   :else (recur (rest num-list) result
>
> Have all good days,
> David Sletten
>
> On Aug 9, 2010, at 8:24 PM, Carlos Torres wrote:
>
> Hi to everyone,
>
> I'm trying to create a function that takes a simple list and returns the
> number of zeros in the list.
> So I'm assuming that they will enter a list containing only numbers.
> This is what I have so far, but it only works when the list empty. Can
> somebody tell me what I'm missing?
>
> (defn count-zeros
>   "Returns the numbers of zero in a simple sequence of numbers"
>   [list1]
>   (cond
> (empty? list1) 0
> (not (zero? (first list1))) 0
> :else
> (recur (+ 1 (count-zeros (rest list1))
>
> --Carlos
>
> --
> 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
>

-- 
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 help! Really simple function not working.

2010-08-09 Thread David Sletten

On Aug 10, 2010, at 2:22 AM, Laurent PETIT wrote:

> 
> 
> You could accomplish pretty much the same thing by defining two versions with 
> different arities:
> (defn count-zeros
>   ([l] (count-zeros l 0))
>   ([l result]
>  (cond (empty? l) result
>(zero? (first l)) (recur (rest l) (inc result))
>:else (recur (rest l) result
> 
> Though here, the version with different arities "exposes as API for the user" 
> the 2-arity version, but it may not make sense for the user of your function 
> to know about this 2-arity version. I personally prefer the first approach 
> (with a private helper function via defn-) or the last approach (with an 
> embedded loop).

Hence "pretty much the same thing". :)

Have all good days,
David Sletten




-- 
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 help! Really simple function not working.

2010-08-09 Thread Laurent PETIT
2010/8/10 David Sletten 

>
> On Aug 10, 2010, at 2:22 AM, Laurent PETIT wrote:
>
>
>
>> You could accomplish pretty much the same thing by defining two versions
>> with different arities:
>> (defn count-zeros
>>   ([l] (count-zeros l 0))
>>   ([l result]
>>  (cond (empty? l) result
>>(zero? (first l)) (recur (rest l) (inc result))
>>:else (recur (rest l) result
>>
>
> Though here, the version with different arities "exposes as API for the
> user" the 2-arity version, but it may not make sense for the user of your
> function to know about this 2-arity version. I personally prefer the first
> approach (with a private helper function via defn-) or the last approach
> (with an embedded loop).
>
>
> Hence "pretty much the same thing". :)
>

Sure, since the OP is new to clojure, I thought giving this "guideline"
could be of help to him,

Cheers,

-- 
Laurent


>
> Have all good days,
> David Sletten
>
>
>
>
>  --
> 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