Re: Space usage of lazy seqs

2009-12-02 Thread Dave M


On Dec 2, 9:09 pm, David Brown  wrote:
...
> If you're running JDK 6, you can run the virtualvm, or jconsole to get
> a better handle on the memory usage, and even dig into what it might
> used for.

Google does not return useful references to a tool called virtualvm;
perhaps you mean VisualVM (jvisualvm)?

-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: Java Class Factory

2009-12-02 Thread Dave M


On Dec 2, 11:15 pm, lazy1  wrote:
> Hello,
>
> I'm trying to create a "factory" method for Java classes, however I'm
> doing something wrong.
>
> (import '(java.util Dictionary HashMap))
>
> (def *containers* { :dict Dictionary :hash HashMap})
> (defn new-container
>   [type]
>   (new (*containers* type)))
>
> (def d (new-container :dict))
>
> The above gives me
> Exception in thread "main" java.lang.IllegalArgumentException: Unable
> to resolve classname: (*containers* type) (t.clj:6)

"new" does not evaluate its arguments, so it is trying to interpret
the form "(*containers* type)" as a classname, which it cannot do.

Another problem with your example is that java.util.Dictionary is an
abstract class, and cannot be instantiated directly; of the two
classes you gave, you will only be able to create instances of
HashMap.

...

> What is the right way to do this?

Aside from the issue with Dictionary being abstract, I think you need
a macro to do what you want to do:

(defmacro new-container [type]
  `(new ~(*containers* type)))

-Dave

>
> Thanks,
> --
> Miki

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that 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: Is str supposed to be able to output lazy strings?

2009-12-06 Thread Dave M

On Dec 6, 1:20 pm, CuppoJava  wrote:
> This is expected behavior.
>
> eg. (str (map identity [1 2 3]))
> returns "clojure.lang.lazy...@7861"
>
> The way to think about it is, (str) asks for the string representation
> of an object. The string representation of a lazy sequence in this
> case is "clojure.lang.lazy...@7861".
>
> If you want the string representations of what's inside the lazy seq,
> you can use the apply function.
>
> (apply str (map identity [1 2 3]))
> "123"

API docs for the arguments to apply - "([f args* argseq])"; so the
following is perhaps more straight-forward:

(apply str (seq [1 2 3]))
=> "123"

Additionally, the following works too in Cloure 1.0.0:

(apply str [1 2 3])
=> "123"

...though it does not follow from the API docs, which imply that the
last argument to apply should be seq, and "(seq? [1 2 3])" => false.


-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: Translation from Common Lisp 2

2010-03-18 Thread Dave M
...

> (game-action weld chain bucket attic
>          (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn
^
Your if-condition is nested one form too deeply; try "(if (and (have
'bucket) ...) ...)"

I haven't tried it, so there might be other problems.

-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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Make a loop in a loop

2010-07-07 Thread Dave M
On Jul 7, 5:06 pm, Isak Hansen  wrote:
> On Wed, Jul 7, 2010 at 5:00 PM, Lars Nilsson  wrote:
>
> > Maybe
>
> > (doseq [year (range 1999 2010 1)]
> >  (doseq [month (range 1 53 1)]
> >    (print-data year range)))
>
> You could also do this with dotimes instead of doseq. Doesn't matter
> for Ns this small, but creating a range just so you have something to
> iterate across is a bit wasteful.

That's the beauty of lazy sequences, and range produces a lazy
sequence:

  http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/range

At any point in time, only a single value from each range exists; the
other values in the range are either garbage or don't exist (have not
been computed) yet.

I think this use of range is considered idiomatic Clojure.

-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