On Sun, 14 Nov 2010 00:48:13 -0500
Robert McIntyre <r...@mit.edu> wrote:

> So my friend and I were screwing around, battling versions of LISP as
> nerds are wont to do, when I came across this:
> 
> (eval `(clojure.core/+ ~@(take 1e4 (iterate inc 1))))
> Invalid method Code length 89884 in class file user$eval13607
> 
> 
> This is just trying to evaluate + directly on a bunch of arguments.

I'd say the first problem is using the macro-building constructs
outside a macro. I believe this is generally a bad idea. If you build
the list and apply + to it directly, it works fine

Clojure 1.2.0
user=> (apply + (doall (take 1e4 (iterate inc 1))))
(apply + (take 1e4 (iterate inc 1)))
50005000
user=> (apply + (doall (take 1e5 (iterate inc 1))))
(apply + (take 1e5 (iterate inc 1)))
5000050000
user=> 

But nope, you've got a real problem. It appears to be with eval:

user=> (eval (cons + (take 1e4 (iterate inc 1))))
(eval (cons + (take 1e4 (iterate inc 1))))
java.lang.ClassFormatError: Invalid method Code length 89881 in class file 
user$eval26 (NO_SOURCE_FILE:8)
user=> (count (cons + (take 1e4 (iterate inc 1))))
(count (cons + (take 1e4 (iterate inc 1))))
10001

Of course, eval isn't idiomatic clojure. 

> Common Lisp on my friend's 30 year old Lisp machine does the
> equivalent of this with ease, even for much larger numbers.
> 
> As I'm writing this, my "friend" is rubbing in this in my face by also
> doing the above with C-LISP on his laptop.  (although his stack
> overflows for 1e5)

Well, the apply version works out to 1e8 for me if I leave out the
doall. If I use the doall, it runs out of heap at 1e7. I'm a little
surprised that they're different - I figured apply would instantiate
the sequence, and I'd need to use reduce instead of apply for really
large sequences.

       <mike
-- 
Mike Meyer <m...@mired.org>             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

Reply via email to