Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-27 Thread Mark Engelberg
Thanks for the info.  I'd need to research how clojure.lang.BigInt
differs from java.math.BigInteger, but I'm sure that adding the extra
case for BigInt in the multimethods wouldn't be too hard.

I'm still stumped as to why expt and sqrt would be 100x slower.  My
first thought is that the loop/recur machinery has changed in 1.3, to
support primitives in the recur, so perhaps there's some extra back
and forth boxing/unboxing going on, or perhaps loop/recur is just
fundamentally slower now?  Another possibility is that all the literal
numbers are now longs instead of Integers, so maybe that's slowing
down the computations?

I'd be curious to know whether explicitly boxing everything in the
second line of expt-int helps the performance at all (along with the '
math operators), i.e.,

(defn- expt-int [base pow]
  (loop [n pow, y (num 1), z base]

to

(defn- expt-int [base pow]
  (loop [n (num pow), y (num 1), z (num base)]

-- 
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: Some programs require much more memory in Clojure 1.3 alpha1

2010-09-27 Thread Andy Fingerhut
Hmmm.  I did some additional experiments using the JRockit JVM on  
Windows XP, and JRockit not only has equivalent memory usage for  
Clojure 1.2 and 1.3 alpha1, but it can also run these programs with  
significantly less memory than HotSpot.  HotSpot is similar, but not  
identical, in its memory requirements on all of Mac, Linux, and  
Windows XP.


This particular program has lots of small things allocated (e.g. one  
java.lang.String per line, and also a LazySeq and Cons created by lazy- 
seq in line-seq), and while it is traversing that str is internally  
using StringBuilder to create one big large string of the whole input  
file's contents.  I am guessing that HotSpot's default GC parameters  
are not good for this memory usage pattern, and somehow JRockit gets  
it right by default.


Anyone know any command line options for HotSpot that make it work  
harder to compact things down into the smallest space possible, no  
matter what?  I am aware of several pages of documentation on  
HotSpot's GC options, and I've been reading some of them, but it is a  
lot to wade through.


Thanks,
Andy

On Sep 26, 2010, at 4:30 PM, Andy Fingerhut wrote:

While updating the benchmark programs I wrote for the shootout web  
site for 1.3 alpha1, I came across a program that required much more  
memory to complete in 1.3 than it did in 1.2.  I boiled it down to a  
simpler program that has similar properties.



(ns filestr2
 (:gen-class))

(defn -main [ args]
 (with-open [br (java.io.BufferedReader. *in*)]
   (let [dna-str (apply str (line-seq br))]
 (println len= (count dna-str
 (. System (exit 0)))


I've checked that the function apply, str, and line-seq are  
identical between those two Clojure versions, except for a few minor  
things like type declarations and static declarations added in 1.3.0- 
alpha1.


I'm curious if anyone can explain the cause of this significant  
extra memory.  As an example of what I mean, when run on an input  
file with about 125 million characters, it requires 932 Mbytes with  
Clojure 1.2, but 1,736 Mbytes with Clojure 1.3 alpha1 (using the - 
Xmx command line option to the JVM).  That was on my Mac, and I've  
seen similar but not identical results on an Ubuntu system.  You can  
read more details if you are curious in the README file of this  
tarball:


http://homepage.mac.com/jafingerhut/files/private/toomuch1.tar.bz2

It also includes a program that uses binary search to find the  
smallest memory required in order for the program to succeed, to the  
nearest 8 MB.


Thanks,
Andy



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


Macro expansion problem

2010-09-27 Thread stefanmuenchow
I am a macro newbie... I want to create a macro that calls a function
with a given name and a parameter list on a given object. My first
idea was like this:

(defmacro call
  Calls an instance method on a given object with a list of params.
  [obj method-name params]
  `(. ~obj ~(symbol method-name) ~...@params))

It works fine, if the param list is a simple list, like (1 2 3 4),
but if params is created from an existing list, like (rest alist)
then it doesn't work. So params has to be evaluated first and then the
single params has to be expanded. How do I do that? I tried it with a
let block then I got other errors.

-- 
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: Lazytest 1.0.0 (beta)

2010-09-27 Thread faenvie
i am trying to use lazytest with eclipse + ccw ?

lazytest.watch does not work for me so far.
so i run my lazytests via:

(ns myapp.runtests
  (:require lazytest.runner.console
  lazytest.color
lazytest.report.nested))

; switch ansi-coloring off
(lazytest.color/set-colorize false)

 ; execute tests for specified namespaces
(doseq [sym ['myapp.tests1 'myapp.tests2]]
  (println Loading sym)
  (require sym)
  (println Running tests in sym)
  (lazytest.report.nested/report
   (lazytest.runner.console/run-tests sym)))

any better solutions ?


On Sep 24, 9:38 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
 http://github.com/stuartsierra/lazytest

 My attempt to steal all the good ideas from clojure.test, Circumspec,
 ClojureCheck, RSpec, Spock, ScalaTest, etc.  Kudos to all those
 authors for all their great work.

 -S

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


Hiccup with Sequence

2010-09-27 Thread Paul
Hi all,

I'm trying to output the items from a sequence into a HTML list using
the Hiccup HTML builder, but am having problems.

Here is the code I think 'should' work, but nothing after the ':ul' is
passed back to the response:

(html
[:html
[:body
[:ul
(doseq [item myseq] [:li item])
]
]
]
)

Can anyone see why this is not working?

Thanks,

Paul.

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


Re: Fighting with Emacs ;-)

2010-09-27 Thread psfblair
I found the old thread below, but unfortunately the solution isn't
working for me. If I have a foo.clj file in a buffer and evaluate
region on

(defn foo [] (+ 1 2))

I get

#'user/foo in the minibuffer. If I then evaluate region on

(foo)

I get 3 in the minibuffer. The slime REPL is giving me a prompt user
so I'm assuming it's in the user namespace, but I can't seem to get
expressions from the text buffer to evaluate in there.


On Mar 28, 5:01 am, Michał Marczyk michal.marc...@gmail.com wrote:

 On 27 March 2010 22:25, alux alu...@googlemail.com wrote:

  But now I see people use the result of this evaluation in their REPL
  (I see this in videos, so I cant ask 'em :). This doesnt work at all
  for me. I get the result in the minibuffer (this thing at the very
  bottom) and thats it.

 If the form you evaluate is of the def* variety, it's going to affect
 the namespace it resides in and not the namespace of the REPL. Thus,
 if you have e.g. (ns foo) at the top of the file, yet you're working
 in the user namespace at the REPL, then after using C-x C-e to
 evaluate a function definition in your file, you'll have to say
 something like foo/bar to reach it from the REPL. (Or (use :reload-all
 'foo), if you prefer.)

 If there is no namespace declaration in the file, then the expression
 will be evaluated in the user namespace, which means that you'll be
 able to use it straight away if that's your REPL's namespace. (If you
 say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
 something like user/bar to reach your function.)

 Sincerely,
 Michał

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


Re: Hiccup with Sequence

2010-09-27 Thread Nicolas Oury
doseq do not return anything. (It is for side-effect only).

You might be looking for 'for'.

(doc for)
-
clojure.core/for
([seq-exprs body-expr])
Macro
  List comprehension. Takes a vector of one or more
   binding-form/collection-expr pairs, each followed by zero or more
   modifiers, and yields a lazy sequence of evaluations of expr.
   Collections are iterated in a nested fashion, rightmost fastest,
   and nested coll-exprs can refer to bindings created in prior
   binding-forms.  Supported modifiers are: :let [binding-form expr ...],
   :while test, :when test.

  (take 100 (for [x (range 1) y (range 100) :while ( y x)] [x y]))


On Mon, Sep 27, 2010 at 11:25 AM, Paul paul_bow...@yahoo.com wrote:
 Hi all,

 I'm trying to output the items from a sequence into a HTML list using
 the Hiccup HTML builder, but am having problems.

 Here is the code I think 'should' work, but nothing after the ':ul' is
 passed back to the response:

 (html
        [:html
                [:body
                        [:ul
                                (doseq [item myseq] [:li item])
                        ]
                ]
        ]
 )

 Can anyone see why this is not working?

 Thanks,

 Paul.

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



-- 
Sent from an IBM Model M, 15 August 1989.

-- 
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: Macro expansion problem

2010-09-27 Thread Nicolas Oury
Difficult problem.

macro are syntactic tools. So they are not made to evaluate things at runtime.
You could expand to something that call eval at runtime but it is not
a good idea (It involves the compiler at each call)
If your (rest alist) is known at macro-expansion time, then it can
work but to help, I would need to know the context in which you are
using it.


What you want to do would be done by apply for functions.

However, as far as I know, apply do not work on method calls.
If you look at the problem from the java point of view, it is quite hard to
write some code that call a method with an unkown number of argument
without using reflection.

If you have a fix number of argument, you can do this:

(defmacro call-5
 Calls an instance method on a given object with a list of params.
 [obj method-name params]
 `(apply (fn [x1# x2# x3# x4# x5#] (. ~obj ~(symbol method-name) x1#
x2# x3# x4# x5#) ) ~params))

You can also write a macro that takes the arity as a parameter and do
that trick.

You can also generate an anonymous function with multiple arity
`(apply
  (fn ([x1#] (. ~obj ~(symbol method-name) x1# ))
   ([x1# x2#] (. ~obj ~(symbol method-name) x1#  x2#))
   ([x1# x2# x3#] (. ~obj ~(symbol method-name) x1#  x2# x3#))
  ... up to enough (20 should do the trick)  ~params)

However, ti might be easier to explain what you are trying to achieve
in a bigger context to see if there is a simpler path.


Best,

Nicolas.



On Mon, Sep 27, 2010 at 6:52 AM, stefanmuenchow stefanmuenc...@gmx.de wrote:
 I am a macro newbie... I want to create a macro that calls a function
 with a given name and a parameter list on a given object. My first
 idea was like this:

 (defmacro call
  Calls an instance method on a given object with a list of params.
  [obj method-name params]
  `(. ~obj ~(symbol method-name) ~...@params))

 It works fine, if the param list is a simple list, like (1 2 3 4),
 but if params is created from an existing list, like (rest alist)
 then it doesn't work. So params has to be evaluated first and then the
 single params has to be expanded. How do I do that? I tried it with a
 let block then I got other errors.

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



-- 
Sent from an IBM Model M, 15 August 1989.

-- 
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: Lazytest 1.0.0 (beta)

2010-09-27 Thread Laurent PETIT
Hi,

2010/9/27 faenvie fanny.aen...@gmx.de

 i am trying to use lazytest with eclipse + ccw ?


You note that you're using ccw, is that because you have a clue that there
could be something related to the lazytest-ccw combo in the issue you're
facing ?



 lazytest.watch does not work for me so far.
 so i run my lazytests via:

 (ns myapp.runtests
  (:require lazytest.runner.console
  lazytest.color
lazytest.report.nested))

 ; switch ansi-coloring off
 (lazytest.color/set-colorize false)

  ; execute tests for specified namespaces
 (doseq [sym ['myapp.tests1 'myapp.tests2]]
  (println Loading sym)
  (require sym)
  (println Running tests in sym)
  (lazytest.report.nested/report
   (lazytest.runner.console/run-tests sym)))

 any better solutions ?


 On Sep 24, 9:38 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:
  http://github.com/stuartsierra/lazytest
 
  My attempt to steal all the good ideas from clojure.test, Circumspec,
  ClojureCheck, RSpec, Spock, ScalaTest, etc.  Kudos to all those
  authors for all their great work.
 
  -S

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


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

Re: Hiccup with Sequence

2010-09-27 Thread Paul
Nicolas,

Yes, that's solved the problem. Many thanks for you swift help.

Paul.

On Sep 27, 12:12 pm, Nicolas Oury nicolas.o...@gmail.com wrote:
 doseq do not return anything. (It is for side-effect only).

 You might be looking for 'for'.

 (doc for)
 -
 clojure.core/for
 ([seq-exprs body-expr])
 Macro
   List comprehension. Takes a vector of one or more
    binding-form/collection-expr pairs, each followed by zero or more
    modifiers, and yields a lazy sequence of evaluations of expr.
    Collections are iterated in a nested fashion, rightmost fastest,
    and nested coll-exprs can refer to bindings created in prior
    binding-forms.  Supported modifiers are: :let [binding-form expr ...],
    :while test, :when test.

   (take 100 (for [x (range 1) y (range 100) :while ( y x)] [x 
 y]))





 On Mon, Sep 27, 2010 at 11:25 AM, Paul paul_bow...@yahoo.com wrote:
  Hi all,

  I'm trying to output the items from a sequence into a HTML list using
  the Hiccup HTML builder, but am having problems.

  Here is the code I think 'should' work, but nothing after the ':ul' is
  passed back to the response:

  (html
         [:html
                 [:body
                         [:ul
                                 (doseq [item myseq] [:li item])
                         ]
                 ]
         ]
  )

  Can anyone see why this is not working?

  Thanks,

  Paul.

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

 --
 Sent from an IBM Model M, 15 August 1989.

-- 
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: Some programs require much more memory in Clojure 1.3 alpha1

2010-09-27 Thread Peter Schuller
 Anyone know any command line options for HotSpot that make it work harder to
 compact things down into the smallest space possible, no matter what?  I am
 aware of several pages of documentation on HotSpot's GC options, and I've
 been reading some of them, but it is a lot to wade through.

There is an -XX:+UseCompressedOops which may be relevant.

In any case, is the actual live heap size larger (as in, the heap size
after a full GC, presuming you're running with the default throughput
collector), or are you comparing the growth of the heap size?

In particular, heap size is a function of, among others, the amount of
time spent GC:ing. The discrepancy may potentially be due to Hotspot
increasing the heap size for efficiency policy reasons rather than
necessarily that the live set is in fact bigger with Hotspot. You
might start by running with -XX:+PrintGC -XX:+PrintGCDetails and look
at the heap size after a full collection.

-- 
/ Peter Schuller

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread MarkSwanson
Nice!

-- 
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: Lazytest 1.0.0 (beta)

2010-09-27 Thread Stuart Sierra
Don't have any specific suggestion at the moment.  I'm planning on
adding a REPL runner that will do something similar to the code you
posted.
-S

On Sep 27, 5:52 am, faenvie fanny.aen...@gmx.de wrote:
 i am trying to use lazytest with eclipse + ccw ?

 lazytest.watch does not work for me so far.
 so i run my lazytests via:

 (ns myapp.runtests
   (:require lazytest.runner.console
       lazytest.color
             lazytest.report.nested))

 ; switch ansi-coloring off
 (lazytest.color/set-colorize false)

  ; execute tests for specified namespaces
 (doseq [sym ['myapp.tests1 'myapp.tests2]]
   (println Loading sym)
   (require sym)
   (println Running tests in sym)
   (lazytest.report.nested/report
    (lazytest.runner.console/run-tests sym)))

 any better solutions ?

 On Sep 24, 9:38 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote:



 http://github.com/stuartsierra/lazytest

  My attempt to steal all the good ideas from clojure.test, Circumspec,
  ClojureCheck, RSpec, Spock, ScalaTest, etc.  Kudos to all those
  authors for all their great work.

  -S

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread Tim Daly

 There is a movement afoot in the common lisp community to
implement quicklisp which is similar to the perl cpan site
or debian. It would be useful if there was a quicklisp (or
asdf) for Clojure. Thus you could apt-get a library for
clojure.

Tim Daly

On 9/27/2010 1:47 AM, David Sletten wrote:

Ladies and Gentlemen,

I present for your viewing pleasure the Clojure Cookbook (beta :) ):
http://www.gettingclojure.com/cookbook:clojure-cookbook

Gregg Williams has set up a framework at Getting Clojure to gather material, 
primarily focused on newbies, on how to flatten the learning curve.

The cookbook is a part of that vision. Inspired of course by O'Reilly's Perl 
Cookbook, the cookbook aims to present concrete examples along with brief 
discussions of specific tasks a new Clojure programmer might want to 
accomplish. The cookbook should complement the existing Clojure books and other 
documentation and provide additional examples that the other resources don't 
have time or space to consider.

At this point I have seeded the cookbook with approximately 20 recipes. I want 
to emphasize that I hope this will be a community resource with others 
providing content or even fixing my explanations where they are incorrect or 
off target. At the moment the cookbook is essentially read-only aside from the 
comments section at the bottom of each page. But once we get a sense of the 
community response the site will be opened for anyone to contribute.

Please take a look at the site and let us know what works and what needs to be 
fixed. And start thinking up your own recipes.

Thanks.

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: finding value nearest x

2010-09-27 Thread Glen Rubin
It occurs to me that another way of doing this is to map a new list
and then use the min fn.  something like:

(apply min (map #(Math/abs (- % 136)) xs))

maybe this is better and involves less calculations?



On Sep 25, 2:19 pm, Glen Rubin rubing...@gmail.com wrote:
 min-key looks good!  thx guys!!!

 On Sep 25, 10:44 am, Nicolas Oury nicolas.o...@gmail.com wrote:



  On Sat, Sep 25, 2010 at 3:40 PM, Jules julesjac...@gmail.com wrote:
   Maybe this: (min-key #(abs (- % 136)) xs)

  Wouldn't that be (apply min-key #(abs (- % 136)) xs)?

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


return index of a value

2010-09-27 Thread Glen Rubin
I have a vector of numbers

[0 99 3334 53 2 5 99 2 55 63]

I'd like to find the first index of a particular value.  For example
if the value was 99 then I want to return 1, b/c the index of 99 is
1.  I can do this with a loop/recur structure comparing each value in
the list to my desired value, however am wondering if there isn't a
built-in for doing so??  thanks again!

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


Re: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:28 AM, Glen Rubin wrote:

 It occurs to me that another way of doing this is to map a new list
 and then use the min fn.  something like:
 
 (apply min (map #(Math/abs (- % 136)) xs))
 
 maybe this is better and involves less calculations?

That gives you the minimum distance from 136, not the value itself. You can't 
get back the original value afterwards either, because you don't know whether 
to subtract or add the distance from 136.

-- 
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: finding value nearest x

2010-09-27 Thread Glen Rubin
yes correct.  but i can write a fn to determine the index of the
minimum distance in my new list?

that index applied to my original list will give me the value back.
and this still would involve fewer calculations i think.

On Sep 27, 10:50 am, Michael Gardner gardne...@gmail.com wrote:
 On Sep 27, 2010, at 9:28 AM, Glen Rubin wrote:

  It occurs to me that another way of doing this is to map a new list
  and then use the min fn.  something like:

  (apply min (map #(Math/abs (- % 136)) xs))

  maybe this is better and involves less calculations?

 That gives you the minimum distance from 136, not the value itself. You can't 
 get back the original value afterwards either, because you don't know whether 
 to subtract or add the distance from 136.

-- 
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: return index of a value

2010-09-27 Thread Stuart Halloway
Hi Glen,

Finding the *first* index isn't very Clojurish, what you want is to find *all* 
the indexes, lazily. Then if you want the first one, just call first.

(use '[clojure.contrib.seq-utils :only (positions)])
(positions #{99} [0 99 3334 53 2 5 99 2 55 63])
- (1 6)

Cheers,
Stu

 I have a vector of numbers
 
 [0 99 3334 53 2 5 99 2 55 63]
 
 I'd like to find the first index of a particular value.  For example
 if the value was 99 then I want to return 1, b/c the index of 99 is
 1.  I can do this with a loop/recur structure comparing each value in
 the list to my desired value, however am wondering if there isn't a
 built-in for doing so??  thanks again!
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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: return index of a value

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:45 AM, Glen Rubin wrote:

 I have a vector of numbers
 
 [0 99 3334 53 2 5 99 2 55 63]
 
 I'd like to find the first index of a particular value.  For example
 if the value was 99 then I want to return 1, b/c the index of 99 is
 1.  I can do this with a loop/recur structure comparing each value in
 the list to my desired value, however am wondering if there isn't a
 built-in for doing so??  thanks again!


In general, 'some' is used for linear searches. Given a vector 'v':

(some #(and (= 99 (v %)) %) (range 0 (count v)))

This is awkward because you're asking for the index and not the value itself. 
Index-based array manipulation is not often used in 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: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote:

 yes correct.  but i can write a fn to determine the index of the
 minimum distance in my new list?
 
 that index applied to my original list will give me the value back.
 and this still would involve fewer calculations i think.

Do you have a particular reason to be concerned about performance here? Don't 
worry about it unless profiling tells you it's a bottleneck for your program.

And I doubt it will actually give better performance anyway, even with min-key 
evaluating f more times than is necessary, because your f is so inexpensive to 
calculate.

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread Diullei Gomes
very good!

On Mon, Sep 27, 2010 at 1:12 PM, Tim Daly d...@axiom-developer.org wrote:

  There is a movement afoot in the common lisp community to
 implement quicklisp which is similar to the perl cpan site
 or debian. It would be useful if there was a quicklisp (or
 asdf) for Clojure. Thus you could apt-get a library for
 clojure.

 Tim Daly


 On 9/27/2010 1:47 AM, David Sletten wrote:

 Ladies and Gentlemen,

 I present for your viewing pleasure the Clojure Cookbook (beta :) ):
 http://www.gettingclojure.com/cookbook:clojure-cookbook

 Gregg Williams has set up a framework at Getting Clojure to gather
 material, primarily focused on newbies, on how to flatten the learning
 curve.

 The cookbook is a part of that vision. Inspired of course by O'Reilly's
 Perl Cookbook, the cookbook aims to present concrete examples along with
 brief discussions of specific tasks a new Clojure programmer might want to
 accomplish. The cookbook should complement the existing Clojure books and
 other documentation and provide additional examples that the other resources
 don't have time or space to consider.

 At this point I have seeded the cookbook with approximately 20 recipes. I
 want to emphasize that I hope this will be a community resource with others
 providing content or even fixing my explanations where they are incorrect or
 off target. At the moment the cookbook is essentially read-only aside from
 the comments section at the bottom of each page. But once we get a sense of
 the community response the site will be opened for anyone to contribute.

 Please take a look at the site and let us know what works and what needs
 to be fixed. And start thinking up your own recipes.

 Thanks.

 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
Diullei Gomes
Desenvolvedor .NET
http://diullei.com/
http://twitter.com/diullei

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread Andy Fingerhut

I believe

http://clojars.org

is intended to fill the purpose you describe, except using Leiningen  
or Maven instead of apt-get.  I do not know yet how good its inter- 
library dependency info is, but there is some there.


Andy

On Sep 27, 2010, at 9:12 AM, Tim Daly wrote:


There is a movement afoot in the common lisp community to
implement quicklisp which is similar to the perl cpan site
or debian. It would be useful if there was a quicklisp (or
asdf) for Clojure. Thus you could apt-get a library for
clojure.

Tim Daly

On 9/27/2010 1:47 AM, David Sletten wrote:

Ladies and Gentlemen,

I present for your viewing pleasure the Clojure Cookbook (beta :) ):
http://www.gettingclojure.com/cookbook:clojure-cookbook

Gregg Williams has set up a framework at Getting Clojure to gather  
material, primarily focused on newbies, on how to flatten the  
learning curve.


The cookbook is a part of that vision. Inspired of course by  
O'Reilly's Perl Cookbook, the cookbook aims to present concrete  
examples along with brief discussions of specific tasks a new  
Clojure programmer might want to accomplish. The cookbook should  
complement the existing Clojure books and other documentation and  
provide additional examples that the other resources don't have  
time or space to consider.


At this point I have seeded the cookbook with approximately 20  
recipes. I want to emphasize that I hope this will be a community  
resource with others providing content or even fixing my  
explanations where they are incorrect or off target. At the moment  
the cookbook is essentially read-only aside from the comments  
section at the bottom of each page. But once we get a sense of the  
community response the site will be opened for anyone to contribute.


Please take a look at the site and let us know what works and what  
needs to be fixed. And start thinking up your own recipes.


Thanks.

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


Re: finding value nearest x

2010-09-27 Thread Adam Burry
On Sep 25, 11:41 am, Glen Rubin rubing...@gmail.com wrote:
 I have a list of numbers and I want to find the one that is closest to
 136.  Is there an operator for performing this kind of operation or do
 I need to to do it algorithmically?

I think the normal way to do this is a k-d tree: 
http://en.wikipedia.org/wiki/Kd-tree

Adam

-- 
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: Macro expansion problem

2010-09-27 Thread stefanmuenchow
Thanks for your reply :)

The context: I am developing a wrapper generator that takes a Java
class and generates a Clojure wrapper, with a function for each method
etc. The purpose is to have nice wrappers, so your code is cleaner
as with all that Java calls. And it can ba a basis for more convenient
wrappers.

The generation of normal functions is easy but there is one case that
causes me some trouble: If there are methods that are static and non-
static with the same name and parameter count. So my first thought was
to define a multimethod, depending on the first parameter (which has
to be an instance of the class in case of non-static) with variable
number of args together with two macros, one for a static method call
and one for a simple method call, that take that variable arglist and
expand to the right call.

But I don't need the macros! Five minutes ago, I didn't know that
multimethods can have multiple function-bodies (and therefore multiple
different parameter lists). So I can generate the code for all
possible parameter lists without a variable  args parameter and
without the macros. Will be simple :)

-- 
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: finding value nearest x

2010-09-27 Thread Glen Rubin
ok, thx.  just trying to keep myself to a high standard while learning
this stuff ;)

On Sep 27, 11:12 am, Michael Gardner gardne...@gmail.com wrote:
 On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote:

  yes correct.  but i can write a fn to determine the index of the
  minimum distance in my new list?

  that index applied to my original list will give me the value back.
  and this still would involve fewer calculations i think.

 Do you have a particular reason to be concerned about performance here? Don't 
 worry about it unless profiling tells you it's a bottleneck for your program.

 And I doubt it will actually give better performance anyway, even with 
 min-key evaluating f more times than is necessary, because your f is so 
 inexpensive to calculate.

-- 
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: return index of a value

2010-09-27 Thread Glen Rubin
interesting!  thx guys!

On Sep 27, 10:45 am, Glen Rubin rubing...@gmail.com wrote:
 I have a vector of numbers

 [0 99 3334 53 2 5 99 2 55 63]

 I'd like to find the first index of a particular value.  For example
 if the value was 99 then I want to return 1, b/c the index of 99 is
 1.  I can do this with a loop/recur structure comparing each value in
 the list to my desired value, however am wondering if there isn't a
 built-in for doing so??  thanks again!

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


exception thrown when passing in nil parameter

2010-09-27 Thread Glen Rubin
I have a function that will accept 3 or 4 parameters.  Another
function I have calls it and passes in 4 arguments.  Sometimes, the
4th argument is nil and this causes an error, instead of just calling
the main function as if I passed in 3 arguments.  Meaning the main
function sees a 4th parameter with nil value.  How do I get it to act
as only 3 parameters were passed in this circumstance?  thx

-- 
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: exception thrown when passing in nil parameter

2010-09-27 Thread Alan
(defn f
  ([a b c] ...)
  ([a b c d]
(if d
...
(f a b c

Not the prettiest solution, I'll grant you; I'm sure someone will come
along with something better. But this will work.

On Sep 27, 11:13 am, Glen Rubin rubing...@gmail.com wrote:
 I have a function that will accept 3 or 4 parameters.  Another
 function I have calls it and passes in 4 arguments.  Sometimes, the
 4th argument is nil and this causes an error, instead of just calling
 the main function as if I passed in 3 arguments.  Meaning the main
 function sees a 4th parameter with nil value.  How do I get it to act
 as only 3 parameters were passed in this circumstance?  thx

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


How often do you use REPL?

2010-09-27 Thread Christian Guimaraes
It's a noob question... I know

But in my studies I use REPL 80% of the coding time.

More advanced users still uses REPL so many times?

thanks.

-- christian guimaraes

-- 
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 often do you use REPL?

2010-09-27 Thread Linus Ericsson
Why not?

The only thing I found very practical (even though it does not yet work 100%
(like autoloading the open code in the repl) for me) is the possibility to
fire of longer commands and function definitions (or the like) in Slime (or
vi-equivalent).

The repl is a great way to debug your thoughts, but it's harder to gain the
overview to build more complex programs (with more than a few rows or
functions, that is).

REPL ftw!

/Linus

2010/9/27 Christian Guimaraes cguimaraes...@gmail.com

 It's a noob question... I know

 But in my studies I use REPL 80% of the coding time.

 More advanced users still uses REPL so many times?

 thanks.

 -- christian guimaraes

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

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

Re: Fighting with Emacs ;-)

2010-09-27 Thread Linus Ericsson
I recognize that one. The repl haven't loaded the file your editing.

My (temporary) solution is to do a (load-file the file your editing)
after each edit that I want to debug, but that's a bit boring. I guess there
is some kind of reload feature somewhere...

/Linus

2010/9/27 psfblair psfbl...@gmail.com

 I found the old thread below, but unfortunately the solution isn't
 working for me. If I have a foo.clj file in a buffer and evaluate
 region on

 (defn foo [] (+ 1 2))

 I get

 #'user/foo in the minibuffer. If I then evaluate region on

 (foo)

 I get 3 in the minibuffer. The slime REPL is giving me a prompt user
 so I'm assuming it's in the user namespace, but I can't seem to get
 expressions from the text buffer to evaluate in there.


 On Mar 28, 5:01 am, Michał Marczyk michal.marc...@gmail.com wrote:

  On 27 March 2010 22:25, alux alu...@googlemail.com wrote:
 
   But now I see people use the result of this evaluation in their REPL
   (I see this in videos, so I cant ask 'em :). This doesnt work at all
   for me. I get the result in the minibuffer (this thing at the very
   bottom) and thats it.
 
  If the form you evaluate is of the def* variety, it's going to affect
  the namespace it resides in and not the namespace of the REPL. Thus,
  if you have e.g. (ns foo) at the top of the file, yet you're working
  in the user namespace at the REPL, then after using C-x C-e to
  evaluate a function definition in your file, you'll have to say
  something like foo/bar to reach it from the REPL. (Or (use :reload-all
  'foo), if you prefer.)
 
  If there is no namespace declaration in the file, then the expression
  will be evaluated in the user namespace, which means that you'll be
  able to use it straight away if that's your REPL's namespace. (If you
  say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
  something like user/bar to reach your function.)
 
  Sincerely,
  Michał

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

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

Re: How often do you use REPL?

2010-09-27 Thread Laurent PETIT
A lot. By that, I mean that probably 80% to 100% of the time the REPL is
running waiting for your command.
And what may change is that you may more and more send code to the REPL
from your favorite editor.

2 flavors :
  * keep the full control on what is emitted to the REPL. There are
shortcuts for your favorite editor to send the selection, or the top level s
expression, to the REPL.
  * leverage some automation from your IDE : e.g. ccw (plugin for clojure
code in Eclipse) has a mode for automatically reloading the namespaces of
your project everytime you save a file (in addition to the above mentioned
shortcuts)

2010/9/27 Christian Guimaraes cguimaraes...@gmail.com

 It's a noob question... I know

 But in my studies I use REPL 80% of the coding time.

 More advanced users still uses REPL so many times?

 thanks.

 -- christian guimaraes

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

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

Re: How often do you use REPL?

2010-09-27 Thread Wilson MacGyver
I use REPL quite a bit. Especially if I'm quickly trying to throw
something together.
I'd use vimclojure and REPL.

In intelliJ, I use REPL for brain storm and testing.

On Mon, Sep 27, 2010 at 3:14 PM, Christian Guimaraes
cguimaraes...@gmail.com wrote:
 It's a noob question... I know

 But in my studies I use REPL 80% of the coding time.

 More advanced users still uses REPL so many times?


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


Possible to avoid reflection in this deftype in 1.3 alpha1?

2010-09-27 Thread Andy Fingerhut
The following program compiles and runs perfectly fine in both 1.2 and  
1.3 alpha1.  It has no reflection warnings in 1.2, but it does in 1.3  
alpha1.  I have tried several variations, but I haven't yet been able  
to figure out how to write type declarations that avoid reflection in  
1.3 alpha1.  Does anyone know whether this is a bug?


Or perhaps code like this ought to be structured completely  
differently in order to avoid reflection, and it was just a fluke that  
it worked in 1.2?


Thanks,
Andy

(ns nbody
  (:gen-class))

(set! *warn-on-reflection* true)

(definterface IBody
  (^double x [])
  (^double y [])
  (^double z [])
  (^double dist [other]))

(deftype Body [^{:unsynchronized-mutable true :tag double} x
   ^{:unsynchronized-mutable true :tag double} y
   ^{:unsynchronized-mutable true :tag double} z ]
  IBody
  (x [this] x)
  (y [this] y)
  (z [this] z)
  (dist [this other]
(let [^Body nbody other
  dx (- x (.x nbody))   ; first reflection warning here
  dy (- y (.y nbody))   ; second here
  dz (- z (.z nbody))   ; third here
  dsq (+ (* dx dx)
 (+ (* dy dy)
(* dz dz)))]
  (Math/sqrt dsq

(defn -main [ args]
  (let [b (Body. 0 0 0)]
(println pos: (.x b) (.y b) (.z b

--
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: Fighting with Emacs ;-)

2010-09-27 Thread Alan
C-c C-k in the .clj buffer is easier and equivalent (or at least very
similar)

On Sep 27, 12:27 pm, Linus Ericsson oscarlinuserics...@gmail.com
wrote:
 I recognize that one. The repl haven't loaded the file your editing.

 My (temporary) solution is to do a (load-file the file your editing)
 after each edit that I want to debug, but that's a bit boring. I guess there
 is some kind of reload feature somewhere...

 /Linus

 2010/9/27 psfblair psfbl...@gmail.com

  I found the old thread below, but unfortunately the solution isn't
  working for me. If I have a foo.clj file in a buffer and evaluate
  region on

  (defn foo [] (+ 1 2))

  I get

  #'user/foo in the minibuffer. If I then evaluate region on

  (foo)

  I get 3 in the minibuffer. The slime REPL is giving me a prompt user
  so I'm assuming it's in the user namespace, but I can't seem to get
  expressions from the text buffer to evaluate in there.

  On Mar 28, 5:01 am, Michał Marczyk michal.marc...@gmail.com wrote:

   On 27 March 2010 22:25, alux alu...@googlemail.com wrote:

But now I see people use the result of this evaluation in their REPL
(I see this in videos, so I cant ask 'em :). This doesnt work at all
for me. I get the result in the minibuffer (this thing at the very
bottom) and thats it.

   If the form you evaluate is of the def* variety, it's going to affect
   the namespace it resides in and not the namespace of the REPL. Thus,
   if you have e.g. (ns foo) at the top of the file, yet you're working
   in the user namespace at the REPL, then after using C-x C-e to
   evaluate a function definition in your file, you'll have to say
   something like foo/bar to reach it from the REPL. (Or (use :reload-all
   'foo), if you prefer.)

   If there is no namespace declaration in the file, then the expression
   will be evaluated in the user namespace, which means that you'll be
   able to use it straight away if that's your REPL's namespace. (If you
   say (in-ns 'foo) or (ns foo) at the REPL, then you'll have to say
   something like user/bar to reach your function.)

   Sincerely,
   Michał

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



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


Re: exception thrown when passing in nil parameter

2010-09-27 Thread Stuart Sierra
Here's one popular form:

(defn foo
  ([a b c] (foo a b c nil))
  ([a b c d] (if d ...)))

Most multi-arity functions have the same behavior for every arity,
with some default argument values.

-S

On Sep 27, 2:13 pm, Glen Rubin rubing...@gmail.com wrote:
 I have a function that will accept 3 or 4 parameters.  Another
 function I have calls it and passes in 4 arguments.  Sometimes, the
 4th argument is nil and this causes an error, instead of just calling
 the main function as if I passed in 3 arguments.  Meaning the main
 function sees a 4th parameter with nil value.  How do I get it to act
 as only 3 parameters were passed in this circumstance?  thx

-- 
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: Possible to avoid reflection in this deftype in 1.3 alpha1?

2010-09-27 Thread Stuart Halloway
That's weird. I see no reflection warnings when loading this on 1.3 alpha 1. 

Stu

 The following program compiles and runs perfectly fine in both 1.2 and 1.3 
 alpha1.  It has no reflection warnings in 1.2, but it does in 1.3 alpha1.  I 
 have tried several variations, but I haven't yet been able to figure out how 
 to write type declarations that avoid reflection in 1.3 alpha1.  Does anyone 
 know whether this is a bug?
 
 Or perhaps code like this ought to be structured completely differently in 
 order to avoid reflection, and it was just a fluke that it worked in 1.2?
 
 Thanks,
 Andy
 
 (ns nbody
  (:gen-class))
 
 (set! *warn-on-reflection* true)
 
 (definterface IBody
  (^double x [])
  (^double y [])
  (^double z [])
  (^double dist [other]))
 
 (deftype Body [^{:unsynchronized-mutable true :tag double} x
   ^{:unsynchronized-mutable true :tag double} y
   ^{:unsynchronized-mutable true :tag double} z ]
  IBody
  (x [this] x)
  (y [this] y)
  (z [this] z)
  (dist [this other]
(let [^Body nbody other
  dx (- x (.x nbody))   ; first reflection warning here
  dy (- y (.y nbody))   ; second here
  dz (- z (.z nbody))   ; third here
  dsq (+ (* dx dx)
 (+ (* dy dy)
(* dz dz)))]
  (Math/sqrt dsq
 
 (defn -main [ args]
  (let [b (Body. 0 0 0)]
(println pos: (.x b) (.y b) (.z b
 
 -- 
 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


Interop question concerning optional args

2010-09-27 Thread JonathanBelolo
While toying with the Sesame2.3 library, I've come across the
following behavior for the first time.

This is taken from the api doc for
org.openrdf.repository.base.RepositoryConnectionBase:

add(Resource subject, URI predicate, Value object, Resource...
contexts)
  Adds a statement with the specified subject, predicate and
object to this repository, optionally to one or more named contexts.

But apparently, Clojure seems to think the optional args are
mandatory...

(.add con alice RDF/TYPE person)

No matching method found: add for class
org.openrdf.repository.sail.SailRepositoryConnection
  [Thrown class java.lang.IllegalArgumentException]

So I run

(grep #.add (.getMethods (.getClass con)))

#Method public void
org.openrdf.repository.base.RepositoryConnectionBase.add(org.openrdf.model.Resource,org.openrdf.model.URI,org.openrdf.model.Value,org.openrdf.model.Resource[])
throws org.openrdf.repository.RepositoryException)

Finally the following works...

(.add con alice RDF/TYPE person (make-array Resource 1))
nil

Is this behavior normal? Are optional args mandatory when called with
interop?

Thanks for your help :)

Jonathan

-- 
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: Possible to avoid reflection in this deftype in 1.3 alpha1?

2010-09-27 Thread Andy Fingerhut
OK, so I happened to stumble across a fix to my program, but I still  
wonder whether this is intentional behavior in 1.3 alpha1 or not.


If I change the name 'nbody' in these lines:


   (let [^Body nbody other
 dx (- x (.x nbody))   ; first reflection warning here
 dy (- y (.y nbody))   ; second here
 dz (- z (.z nbody))   ; third here


to some name that is not the name of the namespace, like 'nbo', then  
the reflection warnings go away:



   (let [^Body nbo other
 dx (- x (.x nbo))   ; first reflection warning here
 dy (- y (.y nbo))   ; second here
 dz (- z (.z nbo))   ; third here



If I then change the ns declaration at the top to ns nbo, the  
reflection warnings come back again.


Easy to avoid the problem, once you know.

Andy


On Sep 27, 2010, at 1:58 PM, Andy Fingerhut wrote:

The following program compiles and runs perfectly fine in both 1.2  
and 1.3 alpha1.  It has no reflection warnings in 1.2, but it does  
in 1.3 alpha1.  I have tried several variations, but I haven't yet  
been able to figure out how to write type declarations that avoid  
reflection in 1.3 alpha1.  Does anyone know whether this is a bug?


Or perhaps code like this ought to be structured completely  
differently in order to avoid reflection, and it was just a fluke  
that it worked in 1.2?


Thanks,
Andy

(ns nbody
 (:gen-class))

(set! *warn-on-reflection* true)

(definterface IBody
 (^double x [])
 (^double y [])
 (^double z [])
 (^double dist [other]))

(deftype Body [^{:unsynchronized-mutable true :tag double} x
  ^{:unsynchronized-mutable true :tag double} y
  ^{:unsynchronized-mutable true :tag double} z ]
 IBody
 (x [this] x)
 (y [this] y)
 (z [this] z)
 (dist [this other]
   (let [^Body nbody other
 dx (- x (.x nbody))   ; first reflection warning here
 dy (- y (.y nbody))   ; second here
 dz (- z (.z nbody))   ; third here
 dsq (+ (* dx dx)
(+ (* dy dy)
   (* dz dz)))]
 (Math/sqrt dsq

(defn -main [ args]
 (let [b (Body. 0 0 0)]
   (println pos: (.x b) (.y b) (.z b



--
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: Possible to avoid reflection in this deftype in 1.3 alpha1?

2010-09-27 Thread Andy Fingerhut
I don't know if it makes a difference, but I was doing AOT compilation  
on a file nbody.clj containing the program in my message.


I replied to my own message with a workaround that it seems to be  
related to the variable 'nbody' having the same name as the one in the  
'ns' declaration.


Thanks,
Andy

On Sep 27, 2010, at 4:14 PM, Stuart Halloway wrote:

That's weird. I see no reflection warnings when loading this on 1.3  
alpha 1.


Stu

The following program compiles and runs perfectly fine in both 1.2  
and 1.3 alpha1.  It has no reflection warnings in 1.2, but it does  
in 1.3 alpha1.  I have tried several variations, but I haven't yet  
been able to figure out how to write type declarations that avoid  
reflection in 1.3 alpha1.  Does anyone know whether this is a bug?


Or perhaps code like this ought to be structured completely  
differently in order to avoid reflection, and it was just a fluke  
that it worked in 1.2?


Thanks,
Andy

(ns nbody
(:gen-class))

(set! *warn-on-reflection* true)

(definterface IBody
(^double x [])
(^double y [])
(^double z [])
(^double dist [other]))

(deftype Body [^{:unsynchronized-mutable true :tag double} x
 ^{:unsynchronized-mutable true :tag double} y
 ^{:unsynchronized-mutable true :tag double} z ]
IBody
(x [this] x)
(y [this] y)
(z [this] z)
(dist [this other]
  (let [^Body nbody other
dx (- x (.x nbody))   ; first reflection warning here
dy (- y (.y nbody))   ; second here
dz (- z (.z nbody))   ; third here
dsq (+ (* dx dx)
   (+ (* dy dy)
  (* dz dz)))]
(Math/sqrt dsq

(defn -main [ args]
(let [b (Body. 0 0 0)]
  (println pos: (.x b) (.y b) (.z b

--
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: Interop question concerning optional args

2010-09-27 Thread ataggart
The vararg at the end of the method is just syntactic sugar for an
array, so the add method actually takes 4 args, the last being a
Resource array.  The java compiler just replaces missing varargs
with an empty array.

My guess is that the reflection mechanisms in the compiler just look
at type/arity.  The Method object has a isVarArg() boolean, so that
could be used to allow omitting varargs altogether.  That would need
to be an enhancement to the clojure compiler, so I opened a ticket:

https://www.assembla.com/spaces/clojure/tickets/440-java-method-calls-cannot-omit-varargs


On Sep 27, 1:16 pm, JonathanBelolo jonat...@scorpiomusic.fr wrote:
 While toying with the Sesame2.3 library, I've come across the
 following behavior for the first time.

 This is taken from the api doc for
 org.openrdf.repository.base.RepositoryConnectionBase:

 add(Resource subject, URI predicate, Value object, Resource...
 contexts)
           Adds a statement with the specified subject, predicate and
 object to this repository, optionally to one or more named contexts.

 But apparently, Clojure seems to think the optional args are
 mandatory...

 (.add con alice RDF/TYPE person)

 No matching method found: add for class
 org.openrdf.repository.sail.SailRepositoryConnection
   [Thrown class java.lang.IllegalArgumentException]

 So I run

 (grep #.add (.getMethods (.getClass con)))

 #Method public void
 org.openrdf.repository.base.RepositoryConnectionBase.add(org.openrdf.model. 
 Resource,org.openrdf.model.URI,org.openrdf.model.Value,org.openrdf.model.Re 
 source[])
 throws org.openrdf.repository.RepositoryException)

 Finally the following works...

 (.add con alice RDF/TYPE person (make-array Resource 1))
 nil

 Is this behavior normal? Are optional args mandatory when called with
 interop?

 Thanks for your help :)

 Jonathan

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread Daniel Pittman
Tim Daly d...@axiom-developer.org writes:

 There is a movement afoot in the common lisp community to implement
 quicklisp which is similar to the perl cpan site or debian. It would be
 useful if there was a quicklisp (or asdf) for Clojure. Thus you could
 apt-get a library for clojure.

FWIW, having just started out playing with Clojure with a view to building a
Google App Engine web service — and from a Perl and Debian background:

The single biggest thing that I have missed has been 'lein search' or so,
which would allow me to search an index of the modules it can access and tell
me what is available for meeting my current need.

The second biggest is the lack of a CPAN-alike central service on the web that
would allow me to do the same, plus review the documentation for candidate
libraries.

So, um, that would be nice. :)

Daniel
-- 
✣ Daniel Pittman✉ dan...@rimspace.net☎ +61 401 155 707
   ♽ made with 100 percent post-consumer electrons

-- 
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: ANN: Clojure Cookbook

2010-09-27 Thread Scott Jaderholm
Daniel,

If you install lein-search (http://clojars.org/lein-search or
http://github.com/Licenser/lein-search) you can do searches like that.

lein search mail

If you put it in ~/.lein/plugins it will work for all your lein projects and
you can even use it to add what you find to your project.clj and to go
through all your dependencies and prompt whether your want to update.


Scott


On Mon, Sep 27, 2010 at 10:01 AM, Daniel Pittman dan...@rimspace.netwrote:

 Tim Daly d...@axiom-developer.org writes:

  There is a movement afoot in the common lisp community to implement
  quicklisp which is similar to the perl cpan site or debian. It would be
  useful if there was a quicklisp (or asdf) for Clojure. Thus you could
  apt-get a library for clojure.

 FWIW, having just started out playing with Clojure with a view to building
 a
 Google App Engine web service — and from a Perl and Debian background:

 The single biggest thing that I have missed has been 'lein search' or so,
 which would allow me to search an index of the modules it can access and
 tell
 me what is available for meeting my current need.

 The second biggest is the lack of a CPAN-alike central service on the web
 that
 would allow me to do the same, plus review the documentation for candidate
 libraries.

 So, um, that would be nice. :)

Daniel
 --
 ✣ Daniel Pittman✉ dan...@rimspace.net☎ +61 401 155
 707
   ♽ made with 100 percent post-consumer electrons

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


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

question regarding macro (ab)usage

2010-09-27 Thread gaz jones
hi,

apologies if this is a long question, i would appreciate some guidance here.

i am creating a clojure wrapper around a rather verbose low latency
messaging framework. the main things you can do are publish messages,
receive messages, initialize sources and receivers etc. all are done
through a 'context'. i have ended up with this (silly example):

(with-context [:some parameter]
  (init-receiver some-topic :some option)
  (init-source some-topic :on-disconnect #(println client disconnected))
  (publish some-topic some-message :other option)
  (receive some-topic
   (fn [o m] (println received:  (.dataString m)

which i am fairly happy with. it is all wrapping up access to
underlying java objects (eg a context object, lists of sources,
receivers, threads and so on).

the implementation (somewhat simplified for clarity) is like:

;; these will be bound later
(def init-receiver nil)
(def init-source nil)
(def publish nil)
(def receive nil)

;; real impls with more args than i want to have to pass around
(defn init-receiver-on [context receivers topic] ...boring java stuff)
(defn init-source-on [context sources topic] ...boring java stuff)
(defn publish-on [context sources topic message] ...boring java stuff)
(defn receive-on [context receivers topic func] ...boring java stuff)

(defmacro with-context [options  body]
  `(let [context# (create-context options)
 thread# (create-thread context)
 sources# (atom {})
 receivers# (atom {})]
 (binding [init-receiver (partial init-receiver-on context# receivers#)
   init-source (partial init-source-on context# sources#)
   publish (partial publish-on context# sources#)
   receiver (partial receive-on context# receivers#)]
   (try
 (do ~...@body)
 (finally
   ... close stuff, cleanup)

so i am binding those functions to partial applications which use the
lexically scoped context, thread etc when you use the macro. is this
reasonable?

a prior implementation i had was like:

(defmacro with-context [options  body]
  `(let [context# (create-context options)
 thread# (create-thread context#)]
 sources# (atom {})
 receivers# (atom {})]
(letfn [(~'publish [topic# msg#  options#] (publish-on context#
sources# topic# msg# options#))
(~'receive [topic# callback#  options#] (receive-on
context# receivers# topic# callback# options#))
(~'init-source [topic#  options#] (init-source-on
context# sources# topic# options#))
(~'init-receiver [topic#  options#] (init-receiver-on
context# receivers# topic# options#))]
 (try
   (do ~...@body)
   (finally
... cleanup))

which seems like a bit of an abuse, creating an anaphara for each of
the functions. the problem i had with this was the anaphara werent
available when i was outside of my macro (eg in any other function
called from the macro):

(defn start-server [] (receiver topic (fn [o m] (println this is
full of fail
(with-context [] (start-server))

i also tried implementing it using a protocol and reify, which worked
rather well and felt the 'cleanest' solution, the impl of which is
probably fairly obvious so i wont bother typing it in here. however i
didnt like having to pass an object around everywhere to call methods
on.

my question is simply, what is the most idiomatic solution? im
guessing the protocol and reify, but is the first solution also
reasonable?

again, sorry for the long question - i also typed it all from memory
so apologies for any obvious typos / mistakes, i dont have the code
available on the machine i am using. any insight would be appreciated.

thanks,

gareth

-- 
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 often do you use REPL?

2010-09-27 Thread ngocdaothanh
cake (http://github.com/ninjudd/cake) has the tab completion
feature.

Because this is very useful, I wonder if this feature should be added
to leiningen or Clojure itself.

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