by the way, Tim, I've seen NB before as comments in J.  What's it stand for?

On Mon, Jan 12, 2009 at 10:39 PM, e <evier...@gmail.com> wrote:

> ohhhhhhhh!  all the stuff from listmerge ended up in my-list directly.  so
> then when listmerge was called on these elements it rightly complained!
> Awesome.  Lots of good lessons coming out of this.
>
> I need to learn how to run closure code as a script then.  I seem to
> remember something about this where you do java -cp clojure.jar
> something.something.REPL yourcode.clj . . . . I'll try to find it.  I'm glad
> I was pretty close.  Was gettin' ready to throw in the towel . . . which
> could have been good 'cause I have a lot of languages in the queue to try
> out. . . but nope.  Gonna keep at it for now.  I think I need to build an
> 800 core machine so I can get an appreciation for it all!
>
> But I already appreciate all the help.  You guys are dedicated!
>
> Thanks again.
>
>
> On Mon, Jan 12, 2009 at 10:23 PM, Timothy Pratley <
> timothyprat...@gmail.com> wrote:
>
>>
>> > I just want to get this out of my system, but I'm getting some class
>> cast
>> > exception and no useful line number.
>>
>> In situations like these I find that looking at the entire stack trace
>> provides clues. The REPL by default does not print the entire stack
>> though I'm sure there is a way to achieve that. However I prefer to
>> put the code in the file and run it as a script, which by default
>> prints the entire stack and from that you can see what line it occured
>> on (search for the first appearance of your filename). Doing so showed
>> me that the exception was actually thrown in listmerge, because
>> listmerge was passed in two integers instead of two lists, so I looked
>> at where you called listmerge, and saw that you called concat
>> probabbly expecting it to concat lists, but actually it concats the
>> contents of the lists
>>
>> >      (var-set my-list (concat @my-list (listmerge [...@l1] [...@l2]))))
>> @my-list))
>>
>> Here is a naive solution:
>>     (var-set my-list (concat @my-list (list (listmerge @l1 @l2)))))
>> @my-list)
>>
>> So in total your code minimally changed is:
>>
>> (defn msort [toSort]
>>  (with-local-vars [my-list (for [x toSort] [x]) l1 0 l2 0]
>>   (while (rest @my-list)
>> ;     (println @my-list)
>>      (var-set l1 (first @my-list))
>>     (var-set l2 (second @my-list))
>>     (var-set my-list (drop 2 @my-list))
>>      (var-set my-list (concat @my-list (list (listmerge @l1 @l2)))))
>> @my-list))
>>
>> user=> (msort [64 45 2 67 1 7])
>> ((1 2 7 45 64 67))
>>
>> NB: the good old print out my-list also helps narrow down what is
>> happening.
>> Again, I'm just providing a fix for your code, not suggesting this is
>> the best approach.
>>
>>
>> Regards,
>> Tim.
>>
>>
>> >>
>>
>

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